// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movl %esi, -0x30(%rbp)
movq %rdi, %rbx
xorl %ecx, %ecx
cmpl $0x2, %edx
setae %cl
leaq 0xb637(%rip), %rdi      # 0x2c3eb
leaq 0xb723(%rip), %rdx      # 0x2c4de
movl $0xb4, %esi
callq 0x6903
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x9a17
movq %rax, %r12
movl %r14d, -0x2c(%rbp)
movl %r14d, %r14d
movq %rax, %rdi
movq %r14, %rsi
callq 0x29ad4
movq %rax, %r13
imulq $0x88, %r14, %rax
cmpq %r15, %rax
je 0x20e05
movl $0x40000000, (%r13,%r15) # imm = 0x40000000
addq $0x88, %r15
jmp 0x20dee
leaq 0x8(%rbx), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x21c0
movq %r12, 0x120(%rbx)
movl $0x1, 0x108(%rbx)
movl -0x2c(%rbp), %eax
movl %eax, 0x110(%rbx)
movq %r13, 0x118(%rbx)
movl -0x30(%rbp), %eax
movl %eax, 0x4(%rbx)
movw $0x100, 0x129(%rbx)     # imm = 0x100
movb $0x0, 0x12c(%rbx)
andl $0x0, (%rbx)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, 0x130(%rbx)
movabsq $0x4000000040000000, %rax # imm = 0x4000000040000000
movq %rax, 0x138(%rbx)
movl $0x40c90fd0, 0x144(%rbx) # imm = 0x40C90FD0
andl $0x0, 0x14c(%rbx)
movabsq $0x3f8000003f000000, %rax # imm = 0x3F8000003F000000
movq %rax, 0x188(%rbx)
andl $0x0, 0x19c(%rbx)
leaq -0x18ded(%rip), %rax    # 0x80ae
movq %rax, 0x208(%rbx)
movaps 0xa427(%rip), %xmm0     # 0x2b2d0
movups %xmm0, 0x1a8(%rbx)
xorps %xmm1, %xmm1
movups %xmm1, 0x150(%rbx)
movaps 0xa41f(%rip), %xmm2     # 0x2b2e0
movups %xmm2, 0x160(%rbx)
movaps 0xa421(%rip), %xmm2     # 0x2b2f0
movups %xmm2, 0x170(%rbx)
andl $0x0, 0x184(%rbx)
movups %xmm0, 0x1b8(%rbx)
movups %xmm0, 0x1c8(%rbx)
movups %xmm1, 0x1f0(%rbx)
movups %xmm1, 0x1e0(%rbx)
leaq -0x18d96(%rip), %rax    # 0x816a
movq %rax, 0x210(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq