// File: IsaacLaw12[P]RayTracer/./src/raytracer.cpp
// Function: parse_args(int, char**, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
int parse_args(int argc, char*argv[], int &num_threads, std::string &driver_file, std::string &save_folder){
    int status = 0;

    // Set Defaults
    num_threads = 1;

    // Parse flags
    for (int i=1; i<argc-2; i++){
        std::string arg = argv[i];
        if (arg == "-t" || arg == "--threads"){
            int valid_int = 0;
            num_threads = parse_int(std::string(argv[++i]), valid_int);
            if (valid_int != 0 || (!(i < argc-2))){
                std::cout << "Number of threads not specified\n";
                status = 1;
                num_threads = 1;
            } else{
                num_threads = std::max(std::min(num_threads, 100), 1);
            }
        }
    }
    if (!(argc >= 3)){
        status = 1;
    }
    // Extract two mandatory arguments
    if (status == 0){
        driver_file = argv[argc-2];
        save_folder = parse_folder_name(argv[argc-1]);
    } else{
        std::cout << "Error: run with " << argv[0] << " <driver_file> <save_folder>\n\n"
                  << "    driver_file: A scene specification file, more detail in scene_driver.md\n"
                  << "    save_folder: The folder to save output images to. If it already exists current\n"
                  << "        contents will be replaced\n\n"
                  << "    Optional:\n"
                  << "         --threads, -t  specify number of threads\n\n";
    }
    return status;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movl %edi, 0x134(%rsp)
movq %rsi, 0x128(%rsp)
movq %rdx, 0x120(%rsp)
movq %rcx, 0x118(%rsp)
movq %r8, 0x110(%rsp)
movl $0x0, 0x10c(%rsp)
movq 0x120(%rsp), %rax
movl $0x1, (%rax)
movl $0x1, 0x108(%rsp)
movl 0x108(%rsp), %eax
movl 0x134(%rsp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x13276
movq 0x128(%rsp), %rax
movslq 0x108(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x48(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x45f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
callq 0x11e60
jmp 0x1300f
leaq 0xe7(%rsp), %rdi
callq 0x43c0
leaq 0x4ed7e(%rip), %rsi     # 0x61da1
leaq 0xe8(%rsp), %rdi
callq 0x13c40
movb %al, 0x47(%rsp)
jmp 0x13036
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x13067
jmp 0x13040
leaq 0x4ed5d(%rip), %rsi     # 0x61da4
leaq 0xe8(%rsp), %rdi
callq 0x13c40
movb %al, 0x46(%rsp)
jmp 0x1305a
movb 0x46(%rsp), %al
testb $0x1, %al
jne 0x13067
jmp 0x13241
movl $0x0, 0xd0(%rsp)
movq 0x128(%rsp), %rax
movslq 0x108(%rsp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, 0x108(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x45f0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x11e60
jmp 0x130c2
leaq 0xb0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x12d80
movl %eax, 0x2c(%rsp)
jmp 0x130dd
movl 0x2c(%rsp), %ecx
movq 0x120(%rsp), %rax
movl %ecx, (%rax)
leaq 0xb0(%rsp), %rdi
callq 0x4200
leaq 0xaf(%rsp), %rdi
callq 0x43c0
cmpl $0x0, 0xd0(%rsp)
jne 0x13128
movl 0x108(%rsp), %eax
movl 0x134(%rsp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jl 0x131e3
movq 0x87e91(%rip), %rdi     # 0x9afc0
leaq 0x4ec78(%rip), %rsi     # 0x61dae
callq 0x4360
jmp 0x1313d
movl $0x1, 0x10c(%rsp)
movq 0x120(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1323f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe7(%rsp), %rdi
callq 0x43c0
jmp 0x13422
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x13264
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x131d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x4200
leaq 0xaf(%rsp), %rdi
callq 0x43c0
jmp 0x13264
movq 0x120(%rsp), %rdi
movl $0x64, 0xa8(%rsp)
leaq 0xa8(%rsp), %rsi
callq 0x13cb0
movq %rax, 0x20(%rsp)
jmp 0x1320a
movq 0x20(%rsp), %rdi
movl $0x1, 0xa4(%rsp)
leaq 0xa4(%rsp), %rsi
callq 0x13c70
movq %rax, 0x18(%rsp)
jmp 0x1322e
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movq 0x120(%rsp), %rax
movl %ecx, (%rax)
jmp 0x13241
leaq 0xe8(%rsp), %rdi
callq 0x4200
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x12fb2
leaq 0xe8(%rsp), %rdi
callq 0x4200
jmp 0x13422
cmpl $0x3, 0x134(%rsp)
jge 0x1328b
movl $0x1, 0x10c(%rsp)
cmpl $0x0, 0x10c(%rsp)
jne 0x13393
movq 0x128(%rsp), %rax
movl 0x134(%rsp), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
movq 0x118(%rsp), %rdi
callq 0x4480
movq 0x128(%rsp), %rax
movl 0x134(%rsp), %ecx
decl %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x45f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rdi
callq 0x11e60
jmp 0x13301
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x12e10
jmp 0x13315
movq 0x110(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4420
leaq 0x80(%rsp), %rdi
callq 0x4200
leaq 0x60(%rsp), %rdi
callq 0x4200
leaq 0x5f(%rsp), %rdi
callq 0x43c0
jmp 0x13413
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x13384
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x4200
leaq 0x5f(%rsp), %rdi
callq 0x43c0
jmp 0x13422
movq 0x87c26(%rip), %rdi     # 0x9afc0
leaq 0x4ea2e(%rip), %rsi     # 0x61dcf
callq 0x4360
movq %rax, %rdi
movq 0x128(%rsp), %rax
movq (%rax), %rsi
callq 0x4360
movq %rax, %rdi
leaq 0x4ea1d(%rip), %rsi     # 0x61de0
callq 0x4360
movq %rax, %rdi
leaq 0x4ea2d(%rip), %rsi     # 0x61dff
callq 0x4360
movq %rax, %rdi
leaq 0x4ea6b(%rip), %rsi     # 0x61e4c
callq 0x4360
movq %rax, %rdi
leaq 0x4eab0(%rip), %rsi     # 0x61ea0
callq 0x4360
movq %rax, %rdi
leaq 0x4eac5(%rip), %rsi     # 0x61ec4
callq 0x4360
movq %rax, %rdi
leaq 0x4eac5(%rip), %rsi     # 0x61ed3
callq 0x4360
movl 0x10c(%rsp), %eax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xd8(%rsp), %rdi
callq 0x45e0
nop