// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/engine/renderer/particle_system.cpp
// Function: Renderer::create_particle_system(unsigned int, unsigned int, Vec2)
ParticleSystem create_particle_system(u32 layer, u32 num_particles, Vec2 position) {
    ASSERT(num_particles > 1, "Too small particle system");
    Util::MemoryArena *arena = Util::request_arena();
    Particle *particles = arena->push<Particle>(num_particles);

    for (u32 i = 0; i < num_particles; i++) {
        particles[i].progress = 2.0;
    }
    ParticleSystem particle_system = {};
    particle_system.memory = arena;
    particle_system.num_sprites = 0;
    particle_system.layer = 1;
    particle_system.head = 1;
    particle_system.max_num_particles = num_particles;
    particle_system.particles = particles;
    particle_system.layer = layer;

    particle_system.relative = false;
    particle_system.keep_alive = false;
    particle_system.one_color = true;
    particle_system.one_alpha = false;
    particle_system.one_size = false;
    particle_system.drop_oldest = false;

    particle_system.num_sprites = 0;

    particle_system.position = position;

    particle_system.alive_time = {2, 2};
    particle_system.rotation = {0, 2 * PI};
    particle_system.angular_velocity = {0, 0};

    particle_system.spawn_size = {0.5, 1.0};
    particle_system.die_size = {0.0, 0.0};
    particle_system.progress_func_size = std_progress_func_f32;

    particle_system.width = {1.0, 1.0};
    particle_system.height = {1.0, 1.0};

    particle_system.position_x = {0.0, 0.0};
    particle_system.position_y = {0.0, 0.0};
    particle_system.velocity_dir = {PI / 2.0, PI / 2.0};
    particle_system.velocity = {3.0, 5.0};
    particle_system.damping = {0.90, 1.0};
    particle_system.acceleration_dir = {-PI / 2.0, -PI / 2.0};
    particle_system.acceleration = {0.0, 0.0};

    particle_system.spawn_red = {1.0, 1.0};
    particle_system.spawn_green = {1.0, 1.0};
    particle_system.spawn_blue = {1.0, 1.0};
    particle_system.spawn_alpha = {1.0, 1.0};

    particle_system.die_red = {};
    particle_system.die_green = {};
    particle_system.die_blue = {};
    particle_system.die_alpha = {};

    particle_system.progress_func_color = std_progress_func_vec4;

    return particle_system;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movaps %xmm0, -0x40(%rbp)
movl %edx, %r15d
movl %esi, -0x2c(%rbp)
movq %rdi, %rbx
xorl %ecx, %ecx
cmpl $0x2, %edx
setae %cl
leaq 0xe61e(%rip), %rdi      # 0x31423
leaq 0xe70a(%rip), %rdx      # 0x31516
movl $0xb4, %esi
callq 0x722f
xorl %edi, %edi
callq 0xaf5a
movq %rax, %r12
movl %r15d, %r14d
movq %rax, %rdi
movq %r14, %rsi
callq 0x2e4be
movq %rax, %r13
testl %r15d, %r15d
je 0x22e58
movq %r14, %rax
shlq $0x7, %rax
leaq (%rax,%r14,8), %rax
xorl %ecx, %ecx
movl $0x40000000, (%r13,%rcx) # imm = 0x40000000
addq $0x88, %rcx
cmpq %rcx, %rax
jne 0x22e43
xorl %r14d, %r14d
movl $0x218, %edx            # imm = 0x218
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21c0
movq %r12, 0x120(%rbx)
movl $0x0, (%rbx)
movl $0x1, 0x108(%rbx)
movl %r15d, 0x110(%rbx)
movq %r13, 0x118(%rbx)
movl -0x2c(%rbp), %eax
movl %eax, 0x4(%rbx)
movl $0x10000, 0x128(%rbx)   # imm = 0x10000
movw $0x0, 0x12c(%rbx)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, 0x130(%rbx)
movaps 0xd426(%rip), %xmm0     # 0x302e0
movups %xmm0, 0x138(%rbx)
movq %r14, 0x148(%rbx)
movabsq $0x3f8000003f000000, %rax # imm = 0x3F8000003F000000
movq %rax, 0x188(%rbx)
movq %r14, 0x198(%rbx)
leaq -0x1a048(%rip), %rax    # 0x8e9f
movq %rax, 0x208(%rbx)
movaps 0xd3fb(%rip), %xmm0     # 0x302f0
movups %xmm0, 0x1a8(%rbx)
xorps %xmm1, %xmm1
movups %xmm1, 0x150(%rbx)
movaps 0xd3f3(%rip), %xmm2     # 0x30300
movups %xmm2, 0x160(%rbx)
movaps 0xd3f5(%rip), %xmm2     # 0x30310
movups %xmm2, 0x170(%rbx)
movq %r14, 0x180(%rbx)
movups %xmm0, 0x1b8(%rbx)
movups %xmm0, 0x1c8(%rbx)
movups %xmm1, 0x1f0(%rbx)
movups %xmm1, 0x1e0(%rbx)
leaq -0x19fe5(%rip), %rax    # 0x8f67
movq %rax, 0x210(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq