// File: /workspace/github_cpp_makefile_star2_O2/therealgymmy[P]HelicopterGame/src/control.cpp
// Function: control(void*)
void processMovement (ControlArg *controlArg) {
    Resources       *resources = controlArg->resources_;
    XHandler        *xhandler  = controlArg->xhandler_;
    pthread_mutex_t *mutex     = controlArg->mutex_;

    BombList      &bombs      = resources->bombs_;
    ExplosionList &explosions = resources->explosions_;
    Helicopter    &heli       = resources->heli_;
    TowerList     &towers     = resources->towers_;
    MissileList   &missiles   = resources->missiles_;
    HealthBar     &hp         = resources->healthBar_;
    Score         &score      = resources->score_;

    while (true) {
        if (!xhandler->showCredit()) {
            if (pthread_mutex_lock(mutex) == -1) {
                error("cannot lock mutex in control thread");
            }

            // helicopter
            heli.move();

            // explosions
            explosions.move();

            // towers
            towers.move();
            towers.fire(missiles);

            // missiles
            missiles.move();
            missiles.recharge();

            // bombs
            bombs.move();
            bombs.recharge();

            // collision detection
            detectCollision(bombs, towers, explosions, hp, score);
            detectCollision(missiles, heli, hp, score);
            detectCollision(heli, towers, hp, score);

            // score
            score.incScore(1);

            if (pthread_mutex_unlock(mutex) == -1) {
                error("cannot unlock mutex in control thread");
            }
        }
        usleep(1000 * 15);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq (%rdi), %r12
movq 0x8(%rdi), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rdi), %r15
leaq 0x20(%r12), %rax
movq %rax, 0x8(%rsp)
leaq 0x38(%r12), %rax
movq %rax, 0x18(%rsp)
leaq 0x80(%r12), %rbp
leaq 0x60(%r12), %r13
leaq 0x38(%rsp), %rbx
movq %r15, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
movq %r13, 0x10(%rsp)
movq 0x28(%rsp), %rax
cmpb $0x0, 0xf0(%rax)
jne 0x4a01
movq %r15, %rdi
callq 0x2290
cmpl $-0x1, %eax
jne 0x4686
movq %rbx, %rdi
leaq 0x1bdc(%rip), %rsi      # 0x6248
leaq 0x3(%rsp), %rdx
callq 0x3a9c
movq %rbx, %rdi
callq 0x3a7c
movq %rbx, %rdi
callq 0x20b0
movq 0x18(%rsp), %rdi
callq 0x4232
movq 0x8(%rsp), %rdi
callq 0x5114
movq %rbp, %rdi
callq 0x2b36
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2b92
movq %r13, %rdi
callq 0x4ecc
movq %r13, %rdi
callq 0x4f3c
movq %r12, %rdi
callq 0x4bc0
movq %r12, %rdi
callq 0x4c64
movq %rbp, %r13
movq (%r13), %r13
cmpq %rbp, %r13
je 0x47ca
movl 0x10(%r13), %r15d
movl 0x18(%r13), %eax
movl %eax, 0x4(%rsp)
movq %r12, %rbx
movq (%rbx), %rbx
cmpq %r12, %rbx
je 0x47c0
movl 0x10(%rbx), %r14d
movl %r15d, %eax
leaq 0x4b4e(%rip), %rcx      # 0x9254
subl (%rcx), %eax
cmpl %eax, %r14d
jl 0x46ec
leaq 0x4ad4(%rip), %rax      # 0x91e8
movl (%rax), %eax
addl %r15d, %eax
cmpl %eax, %r14d
jg 0x46ec
movl 0x14(%rbx), %ebp
movl $0xbb8, %eax            # imm = 0xBB8
cmpl %eax, %ebp
jg 0x46ec
leaq 0x4abb(%rip), %rax      # 0x91ec
movl (%rax), %eax
imull 0x4(%rsp), %eax
leaq 0x4b19(%rip), %rcx      # 0x9258
addl (%rcx), %eax
movl $0xbb8, %ecx            # imm = 0xBB8
subl %eax, %ecx
cmpl %ecx, %ebp
jl 0x46ec
cmpb $0x1, 0x1d(%r13)
jne 0x4786
movl 0xa8(%r12), %eax
cmpl $0x63, %eax
jg 0x477a
leal 0xa(%rax), %ecx
movl %ecx, 0xa8(%r12)
leal 0x50(,%rax,8), %eax
movl %eax, 0xa0(%r12)
addl $0x3e8, 0xb0(%r12) # imm = 0x3E8
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4a36
movq %rax, %rbx
movb $0x0, 0x1d(%r13)
leaq 0x4ab4(%rip), %rax      # 0x9254
addl (%rax), %r14d
leaq 0x4aae(%rip), %rax      # 0x9258
addl (%rax), %ebp
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x516e
jmp 0x46ec
movq 0x30(%rsp), %rbp
jmp 0x46d0
movq 0x10(%rsp), %r13
movq %r13, %rax
movq 0x20(%rsp), %r15
leaq 0x4a56(%rip), %rbx      # 0x9234
movq (%rax), %rax
cmpq %r13, %rax
je 0x48bd
movl 0x10(%rax), %ecx
movl 0x4c(%r12), %edx
movl %ecx, %esi
subl (%rbx), %esi
cmpl %esi, %edx
jl 0x47de
leaq 0x4a0f(%rip), %rsi      # 0x9210
addl (%rsi), %ecx
cmpl %ecx, %edx
jg 0x47de
movl 0x14(%rax), %ecx
movl 0x50(%r12), %edx
movl %ecx, %esi
leaq 0x4a20(%rip), %rdi      # 0x9238
subl (%rdi), %esi
cmpl %esi, %edx
jl 0x47de
leaq 0x49ef(%rip), %rsi      # 0x9214
addl (%rsi), %ecx
cmpl %ecx, %edx
jg 0x47de
movl $0x64, 0x5c(%r12)
movl 0xa8(%r12), %ecx
testl %ecx, %ecx
jle 0x485f
leal -0xa(%rcx), %edx
movl %edx, 0xa8(%r12)
leal -0x50(,%rcx,8), %edx
movl %edx, 0xa0(%r12)
cmpl $0xb, %ecx
jae 0x4897
movabsq $0x1f4000001f4, %rcx    # imm = 0x1F4000001F4
movq %rcx, 0x4c(%r12)
movl 0xb0(%r12), %ecx
movl $0xffffec78, %edx       # imm = 0xFFFFEC78
addl %edx, %ecx
movl $0x64, 0xa8(%r12)
movl $0x320, 0xa0(%r12) # imm = 0x320
jmp 0x489f
movl 0xb0(%r12), %ecx
addl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
movl %ecx, 0xb0(%r12)
movq %r13, %rdi
movq %rax, %rsi
callq 0x4a60
jmp 0x47de
movl 0x4c(%r12), %eax
movl 0x50(%r12), %ecx
movl 0xa8(%r12), %r10d
movl (%rbx), %edx
leaq 0x4910(%rip), %rsi      # 0x91e8
movl (%rsi), %esi
leaq 0x490b(%rip), %rdi      # 0x91ec
movl (%rdi), %edi
leaq 0x494e(%rip), %r8       # 0x9238
movl (%r8), %r8d
movq %rbp, %r9
movq (%r9), %r9
cmpq %rbp, %r9
je 0x49be
movl 0x10(%r9), %r11d
movl %r11d, %ebx
subl %edx, %ebx
cmpl %ebx, %eax
jl 0x48f0
addl %esi, %r11d
cmpl %r11d, %eax
jg 0x48f0
movl $0xbb8, %r11d           # imm = 0xBB8
cmpl %r11d, %ecx
jg 0x48f0
movl 0x18(%r9), %r11d
imull %edi, %r11d
addl %r8d, %r11d
movl $0xbb8, %ebx            # imm = 0xBB8
subl %r11d, %ebx
cmpl %ebx, %ecx
jl 0x48f0
movl $0x64, 0x5c(%r12)
movabsq $0x1f4000001f4, %r11    # imm = 0x1F4000001F4
movq %r11, 0x4c(%r12)
cmpl $0x15, %r10d
jl 0x497d
leal -0x1e(%r10), %ebx
movl %ebx, 0xa8(%r12)
leal -0xf0(,%r10,8), %r11d
movl %r11d, 0xa0(%r12)
movl 0xb0(%r12), %r11d
cmpl $0x1f, %r10d
jae 0x49a7
jmp 0x4985
movl 0xb0(%r12), %r11d
addl $0xffffec78, %r11d      # imm = 0xFFFFEC78
movl $0x64, 0xa8(%r12)
movl $0x320, 0xa0(%r12) # imm = 0x320
pushq $0x64
popq %rbx
addl $0xffffec78, %r11d      # imm = 0xFFFFEC78
movl %r11d, 0xb0(%r12)
movl %ebx, %r10d
jmp 0x48f0
incl 0xb0(%r12)
movq %r15, %rdi
callq 0x2140
cmpl $-0x1, %eax
leaq 0x38(%rsp), %rbx
jne 0x4a01
leaq 0x58(%rsp), %r14
movq %r14, %rdi
leaq 0x188d(%rip), %rsi      # 0x6274
leaq 0x3(%rsp), %rdx
callq 0x3a9c
movq %r14, %rdi
callq 0x3a7c
movq %r14, %rdi
callq 0x20b0
movl $0x3a98, %edi           # imm = 0x3A98
callq 0x2270
jmp 0x4643
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x4a22
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x20b0
jmp 0x4a2e
jmp 0x4a2b
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2330