// File: /workspace/github_c_makefile_star2_O1/adelciotto[P]plasma/src/palette_plasma.c
// Function: InitPlasma
void InitPlasma(void) {
    double halfWidth = width / 2.0;
    double halfHeight = height / 2.0;

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double color = 128.0 + (128.0 * sin(x / 16.0));
            color += 128.0 + (128.0 * sin(y / 8.0));
            color += 128.0 + (128.0 * sin((x + y) / 16.0));
            color += 128.0 +
                     (128.0 *
                      sin(sqrt((double)((x - halfWidth) * (x - halfWidth) +
                                        (y - halfHeight) * (y - halfHeight))) /
                          8.0));
            // Uncomment for some weird shit
            // color += 128.0 + (128.0 * sin((x * y) / 128.0));
            color += 128.0 + (128.0 * sin(sqrt((double)(x * x + y * y)) / 8.0));

            int index = Get1DArrayIndex(x, y, width);
            plasmaBuffer[index] = (Uint32)color / 8;
        }
    }
}

// Assembly:
movl 0x2aae(%rip), %eax      # 0x412c
testl %eax, %eax
jle 0x1873
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
cvtsi2sdl 0x2a90(%rip), %xmm1 # 0x4128
movsd 0x9c0(%rip), %xmm0      # 0x2060
mulsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %ebx, %ebx
cmpl $0x0, 0x2a64(%rip)      # 0x4128
jle 0x185a
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movapd %xmm0, %xmm1
mulsd 0x98b(%rip), %xmm1      # 0x2068
movsd %xmm1, 0x20(%rsp)
subsd 0x10(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movl %ebx, %ebp
imull %ebx, %ebp
movslq %ebx, %r14
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x95c(%rip), %xmm1      # 0x2070
mulsd %xmm1, %xmm0
callq 0x1090
movsd %xmm0, 0x38(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x1090
movsd %xmm0, 0x40(%rsp)
leal (%rbx,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x929(%rip), %xmm0      # 0x2070
callq 0x1090
movsd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd 0x28(%rsp), %xmm0
ucomisd 0x908(%rip), %xmm0      # 0x2078
jb 0x1778
sqrtsd %xmm0, %xmm0
jmp 0x177d
callq 0x1130
mulsd 0x8e3(%rip), %xmm0      # 0x2068
callq 0x1090
movsd %xmm0, 0x8(%rsp)
movl %r15d, %eax
imull %r15d, %eax
addl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0x8d0(%rip), %xmm0      # 0x2078
jb 0x17b0
sqrtsd %xmm0, %xmm0
jmp 0x17b5
callq 0x1130
movsd 0x88b(%rip), %xmm3      # 0x2048
movsd 0x38(%rsp), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm3, %xmm2
movsd 0x40(%rsp), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x30(%rsp), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd 0x859(%rip), %xmm0      # 0x2068
callq 0x1090
movsd 0x82c(%rip), %xmm1      # 0x2048
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movslq 0x28f7(%rip), %rax      # 0x4128
cvttsd2si %xmm0, %rcx
imulq %r14, %rax
shrl $0x3, %ecx
movq 0x291c(%rip), %rdx      # 0x4160
addq %r15, %rax
movl %ecx, (%rdx,%rax,4)
incq %r15
cmpl 0x28d4(%rip), %r15d     # 0x4128
jl 0x16fe
incq %rbx
cmpl 0x28c9(%rip), %ebx      # 0x412c
jl 0x16bd
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq