// File: /workspace/github_c_makefile_star2_O3/yahya-tamur[P]Visualising-Complex-Functions/testImage.cc
// Function: getFrames(std::function<std::complex<long double> (std::complex<long double>)> const&)
std::unique_ptr<std::vector<std::vector<uint8_t>>> getFrames(
    const std::function<std::complex<long double>(std::complex<long double>)> &f) {

    auto frames = std::make_unique<std::vector<std::vector<uint8_t>>>(
        num_frames, std::vector<uint8_t>(width * height));
    //for every pixel, ...
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            auto value
                = f(std::complex<long double>(x_min + ((long double) i / width) * (x_max - x_min),
                    y_max + ((long double) j / height) * (y_min - y_max)));
            int location_index = (width * j + i);

            //(the abs of a complex value is its magnitude)
            long double d = std::abs(value);
            if (logarithmic_contour_lines) {
                d = logl(d);
            }
            int contour_frame = 0;
            if (std::isnormal(d)) {
                contour_frame = fmodl(d, height_difference) * num_frames / height_difference;
            }
            if (contour_frame < 0) {
                contour_frame = (contour_frame % num_frames) + num_frames;
            }
            for (int k = 0; k < num_active_contour_frames; k++) {
                int active_frame = (contour_frame + k) % num_frames;
                (*frames)[active_frame][location_index] = 1;
            }

            d = std::arg(value);
            if (!std::isnormal(d))
                d = 0;
            if (d < 0)
                d += 2 * M_PI;
            int angle_frame = d * num_frames / (2 * M_PI);

            for (int k = 0; k < num_active_angle_frames; k++) {
                int active_frame = (angle_frame + k) % num_frames;
                (*frames)[active_frame][location_index] = 2;
            }
        }
        std::cout << i << " / width = " << width << std::endl;
    }
    return frames;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, 0x58(%rsp)
leaq 0x3728(%rip), %rax      # 0x6194
movslq (%rax), %rax
leaq 0x3722(%rip), %rcx      # 0x6198
movslq (%rcx), %rsi
imulq %rax, %rsi
leaq 0x30(%rsp), %rdi
leaq 0x2f(%rsp), %rdx
callq 0x3272
movl $0x18, %edi
callq 0x2170
movq %rax, %r15
leaq 0x36c8(%rip), %r13      # 0x6168
movslq (%r13), %rsi
leaq 0x30(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
movq %rax, %rdi
callq 0x3348
movq 0x58(%rsp), %rax
movq %r15, (%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2ad8
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x36b5(%rip), %rax      # 0x6194
cmpl $0x0, (%rax)
jle 0x2e3f
movl $0x0, 0x20(%rsp)
leaq 0x3679(%rip), %r12      # 0x6170
leaq 0x366e(%rip), %rbp      # 0x616c
movq %r14, 0xa8(%rsp)
leaq 0x368b(%rip), %rax      # 0x6198
movl (%rax), %eax
testl %eax, %eax
jle 0x2dc4
movl 0x20(%rsp), %ecx
movl %ecx, 0x7c(%rsp)
xorl %ebx, %ebx
fildl 0x7c(%rsp)
fstpt 0xb4(%rsp)
leaq 0x366d(%rip), %rcx      # 0x61a0
fldt (%rcx)
leaq 0x3658(%rip), %rcx      # 0x6194
movl (%rcx), %ecx
movl %ecx, 0x70(%rsp)
fldt 0xb4(%rsp)
fidivl 0x70(%rsp)
leaq 0x365c(%rip), %rcx      # 0x61b0
fldt (%rcx)
fsub %st(2), %st
fmulp %st, %st(1)
faddp %st, %st(1)
leaq 0x366d(%rip), %rcx      # 0x61d0
fldt (%rcx)
movl %ebx, 0x74(%rsp)
fildl 0x74(%rsp)
movl %eax, 0x78(%rsp)
fidivl 0x78(%rsp)
leaq 0x3644(%rip), %rax      # 0x61c0
fldt (%rax)
fsub %st(2), %st
fmulp %st, %st(1)
faddp %st, %st(1)
fxch %st(1)
fstpt 0x30(%rsp)
fstpt 0x40(%rsp)
cmpq $0x0, 0x10(%r14)
je 0x2e56
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq *0x18(%r14)
leaq 0x35e0(%rip), %rax      # 0x6194
movl (%rax), %r14d
imull %ebx, %r14d
fldt 0xc0(%rsp)
fldt 0xd0(%rsp)
fxch %st(1)
fstpt 0x30(%rsp)
fstpt 0x40(%rsp)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
callq 0x2200
leaq 0x359e(%rip), %rax      # 0x6190
cmpb $0x1, (%rax)
jne 0x2bff
fstpt (%rsp)
callq 0x20c0
fld %st(0)
fstpt 0x90(%rsp)
btq $0x3f, 0x90(%rsp)
setae %al
movzwl 0x98(%rsp), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
decl %ecx
movzwl %cx, %ecx
cmpl $0x7ffe, %ecx           # imm = 0x7FFE
setae %dl
xorl %ecx, %ecx
orb %al, %dl
jne 0x2c95
leaq 0x3542(%rip), %rax      # 0x6180
fldt (%rax)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x2060
movl (%r13), %esi
movl %esi, 0x68(%rsp)
fimull 0x68(%rsp)
leaq 0x3521(%rip), %rax      # 0x6180
fldt (%rax)
fdivrp %st, %st(1)
fnstcw 0x28(%rsp)
movzwl 0x28(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x2c(%rsp)
fldcw 0x2c(%rsp)
fistpl 0x6c(%rsp)
fldcw 0x28(%rsp)
movl 0x6c(%rsp), %ecx
testl %ecx, %ecx
jns 0x2c93
movl %ecx, %eax
cltd
idivl %esi
movl %edx, %ecx
addl %esi, %ecx
fldz
fstp %st(0)
addl 0x20(%rsp), %r14d
cmpl $0x0, (%r12)
movslq %r14d, %r14
jle 0x2ccb
xorl %esi, %esi
leal (%rcx,%rsi), %eax
cltd
idivl (%r13)
movslq %edx, %rax
movq (%r15), %rdx
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rax
movb $0x1, (%rax,%r14)
incl %esi
cmpl (%r12), %esi
jl 0x2ca8
fldt 0xc0(%rsp)
fldt 0xd0(%rsp)
fxch %st(1)
fstpt 0x30(%rsp)
fstpt 0x40(%rsp)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
callq 0x2130
fld %st(0)
fstpt 0x80(%rsp)
movq 0x80(%rsp), %rax
movzwl 0x88(%rsp), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
decl %ecx
movzwl %cx, %ecx
shrq $0x3f, %rax
testq %rax, %rax
fldz
fld %st(0)
fcmovne %st(2), %st
fstp %st(2)
cmpl $0x7ffe, %ecx           # imm = 0x7FFE
fld %st(0)
fcmovb %st(2), %st
fstp %st(2)
fucompi %st(1), %st
fldl 0x12e6(%rip)            # 0x4028
fld %st(1)
fadd %st(1), %st
fxch %st(2)
fcmovnbe %st(2), %st
fstp %st(2)
movl (%r13), %eax
movl %eax, 0x60(%rsp)
fxch %st(1)
fimull 0x60(%rsp)
fdivp %st, %st(1)
fnstcw 0x26(%rsp)
movzwl 0x26(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x2a(%rsp)
fldcw 0x2a(%rsp)
fistpl 0x64(%rsp)
fldcw 0x26(%rsp)
cmpl $0x0, (%rbp)
jle 0x2da9
movl 0x64(%rsp), %ecx
xorl %esi, %esi
leal (%rcx,%rsi), %eax
cltd
idivl (%r13)
movslq %edx, %rax
movq (%r15), %rdx
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rax
movb $0x2, (%rax,%r14)
incl %esi
cmpl (%rbp), %esi
jl 0x2d87
incl %ebx
leaq 0x33e6(%rip), %rax      # 0x6198
movl (%rax), %eax
cmpl %eax, %ebx
movq 0xa8(%rsp), %r14
jl 0x2b2c
movq 0x320d(%rip), %rdi      # 0x5fd8
movl 0x20(%rsp), %esi
callq 0x2240
movq %rax, %rbx
movl $0xb, %edx
movq %rax, %rdi
leaq 0x1252(%rip), %rsi      # 0x4038
callq 0x21a0
leaq 0x33a2(%rip), %rax      # 0x6194
movl (%rax), %esi
movq %rbx, %rdi
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movl 0x20(%rsp), %ecx
incl %ecx
leaq 0x3361(%rip), %rax      # 0x6194
movl %ecx, 0x20(%rsp)
cmpl (%rax), %ecx
jl 0x2b06
movq 0x58(%rsp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
movq %rax, %rbx
movl $0x18, %esi
movq %r15, %rdi
callq 0x2180
jmp 0x2e70
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x2e9f
movq %rax, %rbx
jmp 0x2e9f
jmp 0x2e92
jmp 0x2e92
movq %rax, %rbx
movq 0x58(%rsp), %rdi
callq 0x32d2
movq %rbx, %rdi
callq 0x2250