```ts
export function parseOption(segment: string): string[] {
  const eq = segment.indexOf("=");
  if (eq === -1 || !/^[A-Za-z][A-Za-z0-9_]*$/.test(segment.slice(0, eq))) {
    throw new Error("malformed option segment: " + segment);
  }
  let raw = segment.slice(eq + 1);
  if (raw.length >= 2 && raw.startsWith('"') && raw.endsWith('"')) {
    raw = raw.slice(1, -1);
  } else if (raw.includes('"')) {
    throw new Error("unterminated quoted value: " + segment);
  }
  return [segment.slice(0, eq), raw];
}

export function scanPairs(input: string): string[][] {
  if (typeof input !== 'string' || input.length === 0) {
    throw new Error("invalid input: not a non-empty string");
  }

  const pairs = [];
  let currentKey = null;
  let valueBuffer = '';

  for (let i = 0; i < input.length; i++) {
    if (input[i] === '"') {
      // Start of quoted value
      if (valueBuffer.length > 0) {
        throw new Error("unterminated quoted value: " + input);
      }
      let j = i;
      while (j < input.length && input[j] !== '"') {
        j++;
      }
      if (j === input.length) {
        throw new Error("unterminated quoted value: " + input);
      }
      const rawValue = input.slice(i + 1, j).trim();
      valueBuffer += rawValue;
      i = j; // Move past the closing quote
    } else if (input[i] === ';') {
      // End of segment or semicolon in quoted value
      if (valueBuffer.length > 0) {
        pairs.push([currentKey || '', valueBuffer]);
        valueBuffer = '';
        currentKey = null;
      }
    } else if (input[i] === '=') {
      // Start of key=value pair
      if (currentKey !== null) {
        throw new Error("repeated key: " + input);
      }
      let j = i;
      while (j < input.length && /[A-Za-z0-9_]/.test(input[j])) {
        j++;
      }
      if (!/[A-Za-z][A-Za-z0-9_]*$/.test(input.slice(i, j))) {
        throw new Error("malformed option segment: " + input);
      }
      currentKey = input.slice(i, j).trim();
    } else if (input[i] === ' ') || input[i] === '\t') {
      // Skip whitespace
    } else {
      // Invalid character in segment
      throw new Error("invalid character in option segment: " + input);
    }
  }

  // Add the last pair if present
  if (currentKey !== null && valueBuffer.length > 0) {
    pairs.push([currentKey, valueBuffer]);
  }

  return pairs;
}
```