// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %r14
movq 0x10(%rdi), %r15
leaq 0x20(%rax), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x38(%rax), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x80(%rax), %r13
movq %rax, (%rsp)
addq $0x60, %rax
movq %rax, 0x8(%rsp)
movq %r14, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq %r13, 0x38(%rsp)
cmpb $0x0, 0xf0(%r14)
jne 0x529f
movq %r15, %rdi
callq 0x22a0
cmpl $-0x1, %eax
je 0x52ae
movq 0x20(%rsp), %rdi
callq 0x4ca0
movq 0x18(%rsp), %rdi
callq 0x5984
movq %r13, %rdi
callq 0x2c52
movq %r13, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2cc0
movq %rbx, %rdi
callq 0x576c
movq %rbx, %rdi
callq 0x581e
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x55d4
movq %rbx, %rdi
callq 0x56d4
movq %rbx, %rdi
movq 0x80(%rbx), %r15
cmpq %r13, %r15
leaq 0x42d3(%rip), %rsi      # 0x91f8
je 0x504c
movq (%rdi), %r12
cmpq %rdi, %r12
je 0x503b
movl 0x10(%r15), %r13d
movl 0x18(%r15), %eax
movl %eax, 0x14(%rsp)
leaq 0x431a(%rip), %rax      # 0x9264
movl (%rax), %eax
movl 0x10(%r12), %r14d
movl %r13d, %ecx
subl %eax, %ecx
cmpl %ecx, %r14d
jl 0x502e
movl (%rsi), %ecx
addl %r13d, %ecx
cmpl %ecx, %r14d
jg 0x502e
movl 0x14(%r12), %ebp
movl $0xbb8, %ecx            # imm = 0xBB8
cmpl %ecx, %ebp
jg 0x502e
leaq 0x4276(%rip), %rcx      # 0x91fc
movl (%rcx), %ecx
imull 0x14(%rsp), %ecx
leaq 0x42d4(%rip), %rdx      # 0x9268
addl (%rdx), %ecx
movl $0xbb8, %edx            # imm = 0xBB8
subl %ecx, %edx
cmpl %edx, %ebp
jl 0x502e
cmpb $0x1, 0x1d(%r15)
jne 0x4fd7
movl 0xa8(%rdi), %eax
cmpl $0x63, %eax
jg 0x4fcd
leal 0xa(%rax), %ecx
movl %ecx, 0xa8(%rdi)
leal 0x50(,%rax,8), %eax
movl %eax, 0xa0(%rdi)
addl $0x3e8, 0xb0(%rdi)      # imm = 0x3E8
movq (%r12), %rbx
decq 0x10(%rdi)
movq %r12, %rdi
callq 0x2330
movl $0x20, %esi
movq %r12, %rdi
callq 0x2200
movb $0x0, 0x1d(%r15)
leaq 0x4264(%rip), %r12      # 0x9264
addl (%r12), %r14d
leaq 0x425d(%rip), %rax      # 0x9268
addl (%rax), %ebp
movq 0x18(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x5a04
movq (%rsp), %rdi
movl (%r12), %eax
movq %rbx, %r12
leaq 0x41ca(%rip), %rsi      # 0x91f8
movq (%r12), %r12
cmpq %rdi, %r12
jne 0x4f4c
movq (%r15), %r15
movq 0x38(%rsp), %r13
cmpq %r13, %r15
jne 0x4f2b
movq 0x8(%rsp), %r8
movq (%r8), %r12
cmpq %r8, %r12
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
je 0x516f
leaq 0x41d6(%rip), %rax      # 0x9244
movl (%rax), %eax
movl 0x10(%r12), %ecx
movl 0x4c(%rdi), %edx
movl %ecx, %esi
subl %eax, %esi
cmpl %esi, %edx
jl 0x5162
leaq 0x4195(%rip), %rsi      # 0x9220
addl (%rsi), %ecx
cmpl %ecx, %edx
jg 0x5162
movl 0x14(%r12), %ecx
movl 0x50(%rdi), %edx
movl %ecx, %esi
leaq 0x41a2(%rip), %r9       # 0x9248
subl (%r9), %esi
cmpl %esi, %edx
jl 0x5162
leaq 0x416c(%rip), %rsi      # 0x9224
addl (%rsi), %ecx
cmpl %ecx, %edx
jg 0x5162
movl $0x64, 0x5c(%rdi)
movl 0xa8(%rdi), %eax
testl %eax, %eax
jle 0x50ee
leal -0xa(%rax), %ecx
movl %ecx, 0xa8(%rdi)
leal -0x50(,%rax,8), %ecx
movl %ecx, 0xa0(%rdi)
cmpl $0xb, %eax
jae 0x511f
movabsq $0x1f4000001f4, %rax    # imm = 0x1F4000001F4
movq %rax, 0x4c(%rdi)
movl 0xb0(%rdi), %eax
movl $0xffffec78, %ecx       # imm = 0xFFFFEC78
addl %ecx, %eax
movl $0x64, 0xa8(%rdi)
movl $0x320, 0xa0(%rdi)      # imm = 0x320
jmp 0x5125
movl 0xb0(%rdi), %eax
addl $0xfffffc18, %eax       # imm = 0xFFFFFC18
movl %eax, 0xb0(%rdi)
movq (%r12), %rbx
decq 0x70(%rdi)
movq %r12, %rdi
callq 0x2330
movl $0x18, %esi
movq %r12, %rdi
callq 0x2200
movq (%rsp), %rdi
leaq 0x40ec(%rip), %rax      # 0x9244
movl (%rax), %eax
movq %rbx, %r12
movq 0x8(%rsp), %r8
movq (%r12), %r12
cmpq %r8, %r12
jne 0x5070
movq 0x80(%rdi), %rax
cmpq %r13, %rax
movabsq $0x1f4000001f4, %r12    # imm = 0x1F4000001F4
je 0x5284
movq (%rsp), %rsi
movl 0x4c(%rsi), %ecx
movl 0x50(%rsi), %edx
movl 0xa8(%rsi), %r10d
leaq 0x40a3(%rip), %rsi      # 0x9244
movl (%rsi), %esi
leaq 0x404e(%rip), %rdi      # 0x91f8
movl (%rdi), %edi
leaq 0x4049(%rip), %r8       # 0x91fc
movl (%r8), %r8d
leaq 0x408b(%rip), %r9       # 0x9248
movl (%r9), %r9d
movl 0x10(%rax), %r11d
movl %r11d, %ebx
subl %esi, %ebx
cmpl %ebx, %ecx
jl 0x5278
addl %edi, %r11d
cmpl %r11d, %ecx
jg 0x5278
movl $0xbb8, %r11d           # imm = 0xBB8
cmpl %r11d, %edx
jg 0x5278
movl 0x18(%rax), %r11d
imull %r8d, %r11d
addl %r9d, %r11d
movl $0xbb8, %ebx            # imm = 0xBB8
subl %r11d, %ebx
cmpl %ebx, %edx
jl 0x5278
movq (%rsp), %rbx
movl $0x64, 0x5c(%rbx)
movq %r12, 0x4c(%rbx)
cmpl $0x15, %r10d
jl 0x5240
leal -0x1e(%r10), %ebp
movl %ebp, 0xa8(%rbx)
leal -0xf0(,%r10,8), %r11d
movl %r11d, 0xa0(%rbx)
movl 0xb0(%rbx), %r11d
cmpl $0x1f, %r10d
jae 0x5267
jmp 0x5247
movl 0xb0(%rbx), %r11d
addl $0xffffec78, %r11d      # imm = 0xFFFFEC78
movl $0x64, 0xa8(%rbx)
movl $0x320, 0xa0(%rbx)      # imm = 0x320
movl $0x64, %ebp
addl $0xffffec78, %r11d      # imm = 0xFFFFEC78
movl %r11d, 0xb0(%rbx)
movl %ebp, %r10d
movq (%rax), %rax
cmpq %r13, %rax
jne 0x51c0
movq (%rsp), %rax
incl 0xb0(%rax)
movq %r15, %rdi
callq 0x2160
cmpl $-0x1, %eax
je 0x5320
movl $0x3a98, %edi           # imm = 0x3A98
callq 0x2280
jmp 0x4ea2
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x40(%rsp), %rbx
movq $0x23, (%rbx)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2380
movq %rax, (%r14)
movq (%rbx), %rcx
movq %rcx, 0x10(%r14)
movups 0xf72(%rip), %xmm0      # 0x6258
movups %xmm0, 0x10(%rax)
movups 0xf57(%rip), %xmm0      # 0x6248
movups %xmm0, (%rax)
movl $0x64616572, 0x1f(%rax) # imm = 0x64616572
movq %rcx, 0x8(%r14)
movb $0x0, (%rax,%rcx)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x3cdf(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %rdi
callq 0x20c0
jmp 0x5397
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x40(%rsp), %rbx
movq $0x25, (%rbx)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2380
movq %rax, (%r14)
movq (%rbx), %rcx
movq %rcx, 0x10(%r14)
movabsq $0x646165726874206c, %rdx # imm = 0x646165726874206C
movq %rdx, 0x1d(%rax)
movups 0xf1e(%rip), %xmm0      # 0x6284
movups %xmm0, 0x10(%rax)
movups 0xf03(%rip), %xmm0      # 0x6274
movups %xmm0, (%rax)
movq %rcx, 0x8(%r14)
movb $0x0, (%rax,%rcx)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x3c66(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %rdi
callq 0x20c0
movl $0x1, %edi
callq 0x2230
jmp 0x53a3
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x53bb
movq (%r15), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2350
nop