// File: /workspace/github_c_makefile_star2_O3/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 0xe8c2(%rip), %rdi      # 0x31413
leaq 0xe9ae(%rip), %rdx      # 0x31506
movl $0xb4, %esi
callq 0x729c
xorl %edi, %edi
callq 0xacd1
movq %rax, %r12
movl %r15d, %r14d
movq %rax, %rdi
movq %r14, %rsi
callq 0x2dd30
movq %rax, %r13
testl %r15d, %r15d
je 0x22ba4
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 0x22b8f
leaq 0x8(%rbx), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x21c0
movq %r12, 0x120(%rbx)
movl $0x1, 0x108(%rbx)
movl %r15d, 0x110(%rbx)
movq %r13, 0x118(%rbx)
movl -0x2c(%rbp), %eax
movl %eax, 0x4(%rbx)
movw $0x100, 0x129(%rbx)     # imm = 0x100
movb $0x0, 0x12c(%rbx)
xorl %ecx, %ecx
movl %ecx, (%rbx)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, 0x130(%rbx)
movabsq $0x4000000040000000, %rax # imm = 0x4000000040000000
movq %rax, 0x138(%rbx)
movl $0x40c90fd0, 0x144(%rbx) # imm = 0x40C90FD0
movl %ecx, 0x14c(%rbx)
movabsq $0x3f8000003f000000, %rax # imm = 0x3F8000003F000000
movq %rax, 0x188(%rbx)
movl %ecx, 0x19c(%rbx)
leaq -0x19ef1(%rip), %rax    # 0x8d46
movq %rax, 0x208(%rbx)
movaps 0xd69b(%rip), %xmm0     # 0x302e0
movups %xmm0, 0x1a8(%rbx)
xorps %xmm1, %xmm1
movups %xmm1, 0x150(%rbx)
movaps 0xd693(%rip), %xmm2     # 0x302f0
movups %xmm2, 0x160(%rbx)
movaps 0xd695(%rip), %xmm2     # 0x30300
movups %xmm2, 0x170(%rbx)
movl %ecx, 0x184(%rbx)
movups %xmm0, 0x1b8(%rbx)
movups %xmm0, 0x1c8(%rbx)
movups %xmm1, 0x1f0(%rbx)
movups %xmm1, 0x1e0(%rbx)
leaq -0x19e8d(%rip), %rax    # 0x8e0e
movq %rax, 0x210(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq