// File: /workspace/github_c_makefile_star2_O3/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:
xorl %eax, %eax
movq $-0x1e, %rcx
leaq 0x35d6(%rip), %rsi      # 0x5140
movzbl 0x38(%rcx,%rsi), %edx
addl %edx, %eax
incq %rcx
jne 0x1b6a
xorl %ecx, %ecx
testl %eax, %eax
je 0x1d54
movl %eax, %r8d
movq %rdi, %rax
cqto
idivq %r8
testq %rdx, %rdx
jne 0x1d54
cmpw $0x0, 0x35b4(%rip)      # 0x5150
movzwl 0x35ab(%rip), %eax      # 0x514e
je 0x1bc0
leal 0x1(%rax), %edx
movw %dx, 0x359f(%rip)       # 0x514e
movzwl 0x3596(%rip), %ecx      # 0x514c
cmpw $0xc, %dx
jle 0x1bf2
xorl %edx, %edx
jmp 0x1bd9
decw %ax
movw %ax, 0x3584(%rip)       # 0x514e
movzwl 0x357b(%rip), %ecx      # 0x514c
jns 0x1bf0
xorl %eax, %eax
movw $0x1, %dx
movw %ax, 0x356e(%rip)       # 0x514e
incl %ecx
movw %cx, 0x3563(%rip)       # 0x514c
movw %dx, 0x3560(%rip)       # 0x5150
movl %eax, %edx
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movswl %cx, %eax
movswl %dx, %ecx
xorl %edx, %edx
leaq 0x3594(%rip), %rdi      # 0x51a0
leaq 0x3565(%rip), %r8       # 0x5178
cmpb $0x1, 0x1a(%rdx,%rsi)
jne 0x1d3d
movzbl %dl, %r9d
imull $0xcd, %r9d, %r9d
shrl $0xb, %r9d
leal (%rax,%r9,4), %r10d
cmpl $0x11, %r10d
je 0x1cc5
cmpl $0x12, %r10d
jne 0x1d37
movzbl %dl, %r9d
imull $0xcd, %r9d, %r9d
shrl $0xa, %r9d
andl $-0x2, %r9d
leal (%r9,%r9,4), %r9d
movl %edx, %r10d
subb %r9b, %r10b
movzbl %r10b, %r9d
leal (,%r9,8), %r10d
subl %r9d, %r10d
movzbl %r10b, %r9d
leal (%rcx,%r9), %r10d
leal (%rcx,%r9), %r11d
addl $0x4, %r11d
movslq %r10d, %r9
movslq %r11d, %r10
movl $0xc, %r11d
movq %r8, %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq (%r11,%r15), %r12
cmpq %r9, %r12
jl 0x1ca9
cmpq %r10, %r12
jg 0x1ca9
movb $0x0, (%rbx,%r15)
incq %r15
cmpq $0xa, %r15
jne 0x1c96
incq %r14
addq $0xf, %r11
addq $0xa, %rbx
cmpq $0x4, %r14
jne 0x1c93
jmp 0x1d3d
addl %r9d, %r9d
leal (%r9,%r9,4), %r9d
movl %edx, %r10d
subb %r9b, %r10b
movzbl %r10b, %r9d
leal (,%r9,8), %r10d
subl %r9d, %r10d
movzbl %r10b, %r9d
leal (%rcx,%r9), %r10d
leal (%rcx,%r9), %r11d
addl $0x4, %r11d
movslq %r10d, %r9
movslq %r11d, %r10
movl $0x4, %r11d
movl $0xc, %ebx
movq %rdi, %r14
xorl %r15d, %r15d
leaq (%rbx,%r15), %r12
cmpq %r9, %r12
jl 0x1d1b
cmpq %r10, %r12
jg 0x1d1b
movb $0x0, (%r14,%r15)
incq %r15
cmpq $0xa, %r15
jne 0x1d08
incq %r11
addq $0xf, %rbx
addq $0xa, %r14
cmpq $0x8, %r11
jne 0x1d05
jmp 0x1d3d
cmpl $0x15, %r10d
jge 0x1d57
incq %rdx
cmpq $0x1e, %rdx
jne 0x1c13
xorl %ecx, %ecx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movl %ecx, %eax
retq
addq $-0x3e8, 0x33de(%rip) # imm = 0xFC18
movl $0x1, %ecx
jmp 0x1d4c