// File: /workspace/github_c_makefile_star2_O3/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 0x2ab6(%rip), %ecx      # 0x4124
testl %ecx, %ecx
jle 0x1854
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl 0x2a9a(%rip), %eax      # 0x4120
cvtsi2sd %eax, %xmm1
movsd 0x9de(%rip), %xmm0      # 0x2070
mulsd %xmm0, %xmm1
cvtsi2sd %ecx, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0x28(%rsp)
xorl %ebx, %ebx
movsd 0x9ca(%rip), %xmm0      # 0x2078
movsd 0x9ca(%rip), %xmm2      # 0x2080
movsd %xmm1, 0x30(%rsp)
testl %eax, %eax
jle 0x183f
cvtsi2sd %ebx, %xmm4
movapd %xmm4, %xmm5
mulsd %xmm0, %xmm5
movsd %xmm5, 0x38(%rsp)
subsd 0x28(%rsp), %xmm4
mulsd %xmm4, %xmm4
movsd %xmm4, 0x40(%rsp)
movslq %ebx, %r14
movl %ebx, %ebp
imull %ebx, %ebp
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
mulsd %xmm2, %xmm0
callq 0x1090
movapd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x1090
movapd 0x10(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x905(%rip), %xmm0      # 0x2030
mulpd %xmm0, %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movapd %xmm0, 0x10(%rsp)
leal (%r14,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x928(%rip), %xmm0      # 0x2080
callq 0x1090
mulsd 0x8f3(%rip), %xmm0      # 0x2058
addsd 0x8eb(%rip), %xmm0      # 0x2058
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd 0x40(%rsp), %xmm0
sqrtsd %xmm0, %xmm0
movsd 0x8dd(%rip), %xmm1      # 0x2078
mulsd %xmm1, %xmm0
callq 0x1090
mulsd 0x8ac(%rip), %xmm0      # 0x2058
addsd 0x8a4(%rip), %xmm0      # 0x2058
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movl %r15d, %eax
imull %r15d, %eax
addl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
sqrtsd %xmm0, %xmm0
mulsd 0x89c(%rip), %xmm0      # 0x2078
callq 0x1090
movsd 0x86f(%rip), %xmm1      # 0x2058
movsd 0x88f(%rip), %xmm2      # 0x2080
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movslq 0x291a(%rip), %rax      # 0x4120
cvttsd2si %xmm0, %rcx
shrl $0x3, %ecx
movq 0x294b(%rip), %rdx      # 0x4160
imulq %r14, %rax
addq %r15, %rax
movl %ecx, (%rdx,%rax,4)
movl 0x28fb(%rip), %eax      # 0x4120
incq %r15
cmpl %eax, %r15d
jl 0x16f1
movl 0x28ed(%rip), %ecx      # 0x4124
movsd 0x839(%rip), %xmm0      # 0x2078
incq %rbx
cmpl %ecx, %ebx
jl 0x16bc
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq