// File: /workspace/github_c_makefile_star2_O3/skeeto[P]goblin-com/src/game.c
// Function: squad_step
void
squad_step(game_t *game, squad_t *squad)
{
    float tx, ty;
    if (squad->target < 0) {
        tx = CASTLE_X;
        ty = CASTLE_Y;
    } else {
        invader_t *i = game->invaders + squad->target;
        if (!i->active) {
            squad->target = -1;
            tx = CASTLE_X;
            ty = CASTLE_Y;
        }
        tx = i->x;
        ty = i->y;
    }
    float dx = tx - squad->x;
    float dy = ty - squad->y;
    float d = sqrt(dx * dx + dy * dy);
    if (d < 0.1 && !IS_WATER(map_base(game->map, tx, ty))) {
        squad->x = tx;
        squad->y = ty;
        if (squad->target >= 0) {
            game_event_push(game, EVENT_BATTLE);
            // TODO
            invader_delete(game, game->invaders + squad->target);
        }
    } else {
        float speed = SQUAD_SPEED;
        if (map_base(game->map, squad->x, squad->y) == BASE_MOUNTAIN &&
            map_building(game->map, squad->x, squad->y) == C_NONE)
            speed *= 0.6;
        float newx = squad->x + (speed / (float)DAY) * dx / d;
        float newy = squad->y + (speed / (float)DAY) * dy / d;
        if (squad->target < 0 || !IS_WATER(map_base(game->map, newx, newy))) {
            squad->x = newx;
            squad->y = newy;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x8(%rsi), %rax
testq %rax, %rax
js 0x5559
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,8), %rax
addq $0x48, %rax
cmpb $0x0, (%rax)
jne 0x5552
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
movsd 0x4(%rax), %xmm2
jmp 0x5561
movsd 0x23cf(%rip), %xmm2     # 0x7930
movsd (%rbx), %xmm0
movaps %xmm2, %xmm1
subps %xmm0, %xmm1
movaps %xmm1, %xmm0
mulps %xmm1, %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm1, (%rsp)
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtss %xmm1, %xmm0
movaps %xmm0, 0x20(%rsp)
cvtss2sd %xmm0, %xmm0
movsd 0x2417(%rip), %xmm1     # 0x79b0
ucomisd %xmm0, %xmm1
jbe 0x55e9
movq 0x38(%r14), %rdi
cvttss2si %xmm2, %ebp
movaps %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
cvttss2si %xmm0, %r15d
movl %ebp, %esi
movl %r15d, %edx
movaps %xmm2, 0x10(%rsp)
callq 0x4cb3
cmpw $0x20, %ax
je 0x55e9
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x4cb3
movaps 0x10(%rsp), %xmm0
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
jne 0x56b8
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x4cb3
movzwl %ax, %eax
movss 0x23e2(%rip), %xmm2     # 0x79e8
cmpl $0x25b2, %eax           # imm = 0x25B2
jne 0x563a
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x4ce1
movss 0x23c1(%rip), %xmm2     # 0x79e8
testw %ax, %ax
movaps (%rsp), %xmm1
jne 0x563e
movss 0x23b4(%rip), %xmm2     # 0x79ec
jmp 0x563e
movaps (%rsp), %xmm1
divss 0x23aa(%rip), %xmm2     # 0x79f0
movsd (%rbx), %xmm0
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
mulps %xmm2, %xmm1
movaps 0x20(%rsp), %xmm2
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
divps %xmm2, %xmm1
addps %xmm0, %xmm1
cmpl $0x0, 0x8(%rbx)
js 0x56aa
movq 0x38(%r14), %rdi
cvttss2si %xmm1, %ebp
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
cvttss2si %xmm0, %r15d
movl %ebp, %esi
movl %r15d, %edx
movaps %xmm1, (%rsp)
callq 0x4cb3
cmpw $0x20, %ax
je 0x56ad
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x4cb3
movaps (%rsp), %xmm1
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
je 0x56ad
movlps %xmm1, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movlps %xmm0, (%rbx)
movl 0x8(%rbx), %eax
testl %eax, %eax
js 0x56ad
xorl %ecx, %ecx
cmpl $0x0, 0x1dcc(%r14,%rcx,4)
je 0x56da
incq %rcx
cmpq $0x8, %rcx
jne 0x56c4
jmp 0x56e9
movl $0x4, 0x1dcc(%r14,%rcx,4)
movl 0x8(%rbx), %eax
cltq
leaq (%rax,%rax,4), %rax
movb $0x0, 0x48(%r14,%rax,8)
jmp 0x56ad