Repository: JuliaLang/julia
File: src/pipeline.cpp (C++)

Code before:
        // Check for "=" syntax first
        if (Arg.size() > prefix.size() && Arg[prefix.size()] == '=') {
            return Arg.substr(prefix.size() + 1);
        }
        // Otherwise, consume the next argument
        if (idx + 1 < Argv.size()) {
            return StringRef(Argv[++idx]);
        }
        errs() << "Warning: " << prefix << " requires a value\n";
        return StringRef();
    };

    // Process each token
    for (size_t i = 0; i < Argv.size(); ++i) {
        StringRef Arg(Argv[i]);

        if (Arg == "-print-after-all") {
            out.print_after_all = true;
        } else if (Arg == "-print-before-all") {
            out.print_before_all = true;
        } else if (Arg == "-print-module-scope") {
            out.print_module_scope = true;
        } else if (Arg == "-print-changed") {
            out.print_changed = true;
        } else if (Arg.starts_with("-print-after")) {
            StringRef val = getNextValue(i, Arg, "-print-after");
            if (!val.empty())
                out.print_after = val.str();
        } else if (Arg.starts_with("-print-before")) {
            StringRef val = getNextValue(i, Arg, "-print-before");
            if (!val.empty())
                out.print_before = val.str();
        } else if (Arg.starts_with("-filter-print-funcs")) {
            StringRef val = getNextValue(i, Arg, "-filter-print-funcs");
            if (!val.empty())
                out.filter_print_funcs = val.str();
        } else {
            errs() << "Warning: unknown llvm_options flag: " << Arg << "\n";
        }
    }
}

NewPM::NewPM(std::unique_ptr<TargetMachine> TM, OptimizationLevel O, OptimizationOptions options, PrintOptions print_options) :
    TM(std::move(TM)), O(O), options(options), print_options(print_options), TimePasses() {}


NewPM::~NewPM() = default;

AnalysisManagers::AnalysisManagers(TargetMachine &TM, PassBuilder &PB, OptimizationLevel O) : LAM(), FAM(createFAM(O, TM)), CGAM(), MAM() {
    PB.registerLoopAnalyses(LAM);
    PB.registerFunctionAnalyses(FAM);

Review comment (suggestion):
Can you ask Claude to rewrite this so that is isn't doing just a prefix check, but can have `getNextValue` implement the exact checks:
```suggestion
        } else if (StringRef val =  getNextValue(i, Arg, "-print-after=")) {
```

If you were going to do a prefix comparison scan only, the getopt standard requires that you do the prefix in the other direction (e.g. `StringRef("-print-after").starts_with(Arg.split('=').first)`) but that is getting fairly tedious to implement by hand and not something the custom parsers for llvm or gcc arguments currently does

Code after:
    // Supports both "-option=value" and "-option value" syntax
    auto getNextValue = [&](size_t &idx, StringRef Arg, StringRef option) JL_NOTSAFEPOINT -> StringRef {
        StringRef optionName = option.drop_back(); // remove trailing "="
        // Check for "-option=value" syntax
        if (Arg.starts_with(option)) {
            return Arg.substr(option.size());
        }
        // Check for "-option value" syntax (exact match on option name)
        if (Arg == optionName) {
            if (idx + 1 < Argv.size()) {
                return StringRef(Argv[++idx]);
            }
            raw_string_ostream err_stream(out.error);
            err_stream << "Warning: " << optionName << " requires a value\n";
        }
        return StringRef();
    };

    // Helper to split a comma-separated value and append to a vector
    auto addCommaSeparated = [](SmallVector<std::string, 1> &vec, StringRef val) JL_NOTSAFEPOINT {
        SmallVector<StringRef, 4> parts;
        val.split(parts, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
        for (auto &part : parts) {
            vec.push_back(part.str());
        }
    };

    // Process each token
    for (size_t i = 0; i < Argv.size(); ++i) {
        StringRef Arg(Argv[i]);

        if (Arg == "-print-after-all") {
            out.print_after_all = true;
        } else if (Arg == "-print-before-all") {
            out.print_before_all = true;
        } else if (Arg == "-print-module-scope") {
            out.print_module_scope = true;
        } else if (StringRef val = getNextValue(i, Arg, "-print-after="); !val.empty()) {
            addCommaSeparated(out.print_after, val);
        } else if (StringRef val = getNextValue(i, Arg, "-print-before="); !val.empty()) {
            addCommaSeparated(out.print_before, val);
        } else if (StringRef val = getNextValue(i, Arg, "-filter-print-funcs="); !val.empty()) {
            addCommaSeparated(out.filter_print_funcs, val);
        } else {
            raw_string_ostream err_stream(out.error);
            err_stream << "Warning: unknown llvm_options flag: " << Arg << "\n";
        }
    }
}

NewPM::NewPM(std::unique_ptr<TargetMachine> TM, OptimizationLevel O, OptimizationOptions options, PrintOptions print_options) :