// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %r15d
pushq $0x1
popq %rbx
movl $0x1f4, -0x30(%rbp)     # imm = 0x1F4
movl $0x1f4, -0x2c(%rbp)     # imm = 0x1F4
movl %ebx, %r13d
cmpl %r15d, %r13d
jge 0x24f07
movl %r13d, %r12d
movq (%r14,%r12,8), %rdi
callq 0x98e1
movl %ebx, %ecx
testl %eax, %eax
jne 0x24f02
movq 0x8(%r14,%r12,8), %rdi
callq 0x21e0
movl %eax, -0x30(%rbp)
movq 0x10(%r14,%r12,8), %rdi
callq 0x21e0
movl %eax, -0x2c(%rbp)
pushq $0x3
popq %rcx
addl %ecx, %r13d
jmp 0x24ece
movaps 0x6482(%rip), %xmm0     # 0x2b390
leaq 0x25ecf(%rip), %rax     # 0x4ade4
movups %xmm0, (%rax)
movl $0x64, 0x10(%rax)
callq 0x999e
leaq 0x801d(%rip), %rdi      # 0x2cf48
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x1ecc0
movzbl %al, %ecx
leaq 0x7e52(%rip), %rbx      # 0x2cd92
leaq 0x7fae(%rip), %rdx      # 0x2cef5
movq %rbx, %rdi
movl $0x10c, %esi            # imm = 0x10C
callq 0x6903
xorl %edi, %edi
callq 0x20f4a
callq 0x2452c
movzbl %al, %ecx
leaq 0x7fea(%rip), %rdx      # 0x2cf54
movq %rbx, %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x6903
leaq 0x8005(%rip), %rdi      # 0x2cf83
callq 0x214ed
callq 0x21f3a
callq 0x22435
callq 0x24728
callq 0xa790
callq 0x8f2c
movzbl %al, %ecx
leaq 0x7fe6(%rip), %rdx      # 0x2cf8c
movq %rbx, %rdi
movl $0x11c, %esi            # imm = 0x11C
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6903