// File: /workspace/github_c_makefile_star2_O0/FredTheDino[P]Fog/src/engine/unix_main.cpp
// Function: Fog::init(int, char**)
void init(int argc, char **argv) {
    // parse command line arguments
    using namespace Util;
    u32 win_width = 500;
    u32 win_height = 500;
    int index = 1;
    while (index < argc) {
        switch (parse_str_argument(argv[index])) {
        case resolution:
            win_width = (u32) atoi(argv[index + 1]);
            win_height = (u32) atoi(argv[index + 2]);
            index += 3;
            break;
        default:
            // TODO(ed): The editor wants commandline arguments,
            // this gets annoying and confusing if both complain...
            // I'm trying out putting the responsibility on the other
            // process... You want wanna do some sort of copying, of commands
            // that isn't handled here, passing them down to the next level.
            //
            // It might be smarter to have a centralized place for this,
            // it would group the functionally together and noone would
            // accidentally take someones arguments. Needs consideration.
            //
            // LOG("Invalid argument '%s'", argv[index]);
            index++;
        }
    }

    using namespace Input;
    random_seed(FOG_RANDOM_SEED);

    Util::do_all_allocations();
    ASSERT(Renderer::init("Hello there", win_width, win_height),
           "Failed to initalize renderer");
    Renderer::turn_on_camera(0);

    ASSERT(Mixer::init(),
            "Failed to initalize audio mixer");
    Asset::load("data.fog");
    ASSERT(Logic::init(), "Failed to initalize logic system");

    ASSERT(Physics::init(), "Failed to intalize physics");

#ifdef DEBUG
    register_debug_keybinds();
#endif
    // This way, you have to register all mappings
    // in the setup.
    ASSERT(Input::init(), "Failed to initalize input");
    ASSERT(Util::init(), "Failed to initalize utilities");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1f4, -0x14(%rbp)     # imm = 0x1F4
movl $0x1f4, -0x18(%rbp)     # imm = 0x1F4
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x369bb
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x106b0
testl %eax, %eax
jne 0x369b0
jmp 0x36973
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x21e0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x21e0
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x1c(%rbp)
jmp 0x369b9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x36954
movl $0xcafebabe, %edi       # imm = 0xCAFEBABE
callq 0xe180
callq 0x107a0
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq 0x10589(%rip), %rdi     # 0x46f60
callq 0x2d680
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x103bc(%rip), %rdi     # 0x46daa
movl $0x10c, %esi            # imm = 0x10C
leaq 0x10513(%rip), %rdx     # 0x46f0d
movzbl %al, %ecx
callq 0xb210
xorl %edi, %edi
callq 0x2fcb0
callq 0x35cc0
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x1038a(%rip), %rdi     # 0x46daa
movl $0x110, %esi            # imm = 0x110
leaq 0x10540(%rip), %rdx     # 0x46f6c
movzbl %al, %ecx
callq 0xb210
leaq 0x10560(%rip), %rdi     # 0x46f9b
callq 0x30730
callq 0x31710
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x10353(%rip), %rdi     # 0x46daa
movl $0x112, %esi            # imm = 0x112
leaq 0x10541(%rip), %rdx     # 0x46fa4
movzbl %al, %ecx
callq 0xb210
callq 0x31e90
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x10328(%rip), %rdi     # 0x46daa
movl $0x114, %esi            # imm = 0x114
leaq 0x10546(%rip), %rdx     # 0x46fd4
movzbl %al, %ecx
callq 0xb210
callq 0x35fc0
callq 0x11e10
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x102f8(%rip), %rdi     # 0x46daa
movl $0x11b, %esi            # imm = 0x11B
leaq 0x10542(%rip), %rdx     # 0x47000
movzbl %al, %ecx
callq 0xb210
callq 0xf640
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x102cd(%rip), %rdi     # 0x46daa
movl $0x11c, %esi            # imm = 0x11C
leaq 0x10540(%rip), %rdx     # 0x47029
movzbl %al, %ecx
callq 0xb210
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)