// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
movzwl 0x325c(%rip), %eax      # 0x5156
testw %ax, %ax
js 0x1f20
incl %eax
movw %ax, 0x324e(%rip)       # 0x5156
cmpw $0x19, %ax
jl 0x1f9c
movw $0xffff, 0x323b(%rip)   # imm = 0xFFFF
jmp 0x203a
xorl %eax, %eax
movq $-0x1e, %rcx
leaq 0x3210(%rip), %r14      # 0x5140
movzbl 0x38(%rcx,%r14), %edx
addl %edx, %eax
incq %rcx
jne 0x1f30
xorl %ebx, %ebx
testl %eax, %eax
je 0x20c7
callq 0x1180
movslq %eax, %rcx
imulq $-0x77777777, %rcx, %rax # imm = 0x88888889
shrq $0x20, %rax
addl %ecx, %eax
movl %eax, %edx
shrl $0x1f, %edx
sarl $0x4, %eax
addl %edx, %eax
movl %eax, %edx
shll $0x5, %edx
addl %eax, %eax
subl %edx, %eax
addl %ecx, %eax
movslq %eax, %rcx
cmpb $0x1, 0x1a(%rcx,%r14)
jne 0x1f47
cmpl $0x9, %eax
jg 0x2041
cmpb $0x0, 0x2e(%rcx,%r14)
je 0x205f
addq $0x14, %rcx
movl %ecx, %eax
jmp 0x206e
movswl 0x31b5(%rip), %ecx      # 0x5158
cmpw $0x18, %ax
jne 0x1fca
movswl 0x319a(%rip), %edx      # 0x514a
leal -0x2(%rdx), %esi
cmpl %ecx, %esi
setg %sil
addl $0x2, %edx
cmpl %ecx, %edx
setl %dl
orb %sil, %dl
je 0x204d
movl %ecx, %ecx
addq $-0xc, %rcx
leaq 0x31a1(%rip), %rdx      # 0x5178
xorl %esi, %esi
movl %esi, %edi
andl $0x3, %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rdi,%rdi,2), %r8
movq %rcx, %rdi
subq %r8, %rdi
cmpq $0x4, %rsi
movl $0x0, %r8d
adcl $0x13, %r8d
xorl %r9d, %r9d
cmpb $0x1, (%rdx,%r9)
jne 0x2024
movswl %ax, %r10d
cmpl %r10d, %r8d
jne 0x2024
cmpq %r9, %rdi
jne 0x2024
movb $0x0, (%rdx,%r9)
movw $0xffff, 0x3136(%rip)   # imm = 0xFFFF
movw $0xffff, %ax            # imm = 0xFFFF
incq %r9
cmpq $0xa, %r9
jne 0x1ffd
incq %rsi
addq $0xa, %rdx
cmpq $0x8, %rsi
jne 0x1fd9
xorl %ebx, %ebx
jmp 0x20c7
cmpl $0x13, %eax
ja 0x206e
leal 0xa(%rax), %ecx
movl %ecx, %edx
jmp 0x2065
addq $-0x1f4, 0x30e8(%rip) # imm = 0xFE0C
movl $0x1, %ebx
jmp 0x20c7
leal 0xa(%rax), %edx
movslq %edx, %rcx
cmpb $0x0, 0x1a(%rcx,%r14)
cmovnel %edx, %eax
movsbl %al, %ecx
imull $0x67, %ecx, %ecx
movzwl %cx, %ecx
movswl %cx, %edx
shrl $0xf, %ecx
shrl $0xa, %edx
addb %cl, %dl
movsbl %dl, %ecx
leal (,%rcx,4), %edx
addw 0x30b9(%rip), %dx       # 0x514c
addl $0x2, %edx
movw %dx, 0x30b9(%rip)       # 0x5156
movzbl %cl, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subb %cl, %al
movzbl %al, %eax
leal (,%rax,8), %ecx
subl %eax, %ecx
movsbl %cl, %eax
addw 0x3091(%rip), %ax       # 0x514e
addl $0x2, %eax
movw %ax, 0x3091(%rip)       # 0x5158
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop