// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jge 0x7216
movss 0x27b2(%rip), %xmm0     # 0x99b4
movss %xmm0, -0x14(%rbp)
movss 0x27a1(%rip), %xmm0     # 0x99b0
movss %xmm0, -0x18(%rbp)
jmp 0x727b
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, (%rax)
jne 0x725f
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movss 0x2767(%rip), %xmm0     # 0x99b4
movss %xmm0, -0x14(%rbp)
movss 0x2756(%rip), %xmm0     # 0x99b0
movss %xmm0, -0x18(%rbp)
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm0
movss %xmm0, -0x14(%rbp)
movq -0x20(%rbp), %rax
movss 0x8(%rax), %xmm0
movss %xmm0, -0x18(%rbp)
movss -0x14(%rbp), %xmm0
movq -0x10(%rbp), %rax
subss (%rax), %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
subss 0x4(%rax), %xmm0
movss %xmm0, -0x28(%rbp)
movss -0x24(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
movss -0x28(%rbp), %xmm1
mulss -0x28(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1270
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2729(%rip), %xmm0     # 0x9a08
ucomisd %xmm1, %xmm0
jbe 0x7381
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
cvttss2si -0x14(%rbp), %esi
cvttss2si -0x18(%rbp), %edx
callq 0x6270
movzwl %ax, %eax
cmpl $0x20, %eax
je 0x7381
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
cvttss2si -0x14(%rbp), %esi
cvttss2si -0x18(%rbp), %edx
callq 0x6270
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
je 0x7381
movss -0x14(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movss -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x737c
movq -0x8(%rbp), %rdi
movl $0x4, %esi
callq 0x74c0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x48, %rsi
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
callq 0x7520
jmp 0x74ba
movss 0x262f(%rip), %xmm0     # 0x99b8
movss %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
cvttss2si (%rax), %esi
movq -0x10(%rbp), %rax
cvttss2si 0x4(%rax), %edx
callq 0x6270
movzwl %ax, %eax
cmpl $0x25b2, %eax           # imm = 0x25B2
jne 0x73fa
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
cvttss2si (%rax), %esi
movq -0x10(%rbp), %rax
cvttss2si 0x4(%rax), %edx
callq 0x6310
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x73fa
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2623(%rip), %xmm1     # 0x9a10
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movss -0x30(%rbp), %xmm1
movss 0x25ad(%rip), %xmm2     # 0x99bc
divss %xmm2, %xmm1
mulss -0x24(%rbp), %xmm1
divss -0x2c(%rbp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm0
movss -0x30(%rbp), %xmm1
movss 0x2580(%rip), %xmm2     # 0x99bc
divss %xmm2, %xmm1
mulss -0x28(%rbp), %xmm1
divss -0x2c(%rbp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x749d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
cvttss2si -0x34(%rbp), %esi
cvttss2si -0x38(%rbp), %edx
callq 0x6270
movzwl %ax, %eax
cmpl $0x20, %eax
je 0x74b8
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
cvttss2si -0x34(%rbp), %esi
cvttss2si -0x38(%rbp), %edx
callq 0x6270
movzwl %ax, %eax
cmpl $0x2248, %eax           # imm = 0x2248
je 0x74b8
movss -0x34(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movss -0x38(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x4(%rax)
jmp 0x74ba
addq $0x40, %rsp
popq %rbp
retq