```ts
export function scanPairs(input: string): string[][] {
  if (typeof input !== 'string' || input === '') {
    throw new Error('Invalid input');
  }

  const pairs: [string, string][] = [];
  let key = '';
  let value = '';
  let inQuotes = false;

  for (let i = 0; i < input.length; i++) {
    if (input[i] === '"') {
      if (i > 0 && input[i - 1] !== '\\') {
        inQuotes = !inQuotes;
        continue;
      }
    }

    if (input[i] === ';' && !inQuotes) {
      if (!key || key.includes('=')) {
        throw new Error('Invalid segment');
      }
      pairs.push([key, value]);
      key = '';
      value = '';
      continue;
    }

    if (inQuotes) {
      value += input[i];
    } else {
      if (!key && !value && input[i] === '=') {
        throw new Error('Invalid segment');
      }
      if (!key) {
        key += input[i];
      } else {
        value += input[i];
      }
    }
  }

  if (inQuotes || !key || key.includes('=')) {
    throw new Error('Invalid segment');
  }
  pairs.push([key, value]);

  const seenKeys = new Set<string>();
  for (const [k] of pairs) {
    if (seenKeys.has(k)) {
      throw new Error('Repeated key');
    }
    seenKeys.add(k);
  }

  return pairs.map(([k, v]) => parseOption(`${k}=${v}`));
}

export function parseOption(segment: string): string[] {
  const [key, rawValue] = segment.split('=');

  if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key)) {
    throw new Error('Invalid key');
  }

  let value = rawValue.trim();
  if (value.startsWith('"') && value.endsWith('"')) {
    value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
  }

  return [key, value];
}
```