// File: /workspace/github_cpp_makefile_star2_O1/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 0x64946
cmpl $0x0, 0xc(%rbx)
je 0x6471a
xorl %ebp, %ebp
leaq 0x30(%rsp), %r15
cmpl $0x0, 0x8(%rbx)
je 0x6470f
xorl %r12d, %r12d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x643fa
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c6a
movsd (%rax), %xmm0
mulsd 0x24bbc(%rip), %xmm0    # 0x89208
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 0x643fa
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c6a
movsd 0x8(%rax), %xmm0
mulsd 0x24b79(%rip), %xmm0    # 0x89208
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 0x643fa
movq %rax, 0x30(%rsp)
movl %edx, 0x38(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c6a
movsd 0x10(%rax), %xmm0
mulsd 0x24b35(%rip), %xmm0    # 0x89208
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
cmpl 0x8(%rbx), %r12d
jb 0x64622
incl %ebp
cmpl 0xc(%rbx), %ebp
jb 0x64615
movq (%r14), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x40b28
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %ecx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x6, %r8d
movl $0x8, %r9d
callq 0x6ffd8
movl %eax, %ebx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6476a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3a470
testl %ebx, %ebx
jne 0x64792
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x64785
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a470
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x40847(%rip), %rdi     # 0xa4fe0
leaq 0x24b54(%rip), %rsi     # 0x892f4
movl $0x1d, %edx
callq 0x3a4f0
movl %ebx, %edi
callq 0x6f86c
movq 0x40828(%rip), %rdi     # 0xa4fe0
movq %rax, %rsi
callq 0x3a440
movq %rax, %rdi
callq 0x3a200
movl $0x1, %edi
callq 0x3a550
jmp 0x647fc
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x647ff
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3a470
jmp 0x647ff
jmp 0x647fc
jmp 0x647fc
jmp 0x647fc
jmp 0x647fc
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x64816
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a470
movq %rbx, %rdi
callq 0x3a780