// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
pushq $0x20
popq %rdi
callq 0x21e0
testl %eax, %eax
je 0x25f5
movq 0x69e4(%rip), %rdi      # 0x8fd0
leaq 0x2a7d(%rip), %rsi      # 0x5070
jmp 0x2626
leaq 0x6bf4(%rip), %rcx      # 0x91f0
leaq 0x6bf5(%rip), %r8       # 0x91f8
movl $0x780, %edi            # imm = 0x780
movl $0x438, %esi            # imm = 0x438
xorl %edx, %edx
callq 0x2090
testl %eax, %eax
je 0x2644
movq 0x69d1(%rip), %rdi      # 0x8ff0
leaq 0x2a5e(%rip), %rsi      # 0x5084
callq 0x2210
movq %rax, %rdi
callq 0x2120
pushq $-0x1
popq %rax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movaps 0x29c5(%rip), %xmm0     # 0x5010
leaq 0x20(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps 0x29c6(%rip), %xmm0     # 0x5020
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
pushq $0x4
popq %rdi
callq 0x280c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a42
movb $0x1, %r15b
leaq 0x2a2a(%rip), %rbx      # 0x50aa
leaq 0x50(%rsp), %r14
pushq $0x1
popq %rbp
cmpb $0x0, 0x6b71(%rip)      # 0x9200
jne 0x26e8
callq 0x2c37
andb %r15b, %al
cmpb $0x1, %al
jne 0x26a8
movq %rbx, %rdi
callq 0x2c4b
xorl %r15d, %r15d
movq 0x6b49(%rip), %rdi      # 0x91f8
callq 0x2b96
movq 0x6b3d(%rip), %rdi      # 0x91f8
callq 0x2050
movq %r14, %rdi
callq 0x2150
testl %eax, %eax
je 0x26df
cmpl $0x100, 0x50(%rsp)      # imm = 0x100
jne 0x26c0
movb $0x1, 0x6b23(%rip)      # 0x9200
jmp 0x26c0
movl %ebp, %edi
callq 0x2180
jmp 0x2688
movq 0x6b09(%rip), %rdi      # 0x91f8
callq 0x20d0
movq 0x6af5(%rip), %rdi      # 0x91f0
callq 0x2030
leaq 0x29ad(%rip), %rsi      # 0x50b4
leaq 0x30(%rsp), %rbx
leaq 0xf(%rsp), %rdx
movq %rbx, %rdi
callq 0x2738
movq %rbx, %rdi
xorl %esi, %esi
callq 0x256c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2330