// File: /workspace/github_c_makefile_star2_O3/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
movl $0x1f4, %r14d           # imm = 0x1F4
movl $0x1f4, %r12d           # imm = 0x1F4
cmpl $0x2, %edi
jl 0x27e74
movq %rsi, %rbx
movl %edi, %r15d
movl $0x1, %r13d
movl %r13d, %r13d
movq (%rbx,%r13,8), %rdi
callq 0xab78
movl $0x1, %ecx
testl %eax, %eax
jne 0x27e6c
movq 0x8(%rbx,%r13,8), %rdi
callq 0x21e0
movl %eax, %r14d
movq 0x10(%rbx,%r13,8), %rdi
callq 0x21e0
movl %eax, %r12d
movl $0x3, %ecx
addl %ecx, %r13d
cmpl %r15d, %r13d
jl 0x27e38
movaps 0x8525(%rip), %xmm0     # 0x303a0
leaq 0x27f52(%rip), %rax     # 0x4fdd4
movups %xmm0, (%rax)
movl $0x64, 0x10(%rax)
callq 0xac5a
leaq 0xa0d8(%rip), %rdi      # 0x31f70
movl %r14d, %esi
movl %r12d, %edx
callq 0x20330
movzbl %al, %ecx
leaq 0x9f0d(%rip), %rbx      # 0x31dba
leaq 0xa069(%rip), %rdx      # 0x31f1d
movq %rbx, %rdi
movl $0x10c, %esi            # imm = 0x10C
callq 0x729c
xorl %edi, %edi
callq 0x22ce8
callq 0x27285
movzbl %al, %ecx
leaq 0xa0a5(%rip), %rdx      # 0x31f7c
movq %rbx, %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x729c
leaq 0xa0c0(%rip), %rdi      # 0x31fab
callq 0x23336
callq 0x2408a
movl $0x20, %edi
callq 0x2f2ed
leaq 0x3ca3a(%rip), %rcx     # 0x64940
movq $0x20, (%rcx)
movq %rax, 0x8(%rcx)
movb $0x1, 0x10(%rcx)
callq 0x27484
callq 0xbd5b
callq 0xa094
movzbl %al, %ecx
leaq 0xa086(%rip), %rdx      # 0x31fb4
movq %rbx, %rdi
movl $0x11c, %esi            # imm = 0x11C
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x729c