// File: /workspace/github_cpp_makefile_star2_O3/therealgymmy[P]HelicopterGame/src/main.cpp
// Function: main
int main () {
    // set up for multithreading
    XInitThreads();

    Resources resources;
    XHandler xhandler(&resources);

    /*
    updateSize(xhandler.windowAttributes());
    Tower::setDelay(2);
    Missile::setDelay(2);
    Bomb::setDelay(4);

    xhandler.setShowCredit(true);
    */

    pthread_mutex_t mutex;
    pthread_mutex_init(&mutex, NULL);

    // dispatch rendering thread
    RenderArg renderArg = { &resources, &xhandler, &mutex };
    pthread_t renderT;
    pthread_create(&renderT, NULL, render, static_cast<void*>(&renderArg));

    // dispatch events thread
    EventsArg eventsArg = { &resources, &xhandler, &mutex };
    pthread_t eventsT;
    pthread_create(&eventsT, NULL, events, static_cast<void*>(&eventsArg));

    // dispatch controlling thread
    ControlArg controlArg = { &resources, &xhandler, &mutex };
    pthread_t controlT;
    pthread_create(&controlT, NULL, control, static_cast<void*>(&controlArg));

    xhandler.setShowCredit(true);
    usleep(1000 * 2000);
    xhandler.setShowCredit(false);

    /*
    // cleans credit screen
    usleep(1000 * 1000 * 2);
    xhandler.setShowCredit(false);
    */

    // join threads
    pthread_join(renderT,  NULL);
    pthread_join(eventsT,  NULL);
    pthread_join(controlT, NULL);

    pthread_mutex_destroy(&mutex);

    return 0;

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x240, %rsp            # imm = 0x240
callq 0x2190
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
callq 0x2858
leaq 0x148(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e40
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x22b0
leaq 0x78(%rsp), %rcx
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
movq %r15, 0x10(%rcx)
leaq 0x1ac3(%rip), %rdx      # 0x41a9
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x2390
leaq 0x60(%rsp), %rcx
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
movq %r15, 0x10(%rcx)
leaq 0x1c8f(%rip), %rdx      # 0x4398
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x2390
leaq 0x48(%rsp), %rcx
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
movq %r15, 0x10(%rcx)
leaq 0x2728(%rip), %rdx      # 0x4e54
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x2390
movb $0x1, 0x238(%rsp)
movl $0x1e8480, %edi         # imm = 0x1E8480
callq 0x2280
movb $0x0, 0x238(%rsp)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x21c0
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x21c0
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x21c0
leaq 0x20(%rsp), %rdi
callq 0x2220
leaq 0x148(%rsp), %rdi
callq 0x37f6
leaq 0x110(%rsp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x27b2
movq (%rdi), %r15
movl $0x20, %esi
callq 0x2200
movq %r15, %rdi
cmpq %r14, %r15
jne 0x279d
leaq 0xf0(%rsp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x27d7
movq (%rdi), %r15
movl $0x18, %esi
callq 0x2200
movq %r15, %rdi
cmpq %r14, %r15
jne 0x27c2
leaq 0xb0(%rsp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x27fc
movq (%rdi), %r15
movl $0x20, %esi
callq 0x2200
movq %r15, %rdi
cmpq %r14, %r15
jne 0x27e7
movq 0x90(%rsp), %rdi
cmpq %rbx, %rdi
je 0x281e
movq (%rdi), %r14
movl $0x20, %esi
callq 0x2200
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x2809
xorl %eax, %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
jmp 0x2842
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x37f6
leaq 0x90(%rsp), %rdi
callq 0x2956
movq %rbx, %rdi
callq 0x2350
nop