// File: /workspace/github_c_makefile_star2_O1/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 $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x372a(%rip), %rax      # 0x6194
movslq (%rax), %rax
leaq 0x3724(%rip), %rcx      # 0x6198
movslq (%rcx), %rsi
imulq %rax, %rsi
leaq 0x30(%rsp), %rdi
leaq 0x2f(%rsp), %rdx
callq 0x3268
movl $0x18, %edi
callq 0x2170
movq %rax, %r13
leaq 0x36ca(%rip), %r12      # 0x6168
movslq (%r12), %rsi
leaq 0x30(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
movq %rax, %rdi
callq 0x333e
movq %r13, (%rbx)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2ad1
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x36bc(%rip), %rax      # 0x6194
cmpl $0x0, (%rax)
jle 0x2e3b
movl $0x0, 0x20(%rsp)
leaq 0x3680(%rip), %r15      # 0x6170
leaq 0x3675(%rip), %rbp      # 0x616c
movq %r14, 0x98(%rsp)
leaq 0x3692(%rip), %rax      # 0x6198
movl (%rax), %eax
testl %eax, %eax
jle 0x2dc0
movl 0x20(%rsp), %ecx
movl %ecx, 0x6c(%rsp)
xorl %r13d, %r13d
fildl 0x6c(%rsp)
fstpt 0xa4(%rsp)
leaq 0x3673(%rip), %rcx      # 0x61a0
fldt (%rcx)
leaq 0x365e(%rip), %rcx      # 0x6194
movl (%rcx), %ecx
movl %ecx, 0x60(%rsp)
fldt 0xa4(%rsp)
fidivl 0x60(%rsp)
leaq 0x3662(%rip), %rcx      # 0x61b0
fldt (%rcx)
fsub %st(2), %st
fmulp %st, %st(1)
faddp %st, %st(1)
leaq 0x3673(%rip), %rcx      # 0x61d0
fldt (%rcx)
movl %r13d, 0x64(%rsp)
fildl 0x64(%rsp)
movl %eax, 0x68(%rsp)
fidivl 0x68(%rsp)
leaq 0x3649(%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 0x2e50
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq *0x18(%r14)
leaq 0x35e5(%rip), %rax      # 0x6194
movl (%rax), %r14d
imull %r13d, %r14d
fldt 0xb0(%rsp)
fldt 0xc0(%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 0x35a3(%rip), %rax      # 0x6190
cmpb $0x1, (%rax)
jne 0x2bfa
fstpt (%rsp)
callq 0x20c0
fld %st(0)
fstpt 0x80(%rsp)
btq $0x3f, 0x80(%rsp)
setae %al
movzwl 0x88(%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 0x2c83
leaq 0x3547(%rip), %rax      # 0x6180
fldt (%rax)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x2060
movl (%r12), %eax
movl %eax, 0x58(%rsp)
fimull 0x58(%rsp)
leaq 0x3526(%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 0x5c(%rsp)
fldcw 0x28(%rsp)
movl 0x5c(%rsp), %ecx
fldz
fstp %st(0)
testl %ecx, %ecx
jns 0x2c96
movl (%r12), %esi
movl %ecx, %eax
cltd
idivl %esi
movl %edx, %ecx
addl %esi, %ecx
addl 0x20(%rsp), %r14d
cmpl $0x0, (%r15)
movslq %r14d, %r14
jle 0x2ccb
xorl %esi, %esi
leal (%rcx,%rsi), %eax
cltd
idivl (%r12)
movq (%rbx), %rax
movslq %edx, %rdx
movq (%rax), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rax
movb $0x1, (%rax,%r14)
incl %esi
cmpl (%r15), %esi
jl 0x2ca6
fldt 0xb0(%rsp)
fldt 0xc0(%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 0x70(%rsp)
movq 0x70(%rsp), %rax
movzwl 0x78(%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 0x12ef(%rip)            # 0x4028
fld %st(1)
fadd %st(1), %st
fxch %st(2)
fcmovnbe %st(2), %st
fstp %st(2)
movl (%r12), %eax
movl %eax, 0x50(%rsp)
fxch %st(1)
fimull 0x50(%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 0x54(%rsp)
fldcw 0x26(%rsp)
cmpl $0x0, (%rbp)
jle 0x2da3
movl 0x54(%rsp), %ecx
xorl %esi, %esi
leal (%rcx,%rsi), %eax
cltd
idivl (%r12)
movq (%rbx), %rax
movslq %edx, %rdx
movq (%rax), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rax
movb $0x2, (%rax,%r14)
incl %esi
cmpl (%rbp), %esi
jl 0x2d7e
incl %r13d
leaq 0x33eb(%rip), %rax      # 0x6198
movl (%rax), %eax
cmpl %eax, %r13d
movq 0x98(%rsp), %r14
jl 0x2b26
movq 0x3211(%rip), %rdi      # 0x5fd8
movl 0x20(%rsp), %esi
callq 0x2240
movq %rax, %r13
movl $0xb, %edx
movq %rax, %rdi
leaq 0x1256(%rip), %rsi      # 0x4038
callq 0x21a0
leaq 0x33a6(%rip), %rax      # 0x6194
movl (%rax), %esi
movq %r13, %rdi
callq 0x2240
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movl 0x20(%rsp), %ecx
incl %ecx
leaq 0x3365(%rip), %rax      # 0x6194
movl %ecx, 0x20(%rsp)
cmpl (%rax), %ecx
jl 0x2aff
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
movq %rax, %r14
movl $0x18, %esi
movq %r13, %rdi
callq 0x2180
jmp 0x2e6a
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2e97
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x2e97
movq %rax, %r14
jmp 0x2e97
jmp 0x2e8c
jmp 0x2e8c
movq %rax, %r14
movq %rbx, %rdi
callq 0x32c8
movq %r14, %rdi
callq 0x2250