// File: therealgymmy[P]HelicopterGame/src/control.cpp
// Function: processMovement(ControlArg*)
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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
addq $0xb0, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8130
testb $0x1, %al
jne 0x94f8
movq -0x20(%rbp), %rdi
callq 0x3360
cmpl $-0x1, %eax
jne 0x93b0
leaq -0x79(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x3410
movq -0xc0(%rbp), %rdx
leaq 0x3f07(%rip), %rsi      # 0xd250
leaq -0x78(%rbp), %rdi
callq 0x5430
jmp 0x9354
leaq -0x78(%rbp), %rdi
callq 0x53f0
jmp 0x935f
leaq -0x78(%rbp), %rdi
callq 0x3120
leaq -0x79(%rbp), %rdi
callq 0x3290
jmp 0x93b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x93a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3120
leaq -0x79(%rbp), %rdi
callq 0x3290
jmp 0x9507
movq -0x38(%rbp), %rdi
callq 0x8730
movq -0x30(%rbp), %rdi
callq 0xb9b0
movq -0x40(%rbp), %rdi
callq 0x4bf0
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4d10
movq -0x48(%rbp), %rdi
callq 0xb130
movq -0x48(%rbp), %rdi
callq 0xb290
movq -0x28(%rbp), %rdi
callq 0xa510
movq -0x28(%rbp), %rdi
callq 0xa720
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x9520
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x97a0
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x9970
movq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x9b20
movq -0x20(%rbp), %rdi
callq 0x3180
cmpl $-0x1, %eax
jne 0x94f6
leaq -0xb1(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x3410
movq -0xc8(%rbp), %rdx
leaq 0x3dfc(%rip), %rsi      # 0xd27c
leaq -0xb0(%rbp), %rdi
callq 0x5430
jmp 0x948e
leaq -0xb0(%rbp), %rdi
callq 0x53f0
jmp 0x949c
leaq -0xb0(%rbp), %rdi
callq 0x3120
leaq -0xb1(%rbp), %rdi
callq 0x3290
jmp 0x94f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x94e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3120
leaq -0xb1(%rbp), %rdi
callq 0x3290
jmp 0x9507
jmp 0x94f8
movl $0x3a98, %edi           # imm = 0x3A98
callq 0x3330
jmp 0x9308
movq -0x88(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)