// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x8(%rsi), %rax
testq %rax, %rax
js 0x4fa1
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,8), %rax
addq $0x48, %rax
cmpb $0x0, (%rax)
jne 0x4f95
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
movss 0x4(%rax), %xmm0
movss 0x8(%rax), %xmm1
jmp 0x4fb1
movss 0x294f(%rip), %xmm0     # 0x78f8
movss 0x294b(%rip), %xmm1     # 0x78fc
movss %xmm0, 0x10(%rsp)
subss (%rbx), %xmm0
movss %xmm1, 0xc(%rsp)
subss 0x4(%rbx), %xmm1
movss %xmm1, 0x4(%rsp)
mulss %xmm1, %xmm1
movss %xmm0, 0x8(%rsp)
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x4fec
sqrtss %xmm0, %xmm0
jmp 0x4ff1
callq 0x11a0
movss %xmm0, 0x14(%rsp)
cvtss2sd %xmm0, %xmm0
movsd 0x28bd(%rip), %xmm1     # 0x78c0
ucomisd %xmm0, %xmm1
jbe 0x5046
movq 0x38(%r14), %rdi
cvttss2si 0x10(%rsp), %ebp
cvttss2si 0xc(%rsp), %r15d
movl %ebp, %esi
movl %r15d, %edx
callq 0x46b9
cmpw $0x20, %ax
je 0x5046
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x46b9
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
jne 0x5139
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x46b9
movzwl %ax, %eax
movss 0x289d(%rip), %xmm3     # 0x7900
cmpl $0x25b2, %eax           # imm = 0x25B2
jne 0x509f
cvttss2si (%rbx), %esi
movq 0x38(%r14), %rdi
cvttss2si 0x4(%rbx), %edx
callq 0x46e7
movss 0x287c(%rip), %xmm3     # 0x7900
testw %ax, %ax
movss 0x8(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
jne 0x50ab
movss 0x2867(%rip), %xmm3     # 0x7904
jmp 0x50ab
movss 0x8(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
divss 0x2855(%rip), %xmm3     # 0x7908
mulss %xmm3, %xmm0
movss 0x14(%rsp), %xmm2
divss %xmm2, %xmm0
addss (%rbx), %xmm0
mulss %xmm3, %xmm1
divss %xmm2, %xmm1
addss 0x4(%rbx), %xmm1
cmpl $0x0, 0x8(%rbx)
js 0x5125
movq 0x38(%r14), %rdi
cvttss2si %xmm0, %ebp
cvttss2si %xmm1, %r15d
movl %ebp, %esi
movl %r15d, %edx
movss %xmm0, 0x8(%rsp)
movss %xmm1, 0x4(%rsp)
callq 0x46b9
cmpw $0x20, %ax
je 0x512e
movq 0x38(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x46b9
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm0
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
je 0x512e
movss %xmm0, (%rbx)
movss %xmm1, 0x4(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movss 0x10(%rsp), %xmm0
movss %xmm0, (%rbx)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x4(%rbx)
cmpl $0x0, 0x8(%rbx)
js 0x512e
xorl %eax, %eax
cmpl $0x0, 0x1dcc(%r14,%rax,4)
je 0x516c
incq %rax
cmpq $0x8, %rax
jne 0x5156
jmp 0x5178
movl $0x4, 0x1dcc(%r14,%rax,4)
movslq 0x8(%rbx), %rax
leaq (%rax,%rax,4), %rax
movb $0x0, 0x48(%r14,%rax,8)
jmp 0x512e