// File: /workspace/github_c_makefile_star2_O2/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 0x3471(%rip), %edx      # 0x5152
testw %dx, %dx
js 0x1d1d
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subw $0x1, %dx
movw %dx, 0x3458(%rip)       # 0x5152
jae 0x1d20
incw 0x3445(%rip)            # 0x5148
xorl %eax, %eax
movabsq $-0x32, %rcx
addq %rcx, 0x342a(%rip)      # 0x5140
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
movswl 0x3425(%rip), %esi      # 0x514c
movzwl %dx, %r8d
movswl 0x341b(%rip), %r9d      # 0x514e
movswl 0x341a(%rip), %edi      # 0x5154
leal -0x4(%rdi), %r10d
xorl %r11d, %r11d
movb $0xa, %r14b
leaq 0x33f5(%rip), %rbx      # 0x5140
xorl %r15d, %r15d
movzbl %r15b, %eax
divb %r14b
cmpq $0x1e, %r15
je 0x1da7
cmpb $0x1, 0x1a(%r15,%rbx)
jne 0x1d9e
movl %eax, %ecx
movzbl %r15b, %eax
divb %r14b
movzbl %al, %eax
leal (%rsi,%rax,4), %eax
addl $0x2, %eax
cmpl %r8d, %eax
jne 0x1d9e
movzbl %cl, %eax
imull $0x46, %eax, %eax
movl %r11d, %ecx
subb %al, %cl
movzbl %cl, %eax
addl %r9d, %eax
cmpl %edi, %eax
setg %cl
cmpl %r10d, %eax
setl %al
orb %cl, %al
je 0x1e40
incq %r15
addb $0x7, %r11b
jmp 0x1d4e
movzwl 0x339a(%rip), %ecx      # 0x5148
movq 0x338b(%rip), %rsi      # 0x5140
movl %edi, %edi
addq $-0xc, %rdi
leaq 0x33b6(%rip), %r8       # 0x5178
xorl %eax, %eax
xorl %r9d, %r9d
cmpq $0x8, %r9
je 0x1d16
movl %r9d, %r10d
andl $0x3, %r10d
imulq $0xf, %r10, %r11
movq %rdi, %r10
subq %r11, %r10
cmpq $0x4, %r9
movl $0x0, %r11d
adcl $0x13, %r11d
xorl %ebx, %ebx
cmpq $0xa, %rbx
je 0x1e37
cmpb $0x1, (%r8,%rbx)
jne 0x1e32
movswl %dx, %r14d
cmpl %r14d, %r11d
jne 0x1e32
cmpq %rbx, %r10
jne 0x1e32
movb $0x0, (%r8,%rbx)
orw $-0x1, 0x3338(%rip)     # 0x5152
incl %ecx
movw %cx, 0x3325(%rip)       # 0x5148
addq $-0xa, %rsi
movq %rsi, 0x3312(%rip)      # 0x5140
movw $0xffff, %dx            # imm = 0xFFFF
incq %rbx
jmp 0x1df2
incq %r9
addq $0xa, %r8
jmp 0x1dc7
movb $0x0, 0x1a(%r15,%rbx)
orw $-0x1, 0x3304(%rip)     # 0x5152
movl $0x1, %eax
movabsq $0x64, %rcx
jmp 0x1d0f