// File: /workspace/github_c_makefile_star2_O2/skeeto[P]goblin-com/src/game.c
// Function: game_step
yield_t
game_step(game_t *game)
{
    struct {
        double gold;
        double food;
        double wood;
    } init = {game->gold, game->food, game->wood};
    for (int y = 0; y < MAP_HEIGHT; y++) {
        for (int x = 0; x < MAP_WIDTH; x++) {
            uint16_t building = game->map->high[x][y].building;
            if (building != C_NONE) {
                if (++game->map->high[x][y].building_age >= 0)
                    building_process(game, building);
            }
        }
    }
    yield_t diff = {
        .gold = (game->gold - init.gold) * DAY,
        .food = (game->food - init.food) * DAY,
        .wood = (game->wood - init.wood) * DAY
    };

    for (unsigned i = 0; i < countof(game->squads); i++)
        if (game->squads[i].member_count > 0)
            squad_step(game, game->squads + i);

    if (rand_uniform(0, 1) < game->spawn_rate / DAY)
        invader_push(game, invader_generate());
    for (unsigned i = 0; i < countof(game->invaders); i++)
        if (game->invaders[i].active)
            invader_step(game, game->invaders + i);

    /* Generate events. */
    if (game->population >= GAME_WIN_POP)
        game_event_push(game, EVENT_WIN);

    game->time++;
    return diff;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movsd 0x18(%rdi), %xmm8
movupd 0x20(%rdi), %xmm9
movq 0x38(%rdi), %rax
xorl %ecx, %ecx
pushq $0x8
popq %rdx
movsd 0x1ffd(%rip), %xmm0     # 0x6918
movapd 0x1f8d(%rip), %xmm1     # 0x68b0
movsd 0x1ff5(%rip), %xmm2     # 0x6920
xorpd %xmm3, %xmm3
movhpd 0x2001(%rip), %xmm3     # xmm3 = xmm3[0],mem[0]
movsd 0x1ff1(%rip), %xmm4     # 0x6930
movsd 0x1fd1(%rip), %xmm5     # 0x6918
movsd 0x1fd1(%rip), %xmm6     # 0x6920
movapd 0x1f49(%rip), %xmm7     # 0x68a0
movsd %xmm8, 0x48(%rsp)
movapd %xmm8, %xmm10
movapd %xmm9, 0x50(%rsp)
movapd %xmm9, %xmm11
cmpq $0x18, %rcx
je 0x4a5b
movq %rdx, %rsi
cmpq $0x5a08, %rsi           # imm = 0x5A08
je 0x4a4f
movzwl -0x6(%rax,%rsi), %edi
testl %edi, %edi
je 0x4a43
movq (%rax,%rsi), %r8
leaq 0x1(%r8), %r9
movq %r9, (%rax,%rsi)
cmpq $-0x1, %r8
jl 0x4a43
xorpd %xmm9, %xmm9
cmpl $0x2b, %edi
je 0x4a0c
xorpd %xmm8, %xmm8
cmpl $0x57, %edi
je 0x4a1a
cmpl $0x46, %edi
je 0x4a13
cmpl $0x48, %edi
je 0x49e5
cmpl $0x4d, %edi
je 0x4a00
cmpl $0x53, %edi
je 0x49f5
cmpl $0x43, %edi
jne 0x4a1f
movapd %xmm4, %xmm8
movapd %xmm7, %xmm9
jmp 0x4a1f
movhpd 0x1f3a(%rip), %xmm9     # xmm9 = xmm9[0],mem[0]
movapd %xmm4, %xmm8
jmp 0x4a1f
movhpd 0x1f2a(%rip), %xmm9     # xmm9 = xmm9[0],mem[0]
jmp 0x4a1f
movapd %xmm6, %xmm8
movapd %xmm5, %xmm9
jmp 0x4a1f
movapd %xmm0, %xmm8
jmp 0x4a1f
movapd %xmm3, %xmm9
jmp 0x4a1f
movapd %xmm2, %xmm9
divpd %xmm1, %xmm9
addpd %xmm9, %xmm11
movupd %xmm11, 0x20(%rbx)
divsd 0x1ec0(%rip), %xmm8     # 0x68f8
addsd %xmm8, %xmm10
movsd %xmm10, 0x18(%rbx)
addq $0x180, %rsi            # imm = 0x180
jmp 0x497c
incq %rcx
addq $0x10, %rax
jmp 0x496f
leaq 0x2c8(%rbx), %r14
xorl %r15d, %r15d
movsd %xmm10, 0x8(%rsp)
movapd %xmm11, 0x10(%rsp)
cmpq $0x100, %r15            # imm = 0x100
je 0x4a99
cmpl $0x0, 0x2d4(%rbx,%r15)
je 0x4a93
leaq (%r14,%r15), %rsi
movq %rbx, %rdi
callq 0x4724
addq $0x10, %r15
jmp 0x4a73
movss 0x1d0b(%rip), %xmm1     # 0x67ac
xorpd %xmm0, %xmm0
callq 0x51f5
movapd 0x10(%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x1e3a(%rip), %xmm5     # 0x68f8
cvtss2sd %xmm0, %xmm0
cvtss2sd 0x40(%rbx), %xmm1
divsd 0x1e29(%rip), %xmm1     # 0x68f8
ucomisd %xmm0, %xmm1
jbe 0x4b6a
movss 0x1e73(%rip), %xmm1     # 0x6954
xorps %xmm0, %xmm0
callq 0x51f5
movss %xmm0, 0x2c(%rsp)
callq 0x1060
movaps %xmm0, 0x30(%rsp)
movss 0x2c(%rsp), %xmm0
callq 0x1100
movapd 0x10(%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x1de0(%rip), %xmm5     # 0x68f8
movaps 0x30(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, %xmm0
mulps 0x1d96(%rip), %xmm0     # 0x68c0
addps 0x1d5f(%rip), %xmm0     # 0x6890
pushq $0x48
popq %rcx
leaq 0x28(%rcx), %rax
cmpq $0x2f0, %rax            # imm = 0x2F0
je 0x4b6a
cmpb $0x0, (%rbx,%rcx)
movq %rax, %rcx
jne 0x4b34
movb $0x1, %cl
movb %cl, -0x28(%rbx,%rax)
movq %xmm0, %xmm0            # xmm0 = xmm0[0],zero
movdqu %xmm0, -0x24(%rbx,%rax)
movw $0x67, -0x14(%rbx,%rax)
andq $0x0, -0x10(%rbx,%rax)
movb %cl, -0x8(%rbx,%rax)
leaq 0x48(%rbx), %r14
pushq $0x10
popq %r15
subq $0x1, %r15
jb 0x4d9e
cmpb $0x1, (%r14)
jne 0x4d95
cvttss2si 0x4(%r14), %esi
movq 0x38(%rbx), %rdi
cvttss2si 0x8(%r14), %edx
callq 0x3f6c
movl %eax, %ebp
cvttss2si 0x4(%r14), %esi
movq 0x38(%rbx), %rdi
cvttss2si 0x8(%r14), %edx
callq 0x3f99
movl %eax, %r12d
cvttss2si 0xc(%r14), %esi
movq 0x38(%rbx), %rdi
cvttss2si 0x10(%r14), %edx
callq 0x3f6c
movl %eax, %r13d
cvttss2si 0xc(%r14), %esi
movq 0x38(%rbx), %rdi
cvttss2si 0x10(%r14), %edx
callq 0x3f99
cmpb $0x0, 0x20(%r14)
movzwl %bp, %ecx
jne 0x4c0e
movsd 0x30(%rbx), %xmm0
ucomisd 0x1d47(%rip), %xmm0     # 0x6940
jae 0x4c0e
cmpw $0x2248, %r13w          # imm = 0x2248
je 0x4c2f
movzwl %r13w, %edx
cmpl $0x20, %edx
je 0x4c2f
jmp 0x4c48
cmpw $0x2248, %bp            # imm = 0x2248
je 0x4c1a
cmpl $0x20, %ecx
jne 0x4c2a
movsd 0x1c6e(%rip), %xmm0     # 0x6890
movsd %xmm0, 0xc(%r14)
jmp 0x4c48
movb $0x0, 0x20(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movl %ecx, 0x30(%rsp)
movl %eax, %r13d
callq 0x4f87
movl %r13d, %eax
movl 0x30(%rsp), %ecx
testw %r12w, %r12w
je 0x4cac
movq 0x18(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%r14)
cmpq $0x15180, %rax          # imm = 0x15180
movsd 0x1c90(%rip), %xmm5     # 0x68f8
movsd 0x8(%rsp), %xmm6
movapd 0x10(%rsp), %xmm7
jl 0x4d80
andq $0x0, 0x18(%r14)
cvttss2si 0x4(%r14), %esi
cvttss2si 0x8(%r14), %edx
movq %rbx, %rdi
callq 0x4496
movapd 0x10(%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x1c51(%rip), %xmm5     # 0x68f8
jmp 0x4d80
andq $0x0, 0x18(%r14)
movsd 0x4(%r14), %xmm0
movsd 0xc(%r14), %xmm3
movaps %xmm3, %xmm1
subps %xmm0, %xmm1
movaps %xmm1, %xmm2
mulps %xmm1, %xmm2
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm1, %xmm4
mulss %xmm1, %xmm4
addss %xmm2, %xmm4
sqrtss %xmm4, %xmm2
cvtss2sd %xmm2, %xmm4
movsd 0x1c28(%rip), %xmm5     # 0x6910
ucomisd %xmm4, %xmm5
movsd 0x1c04(%rip), %xmm5     # 0x68f8
movsd 0x8(%rsp), %xmm6
movapd 0x10(%rsp), %xmm7
jbe 0x4d0e
testw %ax, %ax
je 0x4d36
movlps %xmm3, 0x4(%r14)
jmp 0x4d80
cmpw $0x20, %bp
je 0x4d2c
movss 0x1c3c(%rip), %xmm3     # 0x6958
cmpl $0x25b2, %ecx           # imm = 0x25B2
je 0x4d4e
cmpl $0x2248, %ecx           # imm = 0x2248
jne 0x4d46
movss 0x1c14(%rip), %xmm3     # 0x6948
jmp 0x4d4e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f87
jmp 0x4c93
movss 0x1c0e(%rip), %xmm3     # 0x695c
movsd 0x30(%rbx), %xmm4
ucomisd 0x1be5(%rip), %xmm4     # 0x6940
jb 0x4d64
xorps 0x1b6c(%rip), %xmm3     # 0x68d0
divss 0x1be4(%rip), %xmm3     # 0x6950
unpcklps %xmm3, %xmm3            # xmm3 = xmm3[0,0,1,1]
mulps %xmm3, %xmm1
unpcklps %xmm2, %xmm2            # xmm2 = xmm2[0,0,1,1]
divps %xmm2, %xmm1
addps %xmm1, %xmm0
movlps %xmm0, 0x4(%r14)
cmpw $0x20, %bp
sete %al
cmpw $0x2248, %bp            # imm = 0x2248
sete %cl
orb %al, %cl
movb %cl, 0x20(%r14)
addq $0x28, %r14
jmp 0x4b72
movsd 0x30(%rbx), %xmm0
ucomisd 0x1b95(%rip), %xmm0     # 0x6940
jb 0x4dcc
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x48cc
movapd 0x10(%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x1b2c(%rip), %xmm5     # 0x68f8
subpd 0x50(%rsp), %xmm7
movapd %xmm7, %xmm0
mulsd %xmm5, %xmm0
cvttsd2si %xmm0, %edx
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
mulsd %xmm5, %xmm7
cvttsd2si %xmm7, %ecx
subsd 0x48(%rsp), %xmm6
mulsd %xmm5, %xmm6
cvttsd2si %xmm6, %eax
incq 0x8(%rbx)
shlq $0x20, %rcx
orq %rcx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq