// File: Lartu[P]coraldb/source/coraldb.cpp
// Function: parse_arguments(int, char**)
int parse_arguments(int argc, char **argv)
{
    std::string argument;
    switch_types requested_switch = none;
    for (int i = 1; i < argc; ++i)
    {
        argument = argv[i];
        if (requested_switch == none)
        {
            if (argument == "-h" || argument == "--help")
            {
                show_help();
                exit(0);
            }
            else if (argument == "-p" || argument == "--port")
            {
                requested_switch = port;
            }
            else if (argument == "-f" || argument == "--file")
            {
                requested_switch = file;
            }
            else if (argument == "-c" || argument == "--checkpoint")
            {
                requested_switch = checkpoint;
            }
            else if (argument == "-a" || argument == "--anyport")
            {
                global_port = 0;
            }
            else if (argument == "-v" || argument == "--version")
            {
                print_version();
                exit(0);
            }
            else
            {
                err_unknown_switch(argument);
            }
        }
        else
        {
            if (requested_switch == port)
            {
                try
                {
                    global_port = stoi(argument);
                }
                catch (const std::invalid_argument &ia)
                {
                    err_malformed_port(argument);
                    return 1;
                }
            }
            else if (requested_switch == file)
            {
                global_filename = argument;
            }
            else if (requested_switch == checkpoint)
            {
                try
                {
                    CHECKPOINT_TIME = stoi(argument) * 1000;
                }
                catch (const std::invalid_argument &ia)
                {
                    err_malformed_checkpoint_timeout(argument);
                    return 1;
                }
            }
            requested_switch = none;
        }
    }
    if (requested_switch != none)
    {
        err_expected_switch_value(argument);
        return 1;
    }
    if (global_filename == "")
    {
        const char *homedir = getenv("HOME");
        if (homedir == NULL)
        {
            homedir = getpwuid(getuid())->pw_dir;
        }
        global_filename = (std::string)homedir + "/coraldb.db";
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3430
movl $0x2, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x57b4
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x30(%rbp), %rdi
callq 0x3400
jmp 0x540c
cmpl $0x2, -0x34(%rbp)
jne 0x563f
leaq 0x5fff(%rip), %rsi      # 0xb41c
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xaa(%rbp)
jmp 0x542e
movb -0xaa(%rbp), %al
testb $0x1, %al
jne 0x545e
jmp 0x543a
leaq 0x5fde(%rip), %rsi      # 0xb41f
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xab(%rbp)
jmp 0x5452
movb -0xab(%rbp), %al
testb $0x1, %al
jne 0x545e
jmp 0x547d
callq 0x52c0
jmp 0x5465
xorl %edi, %edi
callq 0x3370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5923
leaq 0x5fa2(%rip), %rsi      # 0xb426
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xac(%rbp)
jmp 0x5495
movb -0xac(%rbp), %al
testb $0x1, %al
jne 0x54c5
jmp 0x54a1
leaq 0x5f81(%rip), %rsi      # 0xb429
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xad(%rbp)
jmp 0x54b9
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x54c5
jmp 0x54d1
movl $0x0, -0x34(%rbp)
jmp 0x5638
leaq 0x5f58(%rip), %rsi      # 0xb430
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xae(%rbp)
jmp 0x54e9
movb -0xae(%rbp), %al
testb $0x1, %al
jne 0x5519
jmp 0x54f5
leaq 0x5f37(%rip), %rsi      # 0xb433
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xaf(%rbp)
jmp 0x550d
movb -0xaf(%rbp), %al
testb $0x1, %al
jne 0x5519
jmp 0x5525
movl $0x1, -0x34(%rbp)
jmp 0x5636
leaq 0x5f0e(%rip), %rsi      # 0xb43a
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb0(%rbp)
jmp 0x553d
movb -0xb0(%rbp), %al
testb $0x1, %al
jne 0x556d
jmp 0x5549
leaq 0x5eed(%rip), %rsi      # 0xb43d
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb1(%rbp)
jmp 0x5561
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x556d
jmp 0x5579
movl $0x3, -0x34(%rbp)
jmp 0x5634
leaq 0x5eca(%rip), %rsi      # 0xb44a
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb2(%rbp)
jmp 0x5591
movb -0xb2(%rbp), %al
testb $0x1, %al
jne 0x55c1
jmp 0x559d
leaq 0x5ea9(%rip), %rsi      # 0xb44d
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb3(%rbp)
jmp 0x55b5
movb -0xb3(%rbp), %al
testb $0x1, %al
jne 0x55c1
jmp 0x55cd
movl $0x0, 0xbd19(%rip)      # 0x112e4
jmp 0x5632
leaq 0x5e83(%rip), %rsi      # 0xb457
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb4(%rbp)
jmp 0x55e5
movb -0xb4(%rbp), %al
testb $0x1, %al
jne 0x5615
jmp 0x55f1
leaq 0x5e62(%rip), %rsi      # 0xb45a
leaq -0x30(%rbp), %rdi
callq 0x6270
movb %al, -0xb5(%rbp)
jmp 0x5609
movb -0xb5(%rbp), %al
testb $0x1, %al
jne 0x5615
jmp 0x5623
callq 0x5250
jmp 0x561c
xorl %edi, %edi
callq 0x3370
leaq -0x30(%rbp), %rdi
callq 0x3820
jmp 0x562e
jmp 0x5630
jmp 0x5632
jmp 0x5634
jmp 0x5636
jmp 0x5638
jmp 0x563a
jmp 0x57a4
cmpl $0x0, -0x34(%rbp)
jne 0x56dc
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
movl $0xa, %edx
callq 0x66c0
movl %eax, -0xbc(%rbp)
jmp 0x5663
movl -0xbc(%rbp), %eax
movl %eax, 0xbc75(%rip)      # 0x112e4
jmp 0x56d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5923
movq -0x40(%rbp), %rdi
callq 0x3150
movq %rax, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3870
jmp 0x56a5
movl $0x1, -0x4(%rbp)
movl $0x1, -0x54(%rbp)
callq 0x34c0
jmp 0x56cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x34c0
jmp 0x56d2
jmp 0x590e
jmp 0x5923
jmp 0x579d
cmpl $0x1, -0x34(%rbp)
jne 0x56f9
leaq 0xbcc7(%rip), %rdi      # 0x113b0
leaq -0x30(%rbp), %rsi
callq 0x3030
jmp 0x56f4
jmp 0x579b
cmpl $0x3, -0x34(%rbp)
jne 0x5799
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
movl $0xa, %edx
callq 0x66c0
movl %eax, -0xc0(%rbp)
jmp 0x571d
movl -0xc0(%rbp), %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %eax, 0xbbb1(%rip)      # 0x112e0
jmp 0x5797
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5923
movq -0x40(%rbp), %rdi
callq 0x3150
movq %rax, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x38c0
jmp 0x5765
movl $0x1, -0x4(%rbp)
movl $0x1, -0x54(%rbp)
callq 0x34c0
jmp 0x578d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x34c0
jmp 0x5792
jmp 0x590e
jmp 0x5923
jmp 0x5799
jmp 0x579b
jmp 0x579d
movl $0x2, -0x34(%rbp)
jmp 0x57a6
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x53e9
cmpl $0x2, -0x34(%rbp)
je 0x57d8
leaq -0x30(%rbp), %rdi
callq 0x3910
jmp 0x57c5
movl $0x1, -0x4(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x590e
leaq 0xbbd1(%rip), %rdi      # 0x113b0
leaq 0x59b1(%rip), %rsi      # 0xb197
callq 0x6270
movb %al, -0xc1(%rbp)
jmp 0x57f3
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x5802
jmp 0x5900
leaq 0x5c5b(%rip), %rdi      # 0xb464
callq 0x3380
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x583d
callq 0x31c0
movl %eax, %edi
callq 0x3350
movq %rax, -0xd0(%rbp)
jmp 0x582e
movq -0xd0(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3510
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0x3410
jmp 0x5877
leaq 0x5beb(%rip), %rdx      # 0xb469
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x6710
jmp 0x5893
leaq 0xbb16(%rip), %rdi      # 0x113b0
leaq -0x88(%rbp), %rsi
callq 0x3390
leaq -0x88(%rbp), %rdi
callq 0x3578
leaq -0xa8(%rbp), %rdi
callq 0x3578
leaq -0xa9(%rbp), %rdi
callq 0x3330
jmp 0x5900
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x58f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3578
leaq -0xa9(%rbp), %rdi
callq 0x3330
jmp 0x5923
movl $0x0, -0x4(%rbp)
movl $0x1, -0x54(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3578
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x3578
movq -0x40(%rbp), %rdi
callq 0x3500
movq %rax, %rdi
callq 0x6700
nopl (%rax)