// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movaps %xmm4, -0x60(%rbp)
movaps %xmm3, -0xa0(%rbp)
movss %xmm2, -0x2c(%rbp)
movaps %xmm1, -0xd0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movl %edi, %r14d
movq %rsi, %rdi
movl $0x3, %esi
callq 0x23225
movq %rax, %rbx
movq (%rax), %rdi
movl $0x1, %esi
callq 0x23225
movzwl 0x12(%rax), %r15d
xorl %ecx, %ecx
cmpl $0x3, 0x8(%rbx)
setae %cl
leaq 0xfdcb(%rip), %rdi      # 0x3133a
leaq 0xfde4(%rip), %rdx      # 0x3135a
movl $0x3f, %esi
callq 0x729c
movq 0x10(%rbx), %rax
movss (%rax), %xmm0
movss %xmm0, -0x90(%rbp)
movss 0x4(%rax), %xmm0
movss %xmm0, -0x70(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2050
movss %xmm0, -0x30(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2350
movss %xmm0, -0x38(%rbp)
movq 0x10(%rbx), %rax
movsd 0x8(%rax), %xmm0
movaps %xmm0, -0x80(%rbp)
movss 0x10(%rax), %xmm0
movaps %xmm0, -0x50(%rbp)
movss 0x14(%rax), %xmm0
movss %xmm0, -0xb0(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2050
movss %xmm0, -0x34(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2350
cmpl $0x3, 0x8(%rbx)
jb 0x21861
movss -0x30(%rbp), %xmm4
movaps %xmm4, %xmm1
movss -0x70(%rbp), %xmm3
mulss %xmm3, %xmm1
movss -0x90(%rbp), %xmm2
movaps %xmm2, %xmm5
movss -0x38(%rbp), %xmm6
mulss %xmm6, %xmm5
subss %xmm1, %xmm5
mulss %xmm6, %xmm3
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
movaps -0xd0(%rbp), %xmm3
mulss %xmm3, %xmm5
movaps %xmm3, %xmm6
shufps $0x55, %xmm3, %xmm6     # xmm6 = xmm6[1,1],xmm3[1,1]
movaps %xmm6, %xmm1
mulss %xmm2, %xmm1
movaps -0xc0(%rbp), %xmm4
addss %xmm4, %xmm5
movaps %xmm4, %xmm7
shufps $0x55, %xmm4, %xmm7     # xmm7 = xmm7[1,1],xmm4[1,1]
movaps %xmm7, %xmm2
addss %xmm1, %xmm2
unpcklps %xmm2, %xmm5            # xmm5 = xmm5[0],xmm2[0],xmm5[1],xmm2[1]
unpcklpd -0x80(%rbp), %xmm5      # xmm5 = xmm5[0],mem[0]
movaps %xmm5, -0x90(%rbp)
movq 0x10(%rbx), %rax
movsd 0x18(%rax), %xmm5
movss -0x34(%rbp), %xmm10
movaps %xmm10, %xmm1
movss -0xb0(%rbp), %xmm9
mulss %xmm9, %xmm1
movaps -0x50(%rbp), %xmm8
movaps %xmm8, %xmm2
mulss %xmm0, %xmm2
subss %xmm1, %xmm2
mulss %xmm3, %xmm2
addss %xmm4, %xmm2
mulss %xmm0, %xmm9
mulss %xmm10, %xmm8
addss %xmm9, %xmm8
movaps %xmm6, -0x80(%rbp)
mulss %xmm6, %xmm8
movaps %xmm7, -0x70(%rbp)
addss %xmm7, %xmm8
unpcklps %xmm8, %xmm2            # xmm2 = xmm2[0],xmm8[0],xmm2[1],xmm8[1]
movzwl %r15w, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
xorl %r15d, %r15d
cmpl $0x10, %r14d
setb %r15b
movl %r14d, %r14d
shlq $0x5, %r14
addq 0x2d8e4(%rip), %r14     # 0x4efe0
movl $0x2, %r13d
xorl %r12d, %r12d
movaps -0xa0(%rbp), %xmm0
unpcklpd -0x60(%rbp), %xmm0      # xmm0 = xmm0[0],mem[0]
movaps %xmm0, -0xa0(%rbp)
movlhps %xmm5, %xmm2            # xmm2 = xmm2[0],xmm5[0]
movaps %xmm2, -0xb0(%rbp)
movq 0x10(%rbx), %rax
movss 0x20(%rax,%r12), %xmm0
movaps %xmm0, -0x60(%rbp)
movss 0x24(%rax,%r12), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2050
movss %xmm0, -0x34(%rbp)
movss -0x2c(%rbp), %xmm0
callq 0x2350
movss -0x34(%rbp), %xmm5
movaps %xmm5, %xmm1
movss -0x50(%rbp), %xmm4
mulss %xmm4, %xmm1
movaps -0x60(%rbp), %xmm3
movaps %xmm3, %xmm2
mulss %xmm0, %xmm2
subss %xmm1, %xmm2
mulss %xmm0, %xmm4
mulss %xmm5, %xmm3
addss %xmm4, %xmm3
mulss -0xd0(%rbp), %xmm2
mulss -0x80(%rbp), %xmm3
addss -0xc0(%rbp), %xmm2
addss -0x70(%rbp), %xmm3
unpcklps %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
movaps %xmm2, -0x60(%rbp)
movq 0x10(%rbx), %rax
movsd 0x28(%rax,%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0xf8bc(%rip), %rdi      # 0x31075
movl $0x1cc, %esi            # imm = 0x1CC
leaq 0xf932(%rip), %rdx      # 0x310f7
movl %r15d, %ecx
callq 0x729c
movaps -0x90(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movss -0x30(%rbp), %xmm2
movss %xmm2, -0x130(%rbp)
movaps -0xa0(%rbp), %xmm1
movups %xmm1, -0x12c(%rbp)
movaps -0xb0(%rbp), %xmm0
movups %xmm0, -0x11c(%rbp)
movss %xmm2, -0x10c(%rbp)
movups %xmm1, -0x108(%rbp)
movaps -0x60(%rbp), %xmm0
unpcklpd -0x50(%rbp), %xmm0      # xmm0 = xmm0[0],mem[0]
movups %xmm0, -0xf8(%rbp)
movss %xmm2, -0xe8(%rbp)
movups %xmm1, -0xe4(%rbp)
movq %r14, %rdi
movl $0x3, %esi
leaq -0x140(%rbp), %rdx
callq 0x2d8ee
movaps -0x50(%rbp), %xmm5
incq %r13
movl 0x8(%rbx), %eax
addq $0x10, %r12
movaps -0x60(%rbp), %xmm2
cmpq %rax, %r13
jb 0x21718
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq