// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rdi, %rbx
leaq 0x37c6(%rip), %r14      # 0x6184
movslq (%r14), %rax
leaq 0x37c0(%rip), %rcx      # 0x6188
movslq (%rcx), %rsi
imulq %rax, %rsi
leaq 0x80(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0x2ffc
leaq 0x376d(%rip), %r15      # 0x6158
leaq 0x80(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2fa4
leaq 0x80(%rsp), %rdi
callq 0x311e
xorl %esi, %esi
leaq 0x374c(%rip), %r12      # 0x6160
leaq 0x3741(%rip), %rbp      # 0x615c
movq %r13, 0x78(%rsp)
cmpl (%r14), %esi
jge 0x2cc3
movl %esi, 0x4c(%rsp)
xorl %edx, %edx
fildl 0x4c(%rsp)
fstpt 0xa4(%rsp)
movl %esi, 0x24(%rsp)
leaq 0x3743(%rip), %rax      # 0x6188
movl (%rax), %eax
cmpl %eax, %edx
jge 0x2c8a
leaq 0x373a(%rip), %rcx      # 0x6190
fldt (%rcx)
movl (%r14), %ecx
movl %ecx, 0x40(%rsp)
fldt 0xa4(%rsp)
fidivl 0x40(%rsp)
leaq 0x372f(%rip), %rcx      # 0x61a0
fldt (%rcx)
fsub %st(2), %st
fmulp %st, %st(1)
faddp %st, %st(1)
leaq 0x3740(%rip), %rcx      # 0x61c0
fldt (%rcx)
movl %edx, 0x2c(%rsp)
movl %edx, 0x44(%rsp)
fildl 0x44(%rsp)
movl %eax, 0x48(%rsp)
fidivl 0x48(%rsp)
leaq 0x3713(%rip), %rax      # 0x61b0
fldt (%rax)
fsub %st(2), %st
fmulp %st, %st(1)
faddp %st, %st(1)
fxch %st(1)
fstpt 0x80(%rsp)
fstpt 0x90(%rsp)
cmpq $0x0, 0x10(%r13)
je 0x2cd8
movq %r13, %rsi
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
leaq 0x80(%rsp), %rdx
callq *0x18(%rsi)
movl (%r14), %r14d
imull 0x2c(%rsp), %r14d
movq %r13, %rdi
callq 0x304d
leaq 0x368f(%rip), %rax      # 0x6180
cmpb $0x1, (%rax)
jne 0x2afe
fstpt (%rsp)
callq 0x20c0
fld %st(0)
fstpt 0x60(%rsp)
movq 0x60(%rsp), %rax
shrq $0x3f, %rax
movzwl 0x68(%rsp), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
decl %ecx
movzwl %cx, %ecx
cmpl $0x7ffe, %ecx           # imm = 0x7FFE
setb %dl
xorl %r13d, %r13d
movl $0x0, %ecx
testb %al, %dl
je 0x2b8f
leaq 0x3637(%rip), %rax      # 0x6170
fldt (%rax)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x2050
movl (%r15), %esi
movl %esi, 0x38(%rsp)
fimull 0x38(%rsp)
leaq 0x3617(%rip), %rax      # 0x6170
fldt (%rax)
fdivrp %st, %st(1)
fnstcw 0x22(%rsp)
movzwl 0x22(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x2a(%rsp)
fldcw 0x2a(%rsp)
fistpl 0x3c(%rsp)
fldcw 0x22(%rsp)
movl 0x3c(%rsp), %ecx
testl %ecx, %ecx
jns 0x2b8d
movl %ecx, %eax
cltd
idivl %esi
movl %edx, %ecx
addl %esi, %ecx
fldz
fstp %st(0)
addl 0x24(%rsp), %r14d
movslq %r14d, %r14
cmpl (%r12), %r13d
jge 0x2bc2
leal (%rcx,%r13), %eax
cltd
idivl (%r15)
movq (%rbx), %rax
movslq %edx, %rdx
movq (%rax), %rax
imulq $0x18, %rdx, %rdx
movq (%rax,%rdx), %rax
movb $0x1, (%rax,%r14)
incl %r13d
jmp 0x2b99
leaq 0xb0(%rsp), %rdi
callq 0x306c
fld %st(0)
fstpt 0x50(%rsp)
movzwl 0x58(%rsp), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
decl %eax
movzwl %ax, %eax
movq 0x50(%rsp), %rcx
shrq $0x3f, %rcx
testq %rcx, %rcx
fldz
fld %st(0)
fcmovne %st(2), %st
fstp %st(2)
cmpl $0x7ffe, %eax           # imm = 0x7FFE
fld %st(0)
fcmovb %st(2), %st
fstp %st(2)
fucompi %st(1), %st
fldl 0x141d(%rip)            # 0x4028
fld %st(1)
fadd %st(1), %st
fxch %st(2)
fcmovnbe %st(2), %st
fstp %st(2)
movl (%r15), %eax
movl %eax, 0x30(%rsp)
fxch %st(1)
fimull 0x30(%rsp)
fdivp %st, %st(1)
fnstcw 0x20(%rsp)
movzwl 0x20(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x28(%rsp)
fldcw 0x28(%rsp)
fistpl 0x34(%rsp)
fldcw 0x20(%rsp)
xorl %ecx, %ecx
movl 0x34(%rsp), %esi
movq 0x78(%rsp), %r13
cmpl (%rbp), %ecx
jge 0x2c74
leal (%rsi,%rcx), %eax
cltd
idivl (%r15)
movq (%rbx), %rax
movslq %edx, %rdx
movq (%rax), %rax
imulq $0x18, %rdx, %rdx
movq (%rax,%rdx), %rax
movb $0x2, (%rax,%r14)
incl %ecx
jmp 0x2c4e
movl 0x2c(%rsp), %edx
incl %edx
leaq 0x3503(%rip), %r14      # 0x6184
movl 0x24(%rsp), %esi
jmp 0x2a3e
movq 0x3347(%rip), %rdi      # 0x5fd8
callq 0x2220
movq %rax, %rdi
leaq 0x1398(%rip), %rsi      # 0x4038
callq 0x2140
movl (%r14), %esi
movq %rax, %rdi
callq 0x2220
movq %rax, %rdi
callq 0x20b0
movl 0x24(%rsp), %esi
incl %esi
jmp 0x2a20
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2090
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x311e
jmp 0x2d0b
movq %rax, %r14
jmp 0x2d0b
jmp 0x2d00
jmp 0x2d00
fstp %st(0)
jmp 0x2d00
fstp %st(0)
jmp 0x2d00
movq %rax, %r14
movq %rbx, %rdi
callq 0x308c
movq %r14, %rdi
callq 0x2230