// File: /workspace/github_c_makefile_star2_O1/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 0x33d1(%rip), %ecx      # 0x5152
testw %cx, %cx
js 0x1db4
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subw $0x1, %cx
movw %cx, 0x33bc(%rip)       # 0x5152
jae 0x1db7
incw 0x33a9(%rip)            # 0x5148
xorl %eax, %eax
movq $-0x32, %rcx
addq %rcx, 0x3391(%rip)      # 0x5140
jmp 0x1ee1
xorl %eax, %eax
retq
movswl 0x338e(%rip), %eax      # 0x514c
movswl %cx, %ecx
movswl 0x3386(%rip), %edx      # 0x514e
movswl 0x3385(%rip), %esi      # 0x5154
leal -0x4(%rsi), %r8d
xorl %edi, %edi
movl $0xcccccccd, %r10d      # imm = 0xCCCCCCCD
leaq 0x335e(%rip), %r9       # 0x5140
cmpb $0x1, 0x1a(%rdi,%r9)
jne 0x1e2e
movl %edi, %r11d
imulq %r10, %r11
shrq $0x21, %r11
andl $-0x4, %r11d
addl %eax, %r11d
addl $0x2, %r11d
cmpl %ecx, %r11d
jne 0x1e2e
movl %edi, %r11d
imulq %r10, %r11
shrq $0x23, %r11
imull $0x46, %r11d, %r11d
movl %edx, %ebx
subl %r11d, %ebx
cmpl %esi, %ebx
setg %r11b
cmpl %r8d, %ebx
setl %bl
orb %r11b, %bl
je 0x1ee4
incq %rdi
addl $0x7, %edx
cmpq $0x1e, %rdi
jne 0x1de2
movswq 0x3312(%rip), %rdx      # 0x5154
movzwl 0x3308(%rip), %r8d      # 0x5152
movzwl 0x32f7(%rip), %eax      # 0x5148
movq 0x32e8(%rip), %rcx      # 0x5140
movl %edx, %edx
addq $-0xc, %rdx
leaq 0x3313(%rip), %rsi      # 0x5178
xorl %edi, %edi
movl %edi, %r9d
andl $0x3, %r9d
leaq (%r9,%r9,4), %r9
leaq (%r9,%r9,2), %r10
movq %rdx, %r9
subq %r10, %r9
cmpq $0x4, %rdi
movl $0x0, %r10d
adcl $0x13, %r10d
xorl %r11d, %r11d
cmpb $0x1, (%rsi,%r11)
jne 0x1ec9
movswl %r8w, %ebx
cmpl %ebx, %r10d
jne 0x1ec9
cmpq %r11, %r9
jne 0x1ec9
movb $0x0, (%rsi,%r11)
movw $0xffff, 0x32a2(%rip)   # imm = 0xFFFF
incl %eax
movw %ax, 0x328f(%rip)       # 0x5148
addq $-0xa, %rcx
movq %rcx, 0x327c(%rip)      # 0x5140
movw $0xffff, %r8w           # imm = 0xFFFF
incq %r11
cmpq $0xa, %r11
jne 0x1e8d
incq %rdi
addq $0xa, %rsi
cmpq $0x8, %rdi
jne 0x1e67
xorl %eax, %eax
popq %rbx
popq %rbp
retq
movb $0x0, 0x1a(%rdi,%r9)
movw $0xffff, 0x325f(%rip)   # imm = 0xFFFF
movl $0x1, %eax
movl $0x64, %ecx
jmp 0x1da8