// File: /workspace/github_cpp_makefile_star2_O2/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 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl 0x8(%rbx), %esi
imull 0xc(%rbx), %esi
shll $0x2, %esi
callq 0x737c0
xorl %ebp, %ebp
leaq 0x10(%rsp), %r15
cmpl 0xc(%rbx), %ebp
jae 0x73703
xorl %r12d, %r12d
cmpl 0x8(%rbx), %r12d
jae 0x736fc
movq %rbx, %rdi
movl %ebp, %esi
callq 0x73494
movq %rax, 0x10(%rsp)
movl %edx, 0x18(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x73004
movsd (%rax), %xmm0
mulsd 0x1cd4a(%rip), %xmm0    # 0x90388
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x30(%rsp), %rdx
movb %al, (%rdx,%rcx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x73494
movq %rax, 0x10(%rsp)
movl %edx, 0x18(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x73004
movsd 0x8(%rax), %xmm0
mulsd 0x1cd07(%rip), %xmm0    # 0x90388
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x30(%rsp), %rdx
movb %al, 0x1(%rdx,%rcx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x73494
movq %rax, 0x10(%rsp)
movl %edx, 0x18(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x73004
movsd 0x10(%rax), %xmm0
mulsd 0x1ccc3(%rip), %xmm0    # 0x90388
cvttsd2si %xmm0, %eax
movl 0x8(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
shll $0x2, %ecx
movq 0x30(%rsp), %rdx
movb %al, 0x2(%rdx,%rcx)
movl 0x8(%rbx), %eax
imull %ebp, %eax
addl %r12d, %eax
shll $0x2, %eax
movq 0x30(%rsp), %rcx
movb $-0x1, 0x3(%rcx,%rax)
incl %r12d
jmp 0x7360a
incl %ebp
jmp 0x735fe
movq (%r14), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x56548
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %ecx
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
pushq $0x6
popq %r8
pushq $0x8
popq %r9
callq 0x7c088
movl %eax, %ebx
leaq 0x10(%rsp), %rdi
callq 0x52888
testl %ebx, %ebx
jne 0x73759
leaq 0x30(%rsp), %rdi
callq 0x737ec
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x3e880(%rip), %rdi     # 0xb1fe0
leaq 0x1cd0d(%rip), %rsi     # 0x90474
callq 0x52450
movq %rax, %r14
movl %ebx, %edi
callq 0x7bac8
movq %r14, %rdi
movq %rax, %rsi
callq 0x52450
movq %rax, %rdi
callq 0x52210
pushq $0x1
popq %rdi
callq 0x52550
jmp 0x737aa
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x52888
jmp 0x737ad
jmp 0x737aa
jmp 0x737aa
jmp 0x737aa
jmp 0x737aa
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x737ec
movq %rbx, %rdi
callq 0x527a0
nop