// File: /workspace/github_c_makefile_star2_O1/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 0x28271
movq %rsi, %rbx
movl %edi, %r15d
movl $0x1, %r13d
movl %r13d, %r13d
movq (%rbx,%r13,8), %rdi
callq 0xaddf
movl $0x1, %ecx
testl %eax, %eax
jne 0x28269
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 0x28235
movaps 0x8138(%rip), %xmm0     # 0x303b0
leaq 0x27b65(%rip), %rax     # 0x4fde4
movups %xmm0, (%rax)
movl $0x64, 0x10(%rax)
callq 0xaee1
leaq 0x9ceb(%rip), %rdi      # 0x31f80
movl %r14d, %esi
movl %r12d, %edx
callq 0x205f6
movzbl %al, %ecx
leaq 0x9b20(%rip), %rbx      # 0x31dca
leaq 0x9c7c(%rip), %rdx      # 0x31f2d
movq %rbx, %rdi
movl $0x10c, %esi            # imm = 0x10C
callq 0x722f
xorl %edi, %edi
callq 0x22f99
callq 0x27630
movzbl %al, %ecx
leaq 0x9cb8(%rip), %rdx      # 0x31f8c
movq %rbx, %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x722f
leaq 0x9cd3(%rip), %rdi      # 0x31fbb
callq 0x235e7
callq 0x2433e
movl $0x20, %edi
callq 0x2f9b8
leaq 0x3c64d(%rip), %rcx     # 0x64950
movq $0x20, (%rcx)
movq %rax, 0x8(%rcx)
movb $0x1, 0x10(%rcx)
callq 0x27833
callq 0xc05a
callq 0xa2bf
movzbl %al, %ecx
leaq 0x9c99(%rip), %rdx      # 0x31fc4
movq %rbx, %rdi
movl $0x11c, %esi            # imm = 0x11C
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x722f