// File: /workspace/github_c_makefile_star2_O2/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 0x4758
imulq $0x28, %rax, %rax
addq %r14, %rax
addq $0x48, %rax
cmpb $0x0, (%rax)
jne 0x4751
orl $-0x1, 0x8(%rbx)
movsd 0x4(%rax), %xmm2
jmp 0x4760
movsd 0x2130(%rip), %xmm2     # 0x6890
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
sqrtss %xmm1, %xmm0
movaps %xmm0, 0x20(%rsp)
cvtss2sd %xmm0, %xmm0
movsd 0x217b(%rip), %xmm1     # 0x6910
ucomisd %xmm0, %xmm1
jbe 0x47e1
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 0x3f6c
cmpw $0x20, %ax
je 0x47e1
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x3f6c
movaps 0x10(%rsp), %xmm0
cmpw $0x2248, %ax            # imm = 0x2248
jne 0x48a8
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x3f6c
movss 0x214d(%rip), %xmm2     # 0x6948
cmpw $0x25b2, %ax            # imm = 0x25B2
jne 0x482e
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x3f99
movss 0x212d(%rip), %xmm2     # 0x6948
testw %ax, %ax
movaps (%rsp), %xmm1
jne 0x4832
movss 0x2120(%rip), %xmm2     # 0x694c
jmp 0x4832
movaps (%rsp), %xmm1
divss 0x2116(%rip), %xmm2     # 0x6950
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 0x489a
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 0x3f6c
cmpw $0x20, %ax
je 0x489d
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x3f6c
movaps (%rsp), %xmm1
cmpw $0x2248, %ax            # imm = 0x2248
je 0x489d
movlps %xmm1, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movlps %xmm0, (%rbx)
cmpl $0x0, 0x8(%rbx)
js 0x489d
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x48cc
movslq 0x8(%rbx), %rax
imulq $0x28, %rax, %rax
movb $0x0, 0x48(%r14,%rax)
jmp 0x489d