// File: miklhh[P]mandelbrot/src/render.cpp
// Function: render_mandelbrot(std::complex<double> const&, std::complex<double> const&)
void render_mandelbrot(
    const std::complex<double> & upper_left, 
    const std::complex<double> & lower_right)
{
    /* Test if renderer is initialized. */
    if (!render_initialized)
    {
        std::cerr << "Renderer not initialized. Could not render." << std::endl;
        return;
    }
    /* Set the scale and the offset and aquire the segments. */
    scale = get_scale(upper_left, lower_right);
    offset = get_offset(upper_left, lower_right);
    supersample_init(scale, offset);
    int segment_size_x = scr_width / 20;
    int segment_size_y = scr_height / 20;
    for (int y = 0; y < scr_height / segment_size_y; y++)
    {
        for (int x = 0; x < scr_width / segment_size_x; x++)
        {
            segment_t segment = {
                segment_size_x * x,
                segment_size_y * y,
                segment_size_x * (1 + x),
                segment_size_y * (1 + y)};
            mandelbrot_thread_pool_add_job(thread_pool, segment);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
testb $0x1, 0x11226(%rip)     # 0x15280
jne 0x4083
movq 0x10f8d(%rip), %rdi     # 0x14ff0
leaq 0xa0d2(%rip), %rsi      # 0xe13c
callq 0x3260
movq %rax, %rdi
movq 0x10f3f(%rip), %rsi     # 0x14fb8
callq 0x3290
jmp 0x4214
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm3
callq 0x4220
movsd %xmm0, -0x20(%rbp)
movsd %xmm1, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq %rax, 0x111c1(%rip)     # 0x15298
movq -0x18(%rbp), %rax
movq %rax, 0x111be(%rip)     # 0x152a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x42d0
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq %rax, 0x111a4(%rip)     # 0x152a8
movq -0x48(%rbp), %rax
movq %rax, 0x111a1(%rip)     # 0x152b0
leaq 0x11182(%rip), %rdi     # 0x15298
leaq 0x1118b(%rip), %rsi     # 0x152a8
callq 0x6dc0
leaq 0x9ef7(%rip), %rax      # 0xe020
movl (%rax), %eax
movl $0x14, %ecx
cltd
idivl %ecx
movl %eax, -0x54(%rbp)
leaq 0x9ee7(%rip), %rax      # 0xe024
movl (%rax), %eax
movl $0x14, %ecx
cltd
idivl %ecx
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq 0x9ec3(%rip), %rax      # 0xe024
movl (%rax), %eax
cltd
idivl -0x58(%rbp)
movl %eax, %ecx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jge 0x4214
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq 0x9e92(%rip), %rax      # 0xe020
movl (%rax), %eax
cltd
idivl -0x54(%rbp)
movl %eax, %ecx
movl -0x88(%rbp), %eax
cmpl %ecx, %eax
jge 0x4204
movl -0x54(%rbp), %eax
imull -0x60(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x58(%rbp), %eax
imull -0x5c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x54(%rbp), %eax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x68(%rbp)
movl -0x58(%rbp), %eax
movl -0x5c(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x64(%rbp)
movq 0x110af(%rip), %rdi     # 0x15288
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x7840
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x417e
jmp 0x4206
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4151
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)