// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
movswl 0x2d37(%rip), %eax      # 0x5152
cmpl $0x0, %eax
jge 0x242c
movl $0x0, -0x4(%rbp)
jmp 0x2663
movw 0x2d1f(%rip), %ax       # 0x5152
addw $-0x1, %ax
movw %ax, 0x2d14(%rip)       # 0x5152
movswl 0x2d0d(%rip), %eax      # 0x5152
cmpl $0x0, %eax
jge 0x247a
movw 0x2cf7(%rip), %ax       # 0x5148
addw $0x1, %ax
movw %ax, 0x2cec(%rip)       # 0x5148
movq 0x2cdd(%rip), %rax      # 0x5140
subq $0x32, %rax
movq %rax, 0x2cd2(%rip)      # 0x5140
movl $0x0, -0x4(%rbp)
jmp 0x2663
movl $0x0, -0x8(%rbp)
cmpl $0x1e, -0x8(%rbp)
jge 0x255a
movslq -0x8(%rbp), %rcx
leaq 0x2caa(%rip), %rax      # 0x5140
testb $0x1, 0x1a(%rax,%rcx)
je 0x254a
movswl 0x2ca4(%rip), %eax      # 0x514c
movl %eax, -0x1c(%rbp)
movl -0x8(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x1c(%rbp), %eax
shll $0x2, %ecx
addl %ecx, %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
movswl 0x2c81(%rip), %eax      # 0x514e
movl %eax, -0x18(%rbp)
movl -0x8(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl -0x18(%rbp), %eax
imull $0x7, %edx, %ecx
addl %ecx, %eax
movl %eax, -0x10(%rbp)
movswl 0x2c65(%rip), %eax      # 0x5152
cmpl -0x14(%rbp), %eax
jne 0x2548
movswl 0x2c5b(%rip), %eax      # 0x5154
cmpl -0x10(%rbp), %eax
jl 0x2546
movswl 0x2c4f(%rip), %eax      # 0x5154
movl -0x10(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jg 0x2546
movslq -0x8(%rbp), %rcx
leaq 0x2c26(%rip), %rax      # 0x5140
movb $0x0, 0x1a(%rax,%rcx)
movw $0xffff, 0x2c2a(%rip)   # imm = 0xFFFF
movq 0x2c11(%rip), %rax      # 0x5140
addq $0x64, %rax
movq %rax, 0x2c06(%rip)      # 0x5140
movl $0x1, -0x4(%rbp)
jmp 0x2663
jmp 0x2548
jmp 0x254a
jmp 0x254c
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2481
movl $0x0, -0x8(%rbp)
cmpl $0x8, -0x8(%rbp)
jge 0x265c
movl $0x0, -0xc(%rbp)
cmpl $0xa, -0xc(%rbp)
jge 0x264c
movslq -0x8(%rbp), %rcx
leaq 0x2bb9(%rip), %rax      # 0x5140
addq $0x38, %rax
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0x263c
movl -0x8(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %edx
movl $0x13, %eax
movl $0x14, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
imull $0xf, %edx, %eax
addl $0xc, %eax
addl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movswl 0x2b74(%rip), %eax      # 0x5152
cmpl -0x14(%rbp), %eax
jne 0x263a
movswl 0x2b6a(%rip), %eax      # 0x5154
cmpl -0x10(%rbp), %eax
jne 0x263a
movslq -0x8(%rbp), %rcx
leaq 0x2b46(%rip), %rax      # 0x5140
addq $0x38, %rax
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movw $0xffff, 0x2b3c(%rip)   # imm = 0xFFFF
movw 0x2b2b(%rip), %ax       # 0x5148
addw $0x1, %ax
movw %ax, 0x2b20(%rip)       # 0x5148
movq 0x2b11(%rip), %rax      # 0x5140
subq $0xa, %rax
movq %rax, 0x2b06(%rip)      # 0x5140
jmp 0x263c
jmp 0x263e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2572
jmp 0x264e
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2561
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)