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

  if (game_state.shot_pos_y < 0)
    return 0; /* No shot is being fired. */

  game_state.shot_pos_y--;
  if (game_state.shot_pos_y < 0) { /* Out of range. */
    game_state.wasted_shots++;
    game_state.score -= 50;
    return 0;
  }

  /* Check for collision with invaders. */
  for (i = 0; i < GAME_INVADERS; i++) {
    if (game_state.invader_alive[i]) {
      y = game_state.invaders_pos_y + ((i / 10) * 4) + 2;
      x = game_state.invaders_pos_x + ((i % 10) * 7);
      if (game_state.shot_pos_y == y) {
        if ((game_state.shot_pos_x >= x) && 
            (game_state.shot_pos_x <= x + 4)) {
          game_state.invader_alive[i] = false;
          game_state.shot_pos_y = -1;
          game_state.score += 100;
          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.shot_pos_y == y) &&
            (game_state.shot_pos_x == x)) {
          game_state.shield_intact[i][j] = false;
          game_state.shot_pos_y = -1;
          game_state.wasted_shots++;
          game_state.score -= 10;
        }
      }
    }
  }

  return 0;
}

// Assembly:
movzwl 0x33e2(%rip), %eax      # 0x5152
testw %ax, %ax
js 0x1da5
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subw $0x1, %ax
movw %ax, 0x33cb(%rip)       # 0x5152
jae 0x1da8
incw 0x33b8(%rip)            # 0x5148
xorl %eax, %eax
movq $-0x32, %rcx
addq %rcx, 0x33a0(%rip)      # 0x5140
jmp 0x1ec9
xorl %eax, %eax
retq
movswl 0x339d(%rip), %ecx      # 0x514c
movzwl %ax, %edx
movswl 0x3395(%rip), %edi      # 0x514e
movswl 0x3394(%rip), %esi      # 0x5154
leal -0x4(%rsi), %r8d
xorl %r9d, %r9d
leaq 0x3372(%rip), %r10      # 0x5140
xorl %r11d, %r11d
cmpb $0x1, 0x1a(%r11,%r10)
jne 0x1e26
movzbl %r11b, %ebx
imull $0xcd, %ebx, %ebx
shrl $0x9, %ebx
andb $0x7c, %bl
movzbl %bl, %ebx
addl %ecx, %ebx
addl $0x2, %ebx
cmpl %edx, %ebx
jne 0x1e26
movzbl %r11b, %ebx
imull $0xcd, %ebx, %ebx
shrl $0xb, %ebx
imull $0x46, %ebx, %ebx
movl %r9d, %r14d
subb %bl, %r14b
movzbl %r14b, %ebx
addl %edi, %ebx
cmpl %esi, %ebx
setg %r14b
cmpl %r8d, %ebx
setl %bl
orb %r14b, %bl
je 0x1ece
incq %r11
addb $0x7, %r9b
cmpq $0x1e, %r11
jne 0x1dd1
movzwl 0x330e(%rip), %ecx      # 0x5148
movq 0x32ff(%rip), %rdx      # 0x5140
movl %esi, %esi
addq $-0xc, %rsi
leaq 0x332a(%rip), %rdi      # 0x5178
xorl %r8d, %r8d
movl %r8d, %r9d
andl $0x3, %r9d
leaq (%r9,%r9,4), %r9
leaq (%r9,%r9,2), %r10
movq %rsi, %r9
subq %r10, %r9
cmpq $0x4, %r8
movl $0x0, %r10d
adcl $0x13, %r10d
xorl %r11d, %r11d
cmpb $0x1, (%rdi,%r11)
jne 0x1eb1
movswl %ax, %ebx
cmpl %ebx, %r10d
jne 0x1eb1
cmpq %r11, %r9
jne 0x1eb1
movb $0x0, (%rdi,%r11)
movw $0xffff, 0x32b9(%rip)   # imm = 0xFFFF
incl %ecx
movw %cx, 0x32a6(%rip)       # 0x5148
addq $-0xa, %rdx
movq %rdx, 0x3293(%rip)      # 0x5140
movw $0xffff, %ax            # imm = 0xFFFF
incq %r11
cmpq $0xa, %r11
jne 0x1e77
incq %r8
addq $0xa, %rdi
cmpq $0x8, %r8
jne 0x1e51
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
movb $0x0, 0x1a(%r11,%r10)
movw $0xffff, 0x3275(%rip)   # imm = 0xFFFF
movl $0x1, %eax
movl $0x64, %ecx
jmp 0x1d99