// File: /workspace/github_c_makefile_star2_O2/yahya-tamur[P]Visualising-Complex-Functions/testImage.cc
// Function: main
int main() {
    auto before_frames = std::chrono::high_resolution_clock::now();
    auto frames = getFrames(function);
    auto after_frames = std::chrono::high_resolution_clock::now();

    ge_GIF *gif = ge_new_gif(file_name, width, height, colors,

        palette_bit_depth,
        0 // for infinite loop
    );

    std::cout << "writing..." << std::endl;
    auto before_fwrite = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < num_frames; i++) {
        for (int j = 0; j < width * height; j++)
            gif->frame[j] = (*frames)[i][j];
        ge_add_frame(gif, delay);
        std::cout << i << " / num frames = " << num_frames << std::endl;
    }
    auto after_fwrite = std::chrono::high_resolution_clock::now();
    ge_close_gif(gif);

    auto frame_duration
        = std::chrono::duration_cast<std::chrono::microseconds>(after_frames - before_frames);
    auto fwrite_duration
        = std::chrono::duration_cast<std::chrono::microseconds>(after_fwrite - before_fwrite);

    FILE *p_file = NULL;
    p_file = fopen(file_name, "rb");
    fseek(p_file, 0, SEEK_END);
    int size = ftell(p_file);
    fclose(p_file);
    double file_size = size / 1000000.0;
    std::cout << "function duration (s) :      " << frame_duration.count() / 1000000.0 << std::endl;
    std::cout << "file write duration (s) : " << fwrite_duration.count() / 1000000.0 << std::endl;
    std::cout << "file size (mb) :          " << file_size << std::endl;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
callq 0x2040
leaq 0x28(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movq %rax, %rbx
leaq 0x756(%rip), %rax       # 0x3490
movq %rax, (%rsi)
leaq 0x704(%rip), %rax       # 0x3448
movq %rax, 0x18(%rsi)
leaq 0x71d(%rip), %rax       # 0x346c
movq %rax, 0x10(%rsi)
leaq 0x8(%rsp), %rdi
callq 0x29a0
movq %rbx, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x30a6
callq 0x2040
movq %rax, 0x18(%rsp)
leaq 0x3407(%rip), %r12      # 0x6184
movzwl (%r12), %esi
leaq 0x33ff(%rip), %r14      # 0x6188
movzwl (%r14), %edx
leaq 0x343c(%rip), %rax      # 0x61d0
movl (%rax), %r8d
leaq 0x33b2(%rip), %rdi      # 0x6150
leaq 0x342f(%rip), %rcx      # 0x61d4
xorl %r9d, %r9d
callq 0x237c
movq %rax, %r15
movq 0x3221(%rip), %rdi      # 0x5fd8
leaq 0x1286(%rip), %rsi      # 0x4044
callq 0x2140
movq %rax, %rdi
callq 0x20b0
xorl %r13d, %r13d
callq 0x2040
movq %rax, 0x10(%rsp)
leaq 0x3379(%rip), %rbp      # 0x6158
leaq 0x1269(%rip), %rbx      # 0x404f
movslq (%rbp), %rax
cmpq %rax, %r13
jge 0x2e64
imulq $0x18, %r13, %rax
xorl %ecx, %ecx
movslq (%r12), %rdx
movslq (%r14), %rsi
imulq %rdx, %rsi
cmpq %rsi, %rcx
jge 0x2e20
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movq (%rdx,%rax), %rdx
movb (%rdx,%rcx), %dl
movq 0x18(%r15), %rsi
movb %dl, (%rsi,%rcx)
incq %rcx
jmp 0x2df5
leaq 0x333d(%rip), %rax      # 0x6164
movzwl (%rax), %esi
movq %r15, %rdi
callq 0x2511
movq 0x319f(%rip), %rdi      # 0x5fd8
movl %r13d, %esi
callq 0x2220
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2140
movl (%rbp), %esi
movq %rax, %rdi
callq 0x2220
movq %rax, %rdi
callq 0x20b0
incq %r13
jmp 0x2de6
callq 0x2040
movq %rax, %rbx
movq %r15, %rdi
callq 0x2821
subq 0x10(%rsp), %rbx
movl $0x3e8, %r14d           # imm = 0x3E8
movq %rbx, %rax
cqto
idivq %r14
movq %rax, %rbx
leaq 0x32bf(%rip), %rdi      # 0x6150
leaq 0x11c8(%rip), %rsi      # 0x4060
callq 0x2190
movq %rax, %r12
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2180
movq %r12, %rdi
callq 0x2030
movq %rax, %r15
movq %r12, %rdi
callq 0x2150
movq 0x3111(%rip), %rdi      # 0x5fd8
leaq 0x1195(%rip), %rsi      # 0x4063
callq 0x2140
movq %rax, %rdi
movq 0x18(%rsp), %rax
subq 0x20(%rsp), %rax
cqto
idivq %r14
cvtsi2sd %rax, %xmm0
divsd 0x113e(%rip), %xmm0     # 0x4030
callq 0x21f0
movq %rax, %rdi
callq 0x20b0
movq 0x30d2(%rip), %rdi      # 0x5fd8
leaq 0x1174(%rip), %rsi      # 0x4081
callq 0x2140
cvtsi2sd %rbx, %xmm0
divsd 0x1111(%rip), %xmm0     # 0x4030
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x20b0
movq 0x30a2(%rip), %rdi      # 0x5fd8
leaq 0x115f(%rip), %rsi      # 0x409c
callq 0x2140
cvtsi2sd %r15d, %xmm0
divsd 0x10e1(%rip), %xmm0     # 0x4030
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x20b0
leaq 0x8(%rsp), %rdi
callq 0x308c
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f8f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x30a6
jmp 0x2f9c
jmp 0x2f8f
jmp 0x2f8f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x308c
movq %rbx, %rdi
callq 0x2230