// File: /workspace/github_cpp_makefile_star2_O3/miklhh[P]mandelbrot/src/main.cpp
// Function: main
int main (int argc, char *argv[])
{
    /* Get rid of the 'argv', 'argc' warnings. */
    (void)argc;
    (void)argv;

    /* Init SDL. */
    if (SDL_Init(SDL_INIT_VIDEO) != 0) 
    {
        std::cout << "Could not init SDL." << std::endl;
        return -1;
    }

    SDL_Event event;
    if (SDL_CreateWindowAndRenderer(scr_width, scr_height, 0, &window, &renderer) != 0)
    {
        std::cerr << "Could not create window and renderer." << std::endl;
        return -1;
    }

    /* Initialize the mandelbrot renderer. */

    //complex<double> ul = std::complex<double>(-0.74510, 0.11868);
    //complex<double> lr = std::complex<double>(-0.74490, 0.11848);

    /* Fractal. */
    //complex<double> ul = std::complex<double>(-0.7455, 0.1190);
    //complex<double> lr = std::complex<double>(-0.7445, 0.1180);

    /* Fractal zoomed out. */
    //complex<double> ul = std::complex<double>(-0.746, 0.120);
    //complex<double> lr = std::complex<double>(-0.745, 0.119);

    /* Original fractal. */
    std::complex<double> ul = std::complex<double>(-2, 1);
    std::complex<double> lr = std::complex<double>(1, -1);


    render_init(4);
    render_mandelbrot(ul, lr);
    //render_mandelbrot(std::complex<double>(0.3994999999988, 0.195303), scale_t{ 0.00000001, 0.00000001 });

    /* Draw mandelbrot to the renderer and renderer to the screen. */
    bool once = true;
    while (window_is_open)
    {
        if (render_test_complete() && once)
        {
            render_create_bmp("hello.bmp");
            once = false;
        }

        render_draw_to_SDL_Renderer(renderer);
        SDL_RenderPresent(renderer);

        /* Handle events. */
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_QUIT) { window_is_open = false; }
        }
        SDL_Delay(1);
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    shutdown("Successful exit.", 0);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x80, %rsp
movl $0x20, %edi
callq 0x21e0
testl %eax, %eax
je 0x267a
movq 0x5964(%rip), %rbx      # 0x7fd0
leaq 0x29fd(%rip), %rsi      # 0x5070
movl $0x13, %edx
jmp 0x26b0
leaq 0x5b7f(%rip), %rcx      # 0x8200
leaq 0x5b80(%rip), %r8       # 0x8208
movl $0x780, %edi            # imm = 0x780
movl $0x438, %esi            # imm = 0x438
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
je 0x26f0
movq 0x594c(%rip), %rbx      # 0x7ff0
leaq 0x29d9(%rip), %rsi      # 0x5084
movl $0x25, %edx
movq %rbx, %rdi
callq 0x2250
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movaps 0x2919(%rip), %xmm0     # 0x5010
leaq 0x30(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps 0x291a(%rip), %xmm0     # 0x5020
leaq 0x20(%rsp), %r14
movaps %xmm0, (%r14)
movl $0x4, %edi
callq 0x2898
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bc3
cmpb $0x0, 0x5ae5(%rip)      # 0x8210
jne 0x279c
movb $0x1, %bpl
leaq 0x2973(%rip), %rbx      # 0x50aa
leaq 0x48(%rsp), %r14
callq 0x2dfc
andb %bpl, %al
cmpb $0x1, %al
jne 0x2752
movq %rbx, %rdi
callq 0x2e10
xorl %ebp, %ebp
movq 0x5aaf(%rip), %rdi      # 0x8208
callq 0x2d61
movq 0x5aa3(%rip), %rdi      # 0x8208
callq 0x2060
movq %r14, %rdi
callq 0x2140
testl %eax, %eax
je 0x2789
cmpl $0x100, 0x48(%rsp)      # imm = 0x100
jne 0x276a
movb $0x1, 0x5a89(%rip)      # 0x8210
jmp 0x276a
movl $0x1, %edi
callq 0x2180
cmpb $0x1, 0x5a76(%rip)      # 0x8210
jne 0x273c
movq 0x5a65(%rip), %rdi      # 0x8208
callq 0x20e0
movq 0x5a51(%rip), %rdi      # 0x8200
callq 0x2030
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28f0(%rip), %rsi      # 0x50b4
leaq 0x28f9(%rip), %rdx      # 0x50c4
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x2802
movq %rbx, %rdi
xorl %esi, %esi
callq 0x25ec
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x27f9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x2350
nop