// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl 0x2b27(%rip), %eax      # 0x4120
cvtsi2sd %eax, %xmm1
movsd 0xa6b(%rip), %xmm0      # 0x2070
mulsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movl 0x2b0f(%rip), %ecx      # 0x4124
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
xorl %ebx, %ebx
cmpl %ecx, %ebx
jge 0x17ac
cvtsi2sd %ebx, %xmm0
movapd %xmm0, %xmm1
mulsd 0xa3b(%rip), %xmm1      # 0x2078
movsd %xmm1, 0x38(%rsp)
subsd 0x28(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movslq %ebx, %r14
movl %ebx, %ebp
imull %ebx, %ebp
xorl %r15d, %r15d
cmpl %eax, %r15d
jge 0x179e
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xa06(%rip), %xmm1      # 0x2080
mulsd %xmm1, %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 0x98a(%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 (%rbx,%r15), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x9b0(%rip), %xmm0      # 0x2080
callq 0x1090
movapd %xmm0, %xmm1
movsd 0x977(%rip), %xmm0      # 0x2058
mulsd %xmm0, %xmm1
addsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd 0x40(%rsp), %xmm0
sqrtsd %xmm0, %xmm0
movsd 0x961(%rip), %xmm1      # 0x2078
mulsd %xmm1, %xmm0
callq 0x1090
movsd 0x930(%rip), %xmm1      # 0x2058
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movl %r15d, %eax
imull %r15d, %eax
addl %ebp, %eax
cvtsi2sd %eax, %xmm0
sqrtsd %xmm0, %xmm0
mulsd 0x923(%rip), %xmm0      # 0x2078
callq 0x1090
movsd 0x8f6(%rip), %xmm1      # 0x2058
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movslq 0x29a9(%rip), %rax      # 0x4120
imulq %r14, %rax
cvttsd2si %xmm0, %rcx
shrl $0x3, %ecx
movq 0x29d6(%rip), %rdx      # 0x4160
addq %r15, %rax
movl %ecx, (%rdx,%rax,4)
movl 0x298a(%rip), %eax      # 0x4120
incq %r15
jmp 0x165e
incq %rbx
movl 0x297d(%rip), %ecx      # 0x4124
jmp 0x1625
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq