// File: /workspace/github_c_makefile_star2_O0/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
subq $0x170, %rsp            # imm = 0x170
movlpd %xmm0, -0x8(%rbp)
movlpd %xmm1, -0x10(%rbp)
movlpd %xmm3, -0x20(%rbp)
movlpd %xmm4, -0x18(%rbp)
movl %edi, -0x24(%rbp)
movq %rsi, -0x30(%rbp)
movss %xmm2, -0x34(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2dcb0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x2dcd0
movzwl 0x12(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x3, %eax
setae %al
movzbl %al, %ecx
leaq 0x18968(%rip), %rdi     # 0x4630a
leaq 0x18981(%rip), %rdx     # 0x4632a
movl $0x3f, %esi
callq 0xb210
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movss (%rax), %xmm0
movss 0x4(%rax), %xmm1
callq 0xbc10
movlpd %xmm0, -0x64(%rbp)
movss -0x34(%rbp), %xmm1
movsd -0x64(%rbp), %xmm0
callq 0xb500
movlpd %xmm0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movsd -0x5c(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0xb450
movlpd %xmm0, -0x54(%rbp)
movsd -0x54(%rbp), %xmm0
leaq -0x8(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x40dc0
movlpd %xmm0, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movss 0x8(%rax), %xmm0
movss 0xc(%rax), %xmm1
callq 0xbc10
movlpd %xmm0, -0x78(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movss 0x10(%rax), %xmm0
movss 0x14(%rax), %xmm1
callq 0xbc10
movlpd %xmm0, -0x98(%rbp)
movss -0x34(%rbp), %xmm1
movsd -0x98(%rbp), %xmm0
callq 0xb500
movlpd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movsd -0x90(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
callq 0xb450
movq -0x148(%rbp), %rdi
movlpd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0x40dc0
movlpd %xmm0, -0x80(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movss 0x18(%rax), %xmm0
movss 0x1c(%rax), %xmm1
callq 0xbc10
movlpd %xmm0, -0xa8(%rbp)
movl $0x2, -0xac(%rbp)
movl -0xac(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x2dca5
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xac(%rbp), %ecx
shlq $0x4, %rcx
movss (%rax,%rcx), %xmm0
movss 0x4(%rax,%rcx), %xmm1
callq 0xbc10
movlpd %xmm0, -0xcc(%rbp)
movss -0x34(%rbp), %xmm1
movsd -0xcc(%rbp), %xmm0
callq 0xb500
movlpd %xmm0, -0xc4(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movsd -0xc4(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
callq 0xb450
movlpd %xmm0, -0xbc(%rbp)
movsd -0xbc(%rbp), %xmm0
leaq -0x8(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0xb4(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xac(%rbp), %ecx
shlq $0x4, %rcx
movss 0x8(%rax,%rcx), %xmm0
movss 0xc(%rax,%rcx), %xmm1
callq 0xbc10
movlpd %xmm0, -0xe0(%rbp)
movl -0x24(%rbp), %edi
movq -0x4c(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xb4(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x110(%rbp)
movups -0x20(%rbp), %xmm0
movaps %xmm0, -0x120(%rbp)
movups -0x20(%rbp), %xmm0
movaps %xmm0, -0x130(%rbp)
movups -0x20(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movl -0x44(%rbp), %eax
cvtsi2ss %rax, %xmm8
movsd -0xe8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
movsd -0xf8(%rbp), %xmm2
movsd -0x100(%rbp), %xmm3
movsd -0x108(%rbp), %xmm4
movsd -0x110(%rbp), %xmm5
movsd -0x120(%rbp), %xmm6
movsd -0x118(%rbp), %xmm7
movups -0x140(%rbp), %xmm9
movq %rsp, %rax
movups %xmm9, 0x10(%rax)
movups -0x130(%rbp), %xmm9
movups %xmm9, (%rax)
movss %xmm8, 0x20(%rax)
callq 0x2c740
movq -0xb4(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x2dad7
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nop