// File: /workspace/github_cpp_makefile_star2_O1/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 0x29d1(%rip), %rsi      # 0x5044
movl $0x13, %edx
jmp 0x26b0
leaq 0x5b77(%rip), %rcx      # 0x81f8
leaq 0x5b78(%rip), %r8       # 0x8200
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 0x29ad(%rip), %rsi      # 0x5058
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
movabsq $-0x4000000000000000, %rax # imm = 0xC000000000000000
leaq 0x38(%rsp), %rbx
movq %rax, (%rbx)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rbx)
leaq 0x28(%rsp), %r14
movq %rax, (%r14)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x8(%r14)
movl $0x4, %edi
callq 0x28b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bd5
cmpb $0x0, 0x5ac6(%rip)      # 0x8208
jne 0x27b6
movb $0x1, %bpl
leaq 0x2930(%rip), %rbx      # 0x507e
leaq 0x48(%rsp), %r14
callq 0x2e32
testb %al, %al
je 0x276c
testb $0x1, %bpl
je 0x276c
movq %rbx, %rdi
callq 0x2e46
xorl %ebp, %ebp
movq 0x5a8d(%rip), %rdi      # 0x8200
callq 0x2d97
movq 0x5a81(%rip), %rdi      # 0x8200
callq 0x2060
movq %r14, %rdi
callq 0x2140
testl %eax, %eax
je 0x27a3
cmpl $0x100, 0x48(%rsp)      # imm = 0x100
jne 0x2784
movb $0x1, 0x5a67(%rip)      # 0x8208
jmp 0x2784
movl $0x1, %edi
callq 0x2180
cmpb $0x1, 0x5a54(%rip)      # 0x8208
jne 0x2753
movq 0x5a43(%rip), %rdi      # 0x8200
callq 0x20e0
movq 0x5a2f(%rip), %rdi      # 0x81f8
callq 0x2030
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28aa(%rip), %rsi      # 0x5088
leaq 0x28b3(%rip), %rdx      # 0x5098
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x281e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x25ec
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2816
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x2350