// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/invaders/game.c
// Function: game_handle_invaders
int game_handle_invaders(long cycle)
{
  int alive, i, j, k, x, y, shield_x;

  alive = game_invaders_alive();
  if (alive == 0)
    return 0;
  if (cycle % alive != 0)
    return 0;

  if (game_state.invaders_moving_right) {
    game_state.invaders_pos_x++;
    if (game_state.invaders_pos_x > (GAME_MAP_WIDTH - 68)) { /* (10*5)+(9*2) */
      game_state.invaders_pos_x--;
      game_state.invaders_pos_y++;
      game_state.invaders_moving_right = 0;
    }
  } else {
    game_state.invaders_pos_x--;
    if (game_state.invaders_pos_x < 0) {
      game_state.invaders_pos_x = 0;
      game_state.invaders_pos_y++;
      game_state.invaders_moving_right = 1;
    }
  }

  /* Check if invaders have reached the player or shields. */
  for (i = 0; i < GAME_INVADERS; i++) {
    if (game_state.invader_alive[i]) {
      y = game_state.invaders_pos_y + ((i / 10) * 4) + 2;

      if (y == (GAME_MAP_HEIGHT - 4)) {
        x = game_state.invaders_pos_x + ((i % 10) * 7);
        for (j = 0; j < (GAME_SHIELDS / 2); j++) {
          for (k = 0; k < GAME_SHIELD_PARTS; k++) {
            shield_x = 12 + ((j % 4) * 15) + k;
            if ((shield_x >= x) && (shield_x <= x + 4))
              game_state.shield_intact[j][k] = false;
          }
        }
      } else if (y == (GAME_MAP_HEIGHT - 5)) {
        x = game_state.invaders_pos_x + ((i % 10) * 7);
        for (j = GAME_SHIELDS / 2; j < GAME_SHIELDS; j++) {
          for (k = 0; k < GAME_SHIELD_PARTS; k++) {
            shield_x = 12 + ((j % 4) * 15) + k;
            if ((shield_x >= x) && (shield_x <= x + 4))
              game_state.shield_intact[j][k] = false;
          }
        }
      } else if (y >= (GAME_MAP_HEIGHT - 1)) {
        game_state.score -= 1000;
        return 1;
      }
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
callq 0x20c0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2166
movl $0x0, -0x4(%rbp)
jmp 0x2403
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x2185
movl $0x0, -0x4(%rbp)
jmp 0x2403
cmpw $0x0, 0x2fc3(%rip)      # 0x5150
je 0x21dc
movw 0x2fb8(%rip), %ax       # 0x514e
addw $0x1, %ax
movw %ax, 0x2fad(%rip)       # 0x514e
movswl 0x2fa6(%rip), %eax      # 0x514e
cmpl $0xc, %eax
jle 0x21da
movw 0x2f9a(%rip), %ax       # 0x514e
addw $-0x1, %ax
movw %ax, 0x2f8f(%rip)       # 0x514e
movw 0x2f86(%rip), %ax       # 0x514c
addw $0x1, %ax
movw %ax, 0x2f7b(%rip)       # 0x514c
movw $0x0, 0x2f76(%rip)      # 0x5150
jmp 0x2220
movw 0x2f6b(%rip), %ax       # 0x514e
addw $-0x1, %ax
movw %ax, 0x2f60(%rip)       # 0x514e
movswl 0x2f59(%rip), %eax      # 0x514e
cmpl $0x0, %eax
jge 0x221e
movw $0x0, 0x2f4b(%rip)      # 0x514e
movw 0x2f42(%rip), %ax       # 0x514c
addw $0x1, %ax
movw %ax, 0x2f37(%rip)       # 0x514c
movw $0x1, 0x2f32(%rip)      # 0x5150
jmp 0x2220
movl $0x0, -0x18(%rbp)
cmpl $0x1e, -0x18(%rbp)
jge 0x23fc
movslq -0x18(%rbp), %rcx
leaq 0x2f04(%rip), %rax      # 0x5140
testb $0x1, 0x1a(%rax,%rcx)
je 0x23ec
movswl 0x2efe(%rip), %eax      # 0x514c
movl %eax, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x30(%rbp), %eax
shll $0x2, %ecx
addl %ecx, %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
cmpl $0x14, -0x28(%rbp)
jne 0x2319
movswl 0x2ed1(%rip), %eax      # 0x514e
movl %eax, -0x34(%rbp)
movl -0x18(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl -0x34(%rbp), %eax
imull $0x7, %edx, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x2314
movl $0x0, -0x20(%rbp)
cmpl $0xa, -0x20(%rbp)
jge 0x2307
movl -0x1c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
imull $0xf, %edx, %eax
addl $0xc, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x22fa
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jg 0x22fa
movslq -0x1c(%rbp), %rcx
leaq 0x2e59(%rip), %rax      # 0x5140
addq $0x38, %rax
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x22fc
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x22aa
jmp 0x2309
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x229d
jmp 0x23ea
cmpl $0x13, -0x28(%rbp)
jne 0x23c3
movswl 0x2e24(%rip), %eax      # 0x514e
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl -0x38(%rbp), %eax
imull $0x7, %edx, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0x4, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x23c1
movl $0x0, -0x20(%rbp)
cmpl $0xa, -0x20(%rbp)
jge 0x23b4
movl -0x1c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
imull $0xf, %edx, %eax
addl $0xc, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x23a7
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jg 0x23a7
movslq -0x1c(%rbp), %rcx
leaq 0x2dac(%rip), %rax      # 0x5140
addq $0x38, %rax
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x23a9
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2357
jmp 0x23b6
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x234a
jmp 0x23e8
cmpl $0x17, -0x28(%rbp)
jl 0x23e6
movq 0x2d70(%rip), %rax      # 0x5140
subq $0x3e8, %rax            # imm = 0x3E8
movq %rax, 0x2d63(%rip)      # 0x5140
movl $0x1, -0x4(%rbp)
jmp 0x2403
jmp 0x23e8
jmp 0x23ea
jmp 0x23ec
jmp 0x23ee
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2227
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)