// File: /workspace/github_c_makefile_star2_O2/FredTheDino[P]Fog/src/engine/renderer/command.cpp
// Function: Renderer::push_sprite(unsigned int, unsigned long long, Vec2, Vec2, float, Vec4)
void push_sprite(u32 layer, AssetID sprite_id, Vec2 position,
                 Vec2 dimension, f32 angle, Vec4 color) {
    Sprite *sprite = Asset::fetch_sprite(sprite_id);
    u32 slot = Asset::fetch_image(sprite->sprite_sheet)->id;
    ASSERT(sprite->num_points >= 3, "A sprite has to have atleast 3 points");
    // TODO(ed): Here we can brake out the sinus compute to
    // save on doing the same calculation multiple times.

#define TRANSLATE(p) position + hadamard(rotate(V2(p.x, p.y), angle), dimension)
#define UV(p) V2(p.z, p.w)
    Vec2 start_p = TRANSLATE(sprite->points[0]);
    Vec2 start_t = UV(sprite->points[0]);

    Vec2 prev_p = TRANSLATE(sprite->points[1]);
    Vec2 prev_t = UV(sprite->points[1]);
    for (u32 i = 2; i < sprite->num_points; i++) {
        Vec2 next_p = TRANSLATE(sprite->points[i]);
        Vec2 next_t = UV(sprite->points[i]);
        Impl::push_triangle(layer,
                            start_p, prev_p, next_p,
                            start_t, prev_t, next_t,
                            color, color, color, slot);
        prev_p = next_p;
        prev_t = next_t;
    }
#undef TRANSLATE
#undef UV
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movaps %xmm4, -0x70(%rbp)
movaps %xmm3, -0x60(%rbp)
movss %xmm2, -0x24(%rbp)
movaps %xmm1, -0x50(%rbp)
movaps %xmm0, -0x40(%rbp)
movl %edi, %ebx
movq %rsi, %rdi
callq 0x1fef3
movq %rax, %r14
movq (%rax), %rdi
callq 0x1ff02
movzwl 0x12(%rax), %r15d
xorl %ecx, %ecx
cmpl $0x3, 0x8(%r14)
setae %cl
leaq 0xc57d(%rip), %rdi      # 0x2c312
leaq 0xc596(%rip), %rdx      # 0x2c332
pushq $0x3f
popq %rsi
callq 0x6903
movq 0x10(%r14), %rax
movsd (%rax), %xmm0
movss -0x24(%rbp), %xmm1
callq 0x6aaa
mulps -0x50(%rbp), %xmm0
addps -0x40(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
movq 0x10(%r14), %rax
movsd 0x8(%rax), %xmm0
movaps %xmm0, -0x90(%rbp)
movsd 0x10(%rax), %xmm0
movss -0x24(%rbp), %xmm1
callq 0x6aaa
movaps %xmm0, %xmm1
mulps -0x50(%rbp), %xmm1
addps -0x40(%rbp), %xmm1
movq 0x10(%r14), %rax
movsd 0x18(%rax), %xmm2
cvtsi2ss %r15d, %xmm0
movss %xmm0, -0x28(%rbp)
pushq $0x2
popq %r15
xorl %r12d, %r12d
movaps -0x60(%rbp), %xmm0
unpcklpd -0x70(%rbp), %xmm0      # xmm0 = xmm0[0],mem[0]
movaps %xmm0, -0x80(%rbp)
movl 0x8(%r14), %eax
cmpq %rax, %r15
jae 0x1fee3
movq 0x10(%r14), %rax
movsd 0x20(%rax,%r12), %xmm0
movaps %xmm1, -0xd0(%rbp)
movss -0x24(%rbp), %xmm1
movaps %xmm2, -0xe0(%rbp)
callq 0x6aaa
mulps -0x50(%rbp), %xmm0
addps -0x40(%rbp), %xmm0
movaps %xmm0, %xmm2
movaps %xmm0, -0xc0(%rbp)
movq 0x10(%r14), %rax
movsd 0x28(%rax,%r12), %xmm5
movaps %xmm5, -0xb0(%rbp)
movaps -0x80(%rbp), %xmm0
movups %xmm0, -0x100(%rbp)
movups %xmm0, -0xf0(%rbp)
movups -0xf0(%rbp), %xmm0
movups %xmm0, 0x10(%rsp)
movups -0x100(%rbp), %xmm0
movups %xmm0, (%rsp)
movss -0x28(%rbp), %xmm0
movss %xmm0, 0x20(%rsp)
movl %ebx, %edi
movaps -0xa0(%rbp), %xmm0
movaps -0xd0(%rbp), %xmm1
movaps -0x90(%rbp), %xmm3
movaps -0xe0(%rbp), %xmm4
movaps -0x60(%rbp), %xmm6
movaps -0x70(%rbp), %xmm7
callq 0x1f2f7
incq %r15
addq $0x10, %r12
movaps -0xb0(%rbp), %xmm2
movaps -0xc0(%rbp), %xmm1
jmp 0x1fe16
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq