// File: 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 %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movl $0x0, -0x4(%rbp)
callq 0x31c0
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x3ba0
movq -0x258(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x5d80
jmp 0x399f
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x270(%rbp)
leaq -0x1f0(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x3370
movq -0x270(%rbp), %rsi
movq -0x268(%rbp), %rax
leaq -0xc0(%rbp), %rcx
movq %rcx, -0x278(%rbp)
movq %rcx, -0x208(%rbp)
leaq -0x1b8(%rbp), %rcx
movq %rcx, -0x260(%rbp)
movq %rcx, -0x200(%rbp)
movq %rax, -0x1f8(%rbp)
leaq 0x3cbd(%rip), %rdx      # 0x76c0
leaq -0x210(%rbp), %rdi
leaq -0x208(%rbp), %rcx
callq 0x3450
movq -0x278(%rbp), %rdx
movq -0x270(%rbp), %rsi
movq -0x260(%rbp), %rcx
movq -0x268(%rbp), %rax
movq %rdx, -0x228(%rbp)
movq %rcx, -0x220(%rbp)
movq %rax, -0x218(%rbp)
leaq 0x3f62(%rip), %rdx      # 0x79b0
leaq -0x230(%rbp), %rdi
leaq -0x228(%rbp), %rcx
callq 0x3450
movq -0x278(%rbp), %rdx
movq -0x270(%rbp), %rsi
movq -0x260(%rbp), %rcx
movq -0x268(%rbp), %rax
movq %rdx, -0x248(%rbp)
movq %rcx, -0x240(%rbp)
movq %rax, -0x238(%rbp)
leaq 0x57c7(%rip), %rdx      # 0x9260
leaq -0x250(%rbp), %rdi
leaq -0x248(%rbp), %rcx
callq 0x3450
movq -0x260(%rbp), %rdi
movl $0x1, %esi
callq 0x3c90
jmp 0x3abf
movl $0x1e8480, %edi         # imm = 0x1E8480
callq 0x3330
jmp 0x3acb
leaq -0x1b8(%rbp), %rdi
xorl %esi, %esi
callq 0x3c90
jmp 0x3adb
movq -0x210(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3210
jmp 0x3aed
movq -0x230(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3210
jmp 0x3aff
movq -0x250(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3210
jmp 0x3b11
leaq -0x1f0(%rbp), %rdi
callq 0x32c0
movl $0x0, -0x4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x6630
leaq -0xc0(%rbp), %rdi
callq 0x3cc0
movl -0x4(%rbp), %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x3b7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x6630
leaq -0xc0(%rbp), %rdi
callq 0x3cc0
movq -0x1c0(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)
nopl (%rax)