// File: /workspace/github_cpp_makefile_star2_O3/Lut99[P]RayTracer/src/lib/Image.cpp
// Function: RayTracer::Image::to_png(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Image::to_png(std::string path) {
    // Generate a 0-255, four channel vector
    std::vector<unsigned char> raw_image;
    raw_image.resize(this->width * this->height * 4);
    for (unsigned int y = 0; y < this->height; y++) {
        for (unsigned int x = 0; x < this->width; x++) {
            // Store the data as 0-255 Red Green Blue Alhpa
            raw_image[4 * (y * this->width + x) + 0] = (char) (255.0 * this->operator[](y)[x][0]);
            raw_image[4 * (y * this->width + x) + 1] = (char) (255.0 * this->operator[](y)[x][1]);
            raw_image[4 * (y * this->width + x) + 2] = (char) (255.0 * this->operator[](y)[x][2]);
            raw_image[4 * (y * this->width + x) + 3] = 255;
        }
    }

    // Write that to the output file using LodePNG
    unsigned result = lodepng::encode(path.c_str(), raw_image, this->width, this->height);
    if (result != 0) {
        cerr << "Could not write to PNG file: " << lodepng_error_text(result) << endl;
        exit(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl 0x8(%rbx), %esi
imull 0xc(%rbx), %esi
shll $0x2, %esi
callq 0x6446a
movl 0xc(%rbx), %eax
testl %eax, %eax
je 0x6423d
movl 0x8(%rbx), %ecx
xorl %ebp, %ebp
leaq 0x30(%rsp), %r15
testl %ecx, %ecx
movl $0x0, %ecx
je 0x64233
xorl %r12d, %r12d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x63efc
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x6373e
movsd (%rax), %xmm0
mulsd 0x2409d(%rip), %xmm0    # 0x88208
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x10(%rsp), %rdx
movb %al, (%rdx,%rcx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x63efc
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x6373e
movsd 0x8(%rax), %xmm0
mulsd 0x2405a(%rip), %xmm0    # 0x88208
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x10(%rsp), %rdx
movb %al, 0x1(%rdx,%rcx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x63efc
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x6373e
movsd 0x10(%rax), %xmm0
mulsd 0x24016(%rip), %xmm0    # 0x88208
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x10(%rsp), %rdx
movb %al, 0x2(%rdx,%rcx)
movl 0x8(%rbx), %eax
imull %ebp, %eax
addl %r12d, %eax
shll $0x2, %eax
movq 0x10(%rsp), %rcx
movb $-0x1, 0x3(%rcx,%rax)
incl %r12d
movl 0x8(%rbx), %ecx
cmpl %ecx, %r12d
jb 0x64141
movl 0xc(%rbx), %eax
incl %ebp
cmpl %eax, %ebp
jb 0x64131
movq (%r14), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x40986
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %ecx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x6, %r8d
movl $0x8, %r9d
callq 0x6f6a4
movl %eax, %ebx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6428d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3a480
testl %ebx, %ebx
jne 0x642b5
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x642a8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x3fd1c(%rip), %rdi     # 0xa3fd8
leaq 0x24031(%rip), %rsi     # 0x882f4
movl $0x1d, %edx
callq 0x3a500
movl %ebx, %edi
callq 0x6ef41
movq 0x3fcfd(%rip), %rdi     # 0xa3fd8
movq %rax, %rsi
callq 0x3a450
movq %rax, %rdi
callq 0x3a200
movl $0x1, %edi
callq 0x3a560
jmp 0x6431f
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x64322
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3a480
jmp 0x64322
jmp 0x6431f
jmp 0x6431f
jmp 0x6431f
jmp 0x6431f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x64339
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
movq %rbx, %rdi
callq 0x3a790