```ts
export function scanPairs(input: string): string[][] {
  if (typeof input !== 'string') throw new Error('Input must be a string');
  if (!input) return [];

  const result: string[][] = [];
  let currentKey: string | null = null;
  let currentValue: string | null = null;

  let currentSegment = '';
  let inQuotes = false;
  let semicolonFound = false;
  let lastKey: string | null = null;

  for (const char of input) {
    if (char === '"') {
      inQuotes = !inQuotes;
    } else if (char === ';') {
      if (!inQuotes && !semicolonFound) {
        if (lastKey !== currentKey) {
          result.push([currentKey || '', currentValue || '']);
          lastKey = currentKey;
        }
        currentSegment = '';
        semicolonFound = true;
      }
    } else {
      if (inQuotes) {
        currentSegment += char;
      } else {
        if (char === '=') {
          if (!currentKey) throw new Error('Invalid key in segment');
          currentValue = '';
        } else if (/[a-zA-Z0-9_]/.test(char)) {
          if (!currentKey) {
            currentKey = char;
          } else {
            currentSegment += char;
          }
        } else if (currentKey && !/[^=;"]/g.test(char)) {
          throw new Error('Invalid value in segment');
        } else {
          currentSegment += char;
        }
      }
    }
  }

  // Handle the last key-value pair
  if (lastKey !== currentKey) {
    result.push([currentKey || '', currentValue || '']);
  }

  return result;
}

export function parseOption(segment: string): string[] {
  const [key, value] = segment.split('=');
  if (!/^[a-zA-Z0-9_]+$/.test(key)) throw new Error('Invalid key');
  if (value && !/^[^;"]+$/.test(value)) throw new Error('Invalid quoted value');
  return [key, value || ''];
}
```