// File: /workspace/github_c_makefile_star2_O1/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 0x3246(%rip), %eax      # 0x5156
testw %ax, %ax
js 0x1f36
incl %eax
movw %ax, 0x3238(%rip)       # 0x5156
cmpw $0x19, %ax
jl 0x1fb2
movw $0xffff, 0x3225(%rip)   # imm = 0xFFFF
jmp 0x205d
xorl %eax, %eax
movq $-0x1e, %rcx
leaq 0x31fa(%rip), %r14      # 0x5140
movzbl 0x38(%rcx,%r14), %edx
addl %edx, %eax
incq %rcx
jne 0x1f46
xorl %ebx, %ebx
testl %eax, %eax
je 0x20dd
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 0x1f5d
cmpl $0x9, %eax
jg 0x2061
cmpb $0x0, 0x2e(%rcx,%r14)
je 0x207f
addq $0x14, %rcx
movl %ecx, %eax
jmp 0x208e
cmpw $0x18, %ax
jne 0x1fde
movswl 0x3199(%rip), %eax      # 0x5158
movswl 0x3184(%rip), %ecx      # 0x514a
leal -0x2(%rcx), %edx
cmpl %eax, %edx
setg %dl
addl $0x2, %ecx
cmpl %eax, %ecx
setl %al
orb %dl, %al
je 0x206d
movswq 0x3172(%rip), %rax      # 0x5158
movzwl 0x3169(%rip), %ecx      # 0x5156
movl %eax, %eax
addq $-0xc, %rax
leaq 0x317e(%rip), %rdx      # 0x5178
xorl %esi, %esi
movl %esi, %edi
andl $0x3, %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rdi,%rdi,2), %r8
movq %rax, %rdi
subq %r8, %rdi
cmpq $0x4, %rsi
movl $0x0, %r8d
adcl $0x13, %r8d
xorl %r9d, %r9d
cmpb $0x1, (%rdx,%r9)
jne 0x2047
movswl %cx, %r10d
cmpl %r10d, %r8d
jne 0x2047
cmpq %r9, %rdi
jne 0x2047
movb $0x0, (%rdx,%r9)
movw $0xffff, 0x3113(%rip)   # imm = 0xFFFF
movw $0xffff, %cx            # imm = 0xFFFF
incq %r9
cmpq $0xa, %r9
jne 0x2020
incq %rsi
addq $0xa, %rdx
cmpq $0x8, %rsi
jne 0x1ffc
xorl %ebx, %ebx
jmp 0x20dd
cmpl $0x13, %eax
jg 0x208e
leal 0xa(%rax), %ecx
movl %ecx, %edx
jmp 0x2085
addq $-0x1f4, 0x30c8(%rip) # imm = 0xFE0C
movl $0x1, %ebx
jmp 0x20dd
leal 0xa(%rax), %edx
movslq %edx, %rcx
cmpb $0x0, 0x1a(%rcx,%r14)
cmovnel %edx, %eax
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
leal (,%rcx,4), %edx
addw 0x309a(%rip), %dx       # 0x514c
addl $0x2, %edx
movw %dx, 0x309a(%rip)       # 0x5156
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leal (,%rax,8), %ecx
subl %eax, %ecx
addw 0x307b(%rip), %cx       # 0x514e
addl $0x2, %ecx
movw %cx, 0x307b(%rip)       # 0x5158
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop