// File: /workspace/github_c_makefile_star2_O2/kobolt[P]curses-collection/invaders/game.c
// Function: game_handle_bombs
int game_handle_bombs(void)
{
  int i, j, x, y, invader;

  if (game_state.bomb_pos_y >= 0) { /* Bomb is being dropped. */
    game_state.bomb_pos_y++;

    if (game_state.bomb_pos_y > GAME_MAP_HEIGHT) { /* Out of range. */
      game_state.bomb_pos_y = -1;
      return 0;
    }

    /* Check for collision against player. */
    if (game_state.bomb_pos_y == GAME_MAP_HEIGHT) {
      if ((game_state.bomb_pos_x >= game_state.player_pos - 2) && 
          (game_state.bomb_pos_x <= game_state.player_pos + 2)) {
        game_state.score -= 500;
        return 1;
      }
    }

    /* Check for collision with shields. */
    for (i = 0; i < GAME_SHIELDS; i++) {
      for (j = 0; j < GAME_SHIELD_PARTS; j++) {
        if (game_state.shield_intact[i][j]) {
          y = (i / 4 == 0) ? GAME_MAP_HEIGHT - 4 : GAME_MAP_HEIGHT - 5;
          x = 12 + ((i % 4) * 15) + j;
          if ((game_state.bomb_pos_y == y) &&
              (game_state.bomb_pos_x == x)) {
            game_state.shield_intact[i][j] = false;
            game_state.bomb_pos_y = -1;
          }
        }
      }
    }

  } else { /* Check if a new bomb should be dropped. */

    if (game_invaders_alive() == 0)
      return 0;

    /* Pick a random invader that's still alive. */
    do {
      invader = rand() % GAME_INVADERS;
    } while (! game_state.invader_alive[invader]);

    /* Check if anyone below that invader is still alive. */
    if (invader < 10) {
      if (game_state.invader_alive[invader + 20])
        invader += 20;
      else if (game_state.invader_alive[invader + 10])
        invader += 10;
    } else if (invader < 20) {
      if (game_state.invader_alive[invader + 10])
        invader += 10;
    }

    game_state.bomb_pos_y = game_state.invaders_pos_y + 
      ((invader / 10) * 4) + 2;
    game_state.bomb_pos_x = game_state.invaders_pos_x + 
      ((invader % 10) * 7) + 2;
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movzwl 0x32e3(%rip), %eax      # 0x5156
testw %ax, %ax
js 0x1e96
incl %eax
movw %ax, 0x32d5(%rip)       # 0x5156
cmpw $0x19, %ax
jl 0x1ee4
orw $-0x1, 0x32c7(%rip)     # 0x5156
xorl %ebx, %ebx
jmp 0x1fea
callq 0x1ab6
xorl %ebx, %ebx
testl %eax, %eax
je 0x1fea
pushq $0x1e
popq %r15
leaq 0x3290(%rip), %r14      # 0x5140
callq 0x1180
cltd
idivl %r15d
movslq %edx, %rax
cmpb $0x1, 0x1a(%rax,%r14)
jne 0x1eb0
cmpl $0x9, %edx
jg 0x1f87
cmpb $0x0, 0x2e(%rax,%r14)
je 0x1fa3
addq $0x14, %rax
movl %eax, %edx
jmp 0x1fb2
movswl 0x326d(%rip), %ecx      # 0x5158
cmpw $0x18, %ax
jne 0x1f12
movswl 0x3252(%rip), %edx      # 0x514a
leal -0x2(%rdx), %esi
cmpl %ecx, %esi
setg %sil
addl $0x2, %edx
cmpl %ecx, %edx
setl %dl
orb %sil, %dl
je 0x1f93
movl %ecx, %ecx
addq $-0xc, %rcx
leaq 0x3259(%rip), %rdx      # 0x5178
xorl %ebx, %ebx
xorl %esi, %esi
cmpq $0x8, %rsi
je 0x1fea
movl %esi, %edi
andl $0x3, %edi
imulq $0xf, %rdi, %r8
movq %rcx, %rdi
subq %r8, %rdi
cmpq $0x4, %rsi
movl $0x0, %r8d
adcl $0x13, %r8d
xorl %r9d, %r9d
cmpq $0xa, %r9
je 0x1f7e
cmpb $0x1, (%rdx,%r9)
jne 0x1f79
movswl %ax, %r10d
cmpl %r10d, %r8d
jne 0x1f79
cmpq %r9, %rdi
jne 0x1f79
movb $0x0, (%rdx,%r9)
orw $-0x1, 0x31e1(%rip)     # 0x5156
movw $0xffff, %ax            # imm = 0xFFFF
incq %r9
jmp 0x1f4d
incq %rsi
addq $0xa, %rdx
jmp 0x1f23
cmpl $0x13, %edx
ja 0x1fb2
leal 0xa(%rdx), %eax
movl %eax, %ecx
jmp 0x1fa9
addq $-0x1f4, 0x31a2(%rip) # imm = 0xFE0C
pushq $0x1
popq %rbx
jmp 0x1fea
leal 0xa(%rdx), %ecx
movslq %ecx, %rax
cmpb $0x0, 0x1a(%rax,%r14)
cmovnel %ecx, %edx
movsbl %dl, %eax
movb $0xa, %cl
idivb %cl
movsbl %ah, %ecx
movsbl %al, %eax
shll $0x2, %eax
addw 0x3183(%rip), %ax       # 0x514c
addl $0x2, %eax
movw %ax, 0x3183(%rip)       # 0x5156
imull $0x7, %ecx, %eax
movsbl %al, %eax
addw 0x316e(%rip), %ax       # 0x514e
addl $0x2, %eax
movw %ax, 0x316e(%rip)       # 0x5158
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)