// File: jovermann[P]streplace/src/CommandLineParser.cpp
// Function: ut1::CommandLineParser::parseLongOption(int, char const**, int&)
void CommandLineParser::parseLongOption(int argc, const char* argv[], int& i)
{
    std::vector<std::string> fields     = ut1::splitString(argv[i] + 2, '=', 1);
    std::string              longOption = fields[0];

    // First try exact match.
    Option* option = getOption(longOption);
    if (option == nullptr)
    {
        // Then try prefix and take it when it is unique.
        std::vector<std::string> matchingOptions;
        for (const auto& optName: optionList)
        {
            if (ut1::hasPrefix(optName, longOption) && (!ut1::hasPrefix(optName, HEADER_PREFIX)))
            {
                matchingOptions.push_back(optName);
            }
        }
        if (matchingOptions.size() == 0)
        {
            error("Unknown option --" + longOption + ".");
        }
        else if (matchingOptions.size() == 1)
        {
            longOption = matchingOptions[0];
            option     = getOption(longOption);
        }
        else
        {
            error("Ambiguous option --" + longOption + " (matches --" + ut1::joinStrings(matchingOptions, ", --") + ").");
        }
    }

    // We only get here when we had an exact match or a unique prefix.
    assert(option != nullptr);

    if (option->hasArg())
    {
        if (fields.size() == 2)
        {
            // --foo=bar
            option->setValue(fields[1], listSepChar);
        }
        else if (++i < argc)
        {
            // --foo bar
            option->setValue(argv[i], listSepChar);
        }
        else
        {
            error("Option --" + longOption + " requires an argument.");
        }
    }
    else
    {
        if (fields.size() == 1)
        {
            // --foo
            option->setValue("", 0);
        }
        else
        {
            error("Option --" + longOption + " does not accept arguments.");
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
addq $0x2, %rax
movq %rax, -0x2e0(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x7a50
movq -0x2e0(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0xb310
jmp 0x8cb8
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x3d, %edx
movl $0x1, %ecx
callq 0x11cb0
jmp 0x8cd1
leaq -0x58(%rbp), %rdi
callq 0x73c0
leaq -0x59(%rbp), %rdi
callq 0x7670
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0xc3a0
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x7280
jmp 0x8d01
movq -0x2e8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb080
movq %rax, -0x2f0(%rbp)
jmp 0x8d1d
movq -0x2f0(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0x91e8
leaq -0xb0(%rbp), %rdi
callq 0xb2d0
movq -0x2e8(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xc3c0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xb4a0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xc3f0
testb $0x1, %al
jne 0x8d99
jmp 0x8f46
leaq -0xc0(%rbp), %rdi
callq 0xc430
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x113c0
movb %al, %cl
movb $0x0, -0xf2(%rbp)
movb $0x0, -0xf3(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x2f1(%rbp)
jne 0x8dde
jmp 0x8e44
movq -0xd0(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x7a50
movq -0x300(%rbp), %rdx
movb $0x1, -0xf2(%rbp)
leaq 0x4122f(%rip), %rsi     # 0x4a043
leaq -0xf0(%rbp), %rdi
callq 0xb310
jmp 0x8e22
movq -0x308(%rbp), %rdi
movb $0x1, -0xf3(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x113c0
xorb $-0x1, %al
movb %al, -0x2f1(%rbp)
movb -0x2f1(%rbp), %al
movb %al, -0x309(%rbp)
testb $0x1, -0xf3(%rbp)
jne 0x8e5b
jmp 0x8e67
leaq -0xf0(%rbp), %rdi
callq 0x73c0
testb $0x1, -0xf2(%rbp)
jne 0x8e72
jmp 0x8e7e
leaq -0xf1(%rbp), %rdi
callq 0x7670
movb -0x309(%rbp), %al
testb $0x1, %al
jne 0x8e8d
jmp 0x8f33
movq -0xd0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xc450
jmp 0x8ea2
jmp 0x8f33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8eca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x73c0
leaq -0x59(%rbp), %rdi
callq 0x7670
jmp 0x955b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9552
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9546
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
testb $0x1, -0xf2(%rbp)
jne 0x8f11
jmp 0x8f1d
leaq -0xf1(%rbp), %rdi
callq 0x7670
jmp 0x91d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x91d7
jmp 0x8f35
leaq -0xc0(%rbp), %rdi
callq 0xc4c0
jmp 0x8d7d
leaq -0xb0(%rbp), %rdi
callq 0xb550
cmpq $0x0, %rax
jne 0x8fe5
leaq 0x4123f(%rip), %rsi     # 0x4a1a2
leaq -0x138(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xb5b0
jmp 0x8f78
leaq 0x41f94(%rip), %rdx     # 0x4af13
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xb720
jmp 0x8f94
movq -0x2e8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
movl $0x1, %edx
callq 0xb0f0
jmp 0x8fae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x73c0
leaq -0x138(%rbp), %rdi
callq 0x73c0
jmp 0x91d7
leaq -0xb0(%rbp), %rdi
callq 0xb550
cmpq $0x1, %rax
jne 0x9047
xorl %eax, %eax
movl %eax, %esi
leaq -0xb0(%rbp), %rdi
callq 0xc3a0
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x7070
jmp 0x9018
movq -0x2e8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb080
movq %rax, -0x318(%rbp)
jmp 0x9034
movq -0x318(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x91c7
leaq 0x41166(%rip), %rsi     # 0x4a1b4
leaq -0x1b8(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xb5b0
jmp 0x9063
leaq 0x4115e(%rip), %rdx     # 0x4a1c8
leaq -0x198(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xb720
jmp 0x907f
leaq -0x1f9(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x7a50
movq -0x320(%rbp), %rdx
leaq 0x41135(%rip), %rsi     # 0x4a1d5
leaq -0x1f8(%rbp), %rdi
callq 0xb310
jmp 0x90ae
leaq -0x1d8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1f8(%rbp), %rdx
callq 0x124b0
jmp 0x90ca
leaq -0x178(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1d8(%rbp), %rdx
callq 0xc4e0
jmp 0x90e6
leaq 0x42258(%rip), %rdx     # 0x4b345
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xb720
jmp 0x9102
movq -0x2e8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
movl $0x1, %edx
callq 0xb0f0
jmp 0x911c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x91b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x91a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9195
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9189
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x917d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x73c0
leaq -0x178(%rbp), %rdi
callq 0x73c0
leaq -0x1d8(%rbp), %rdi
callq 0x73c0
leaq -0x1f8(%rbp), %rdi
callq 0x73c0
leaq -0x1f9(%rbp), %rdi
callq 0x7670
leaq -0x198(%rbp), %rdi
callq 0x73c0
leaq -0x1b8(%rbp), %rdi
callq 0x73c0
jmp 0x91d7
jmp 0x91c9
leaq -0xb0(%rbp), %rdi
callq 0xb3c0
jmp 0x91e8
leaq -0xb0(%rbp), %rdi
callq 0xb3c0
jmp 0x9546
cmpq $0x0, -0x98(%rbp)
je 0x91f4
jmp 0x9213
leaq 0x40fdf(%rip), %rdi     # 0x4a1da
leaq 0x40fea(%rip), %rsi     # 0x4a1ec
movl $0x1c3, %edx            # imm = 0x1C3
leaq 0x40ff8(%rip), %rcx     # 0x4a206
callq 0x7430
movq -0x98(%rbp), %rdi
callq 0xc5b0
testb $0x1, %al
jne 0x9228
jmp 0x93e5
leaq -0x38(%rbp), %rdi
callq 0xb550
cmpq $0x2, %rax
jne 0x9277
movq -0x98(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0xc3a0
movq -0x328(%rbp), %rdi
movq %rax, %rsi
movq -0x2e8(%rbp), %rax
movsbl 0x90(%rax), %edx
callq 0x7d40
jmp 0x9272
jmp 0x93e0
movq -0x20(%rbp), %rcx
movl (%rcx), %eax
addl $0x1, %eax
movl %eax, (%rcx)
cmpl -0xc(%rbp), %eax
jge 0x9355
movq -0x98(%rbp), %rax
movq %rax, -0x340(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x338(%rbp)
leaq -0x221(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x7a50
movq -0x338(%rbp), %rsi
movq -0x330(%rbp), %rdx
leaq -0x220(%rbp), %rdi
callq 0xb310
jmp 0x92de
movq -0x340(%rbp), %rdi
movq -0x2e8(%rbp), %rax
movsbl 0x90(%rax), %edx
leaq -0x220(%rbp), %rsi
callq 0x7d40
jmp 0x9301
leaq -0x220(%rbp), %rdi
callq 0x73c0
leaq -0x221(%rbp), %rdi
callq 0x7670
jmp 0x93de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9344
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x73c0
leaq -0x221(%rbp), %rdi
callq 0x7670
jmp 0x9546
leaq 0x40ef2(%rip), %rsi     # 0x4a24e
leaq -0x268(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xb5b0
jmp 0x9371
leaq 0x40ee0(%rip), %rdx     # 0x4a258
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0xb720
jmp 0x938d
movq -0x2e8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0x1, %edx
callq 0xb0f0
jmp 0x93a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x93cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x73c0
leaq -0x268(%rbp), %rdi
callq 0x73c0
jmp 0x9546
jmp 0x93e0
jmp 0x9528
leaq -0x38(%rbp), %rdi
callq 0xb550
cmpq $0x1, %rax
jne 0x94a0
movq -0x98(%rbp), %rax
movq %rax, -0x350(%rbp)
leaq -0x289(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x7a50
movq -0x348(%rbp), %rdx
leaq 0x40c67(%rip), %rsi     # 0x4a08e
leaq -0x288(%rbp), %rdi
callq 0xb310
jmp 0x9435
movq -0x350(%rbp), %rdi
leaq -0x288(%rbp), %rsi
xorl %edx, %edx
callq 0x7d40
jmp 0x944c
leaq -0x288(%rbp), %rdi
callq 0x73c0
leaq -0x289(%rbp), %rdi
callq 0x7670
jmp 0x9526
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x948f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x73c0
leaq -0x289(%rbp), %rdi
callq 0x7670
jmp 0x9546
leaq 0x40da7(%rip), %rsi     # 0x4a24e
leaq -0x2d0(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xb5b0
jmp 0x94bc
leaq 0x40dac(%rip), %rdx     # 0x4a26f
leaq -0x2b0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0xb720
jmp 0x94d8
movq -0x2e8(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
movl $0x1, %edx
callq 0xb0f0
jmp 0x94f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9518
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x73c0
leaq -0x2d0(%rbp), %rdi
callq 0x73c0
jmp 0x9546
jmp 0x9528
leaq -0x90(%rbp), %rdi
callq 0x73c0
leaq -0x38(%rbp), %rdi
callq 0xb3c0
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x73c0
leaq -0x38(%rbp), %rdi
callq 0xb3c0
movq -0x68(%rbp), %rdi
callq 0x7a30
nopw %cs:(%rax,%rax)