// File: /workspace/github_c_makefile_star2_O1/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 0x35b2(%rip), %rsi      # 0x5140
movzbl 0x38(%rcx,%rsi), %edx
addl %edx, %eax
incq %rcx
jne 0x1b8e
xorl %ecx, %ecx
testl %eax, %eax
je 0x1d65
movl %eax, %r8d
movq %rdi, %rax
cqto
idivq %r8
testq %rdx, %rdx
jne 0x1d65
cmpw $0x0, 0x3590(%rip)      # 0x5150
movzwl 0x3587(%rip), %eax      # 0x514e
je 0x1bdd
leal 0x1(%rax), %ecx
movw %cx, 0x357b(%rip)       # 0x514e
cmpw $0xc, %cx
jle 0x1c04
xorl %ecx, %ecx
jmp 0x1bef
decw %ax
movw %ax, 0x3567(%rip)       # 0x514e
jns 0x1c04
xorl %eax, %eax
movw $0x1, %cx
movw %ax, 0x3558(%rip)       # 0x514e
incw 0x354f(%rip)            # 0x514c
movw %cx, 0x354c(%rip)       # 0x5150
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movswl 0x3534(%rip), %eax      # 0x514c
movswl 0x352f(%rip), %ecx      # 0x514e
xorl %edx, %edx
movl $0xcccccccd, %edi       # imm = 0xCCCCCCCD
leaq 0x3573(%rip), %r8       # 0x51a0
leaq 0x3544(%rip), %r9       # 0x5178
cmpb $0x1, 0x1a(%rdx,%rsi)
jne 0x1d4c
movl %edx, %r10d
imulq %rdi, %r10
shrq $0x21, %r10
andl $-0x4, %r10d
addl %eax, %r10d
cmpl $0x11, %r10d
je 0x1cd2
cmpl $0x12, %r10d
jne 0x1d46
movl %edx, %r10d
imulq %rdi, %r10
shrq $0x23, %r10
addl %r10d, %r10d
leal (%r10,%r10,4), %r10d
movl %edx, %r11d
subl %r10d, %r11d
leal (,%r11,8), %r10d
subl %r11d, %r10d
leal (%r10,%rcx), %r11d
addl $0x4, %r11d
addl %ecx, %r10d
movslq %r10d, %r10
movslq %r11d, %r11
movl $0xc, %ebx
movq %r9, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq (%rbx,%r12), %r13
cmpq %r10, %r13
jl 0x1cb6
cmpq %r11, %r13
jg 0x1cb6
movb $0x0, (%r14,%r12)
incq %r12
cmpq $0xa, %r12
jne 0x1ca3
incq %r15
addq $0xf, %rbx
addq $0xa, %r14
cmpq $0x4, %r15
jne 0x1ca0
jmp 0x1d4c
movl %edx, %r10d
imulq %rdi, %r10
shrq $0x23, %r10
addl %r10d, %r10d
leal (%r10,%r10,4), %r10d
movl %edx, %r11d
subl %r10d, %r11d
leal (,%r11,8), %r10d
subl %r11d, %r10d
leal (%r10,%rcx), %r11d
addl $0x4, %r11d
addl %ecx, %r10d
movslq %r10d, %r10
movslq %r11d, %r11
movl $0x4, %ebx
movl $0xc, %r14d
movq %r8, %r15
xorl %r12d, %r12d
leaq (%r14,%r12), %r13
cmpq %r10, %r13
jl 0x1d2a
cmpq %r11, %r13
jg 0x1d2a
movb $0x0, (%r15,%r12)
incq %r12
cmpq $0xa, %r12
jne 0x1d17
incq %rbx
addq $0xf, %r14
addq $0xa, %r15
cmpq $0x8, %rbx
jne 0x1d14
jmp 0x1d4c
cmpl $0x15, %r10d
jge 0x1d68
incq %rdx
cmpq $0x1e, %rdx
jne 0x1c34
xorl %ecx, %ecx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %ecx, %eax
retq
addq $-0x3e8, 0x33cd(%rip) # imm = 0xFC18
movl $0x1, %ecx
jmp 0x1d5b