// File: 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:
subq $0x198, %rsp            # imm = 0x198
movq %rsi, 0x98(%rsp)
movq %rdi, 0x190(%rsp)
movq %rsi, 0x188(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x170(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x13c0d0
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rdi
movl 0x8(%rcx), %eax
movl 0xc(%rcx), %ecx
imull %ecx, %eax
shll $0x2, %eax
movl %eax, %esi
callq 0x13c0e0
jmp 0x13bbb9
movl $0x0, 0x160(%rsp)
movq 0xa0(%rsp), %rcx
movl 0x160(%rsp), %eax
cmpl 0xc(%rcx), %eax
jae 0x13bf4b
movl $0x0, 0x15c(%rsp)
movq 0xa0(%rsp), %rcx
movl 0x15c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jae 0x13bf33
movq 0xa0(%rsp), %rdi
movl 0x160(%rsp), %esi
callq 0x13b950
movl %edx, 0x8c(%rsp)
movq %rax, 0x90(%rsp)
jmp 0x13bc24
movl 0x8c(%rsp), %eax
movq 0x90(%rsp), %rcx
movq %rcx, 0x130(%rsp)
movl %eax, 0x138(%rsp)
movl 0x138(%rsp), %eax
movl %eax, 0x148(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x140(%rsp)
movl 0x15c(%rsp), %esi
leaq 0x140(%rsp), %rdi
callq 0x13b160
movq %rax, 0x80(%rsp)
jmp 0x13bc7e
movq 0x80(%rsp), %rax
movq %rax, 0x150(%rsp)
leaq 0x150(%rsp), %rdi
xorl %esi, %esi
callq 0x13af30
movq %rax, 0x78(%rsp)
jmp 0x13bca4
movq 0xa0(%rsp), %rcx
movq 0x78(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x3a39b(%rip), %xmm1    # 0x176058
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x6b(%rsp)
movl 0x160(%rsp), %eax
movl 0x8(%rcx), %ecx
imull %ecx, %eax
movl 0x15c(%rsp), %ecx
addl %ecx, %eax
shll $0x2, %eax
movl %eax, %esi
leaq 0x170(%rsp), %rdi
callq 0x13c180
movb 0x6b(%rsp), %cl
movq 0xa0(%rsp), %rdi
movb %cl, (%rax)
movl 0x160(%rsp), %esi
callq 0x13b950
movl %edx, 0x6c(%rsp)
movq %rax, 0x70(%rsp)
jmp 0x13bd16
movl 0x6c(%rsp), %eax
movq 0x70(%rsp), %rcx
movq %rcx, 0x108(%rsp)
movl %eax, 0x110(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x118(%rsp)
movl 0x15c(%rsp), %esi
leaq 0x118(%rsp), %rdi
callq 0x13b160
movq %rax, 0x60(%rsp)
jmp 0x13bd67
movq 0x60(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x128(%rsp), %rdi
movl $0x1, %esi
callq 0x13af30
movq %rax, 0x58(%rsp)
jmp 0x13bd8d
movq 0xa0(%rsp), %rax
movq 0x58(%rsp), %rcx
movsd (%rcx), %xmm0
movsd 0x3a2b2(%rip), %xmm1    # 0x176058
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, 0x4b(%rsp)
movl 0x160(%rsp), %ecx
movl 0x8(%rax), %eax
imull %eax, %ecx
movl 0x15c(%rsp), %eax
addl %eax, %ecx
movl %ecx, %eax
leal 0x1(,%rax,4), %eax
movl %eax, %esi
leaq 0x170(%rsp), %rdi
callq 0x13c180
movb 0x4b(%rsp), %cl
movq 0xa0(%rsp), %rdi
movb %cl, (%rax)
movl 0x160(%rsp), %esi
callq 0x13b950
movl %edx, 0x4c(%rsp)
movq %rax, 0x50(%rsp)
jmp 0x13be05
movl 0x4c(%rsp), %eax
movq 0x50(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movl %eax, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, 0xf8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl 0x15c(%rsp), %esi
leaq 0xf0(%rsp), %rdi
callq 0x13b160
movq %rax, 0x40(%rsp)
jmp 0x13be56
movq 0x40(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rdi
movl $0x2, %esi
callq 0x13af30
movq %rax, 0x38(%rsp)
jmp 0x13be7c
movq 0xa0(%rsp), %rcx
movq 0x38(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x3a1c3(%rip), %xmm1    # 0x176058
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x37(%rsp)
movl 0x160(%rsp), %eax
imull 0x8(%rcx), %eax
addl 0x15c(%rsp), %eax
shll $0x2, %eax
addl $0x2, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x170(%rsp), %rdi
callq 0x13c180
movb 0x37(%rsp), %dl
movq 0xa0(%rsp), %rcx
movb %dl, (%rax)
movl 0x160(%rsp), %eax
imull 0x8(%rcx), %eax
addl 0x15c(%rsp), %eax
shll $0x2, %eax
addl $0x3, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x170(%rsp), %rdi
callq 0x13c180
movb $-0x1, (%rax)
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
jmp 0x13bbe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0x13c0a9
jmp 0x13bf35
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x13bbc4
movq 0x98(%rsp), %rdi
callq 0xd0220
movq %rax, 0x20(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xd0a20
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0xd8b80
jmp 0x13bf88
movq 0xa0(%rsp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
leaq 0xb8(%rsp), %rdi
leaq 0x170(%rsp), %rsi
movl $0x6, %r8d
movl $0x8, %r9d
callq 0x14b6a0
movl %eax, 0x1c(%rsp)
jmp 0x13bfbd
leaq 0xb8(%rsp), %rdi
callq 0xd0b38
leaq 0xb7(%rsp), %rdi
callq 0xd0630
movl 0x1c(%rsp), %eax
movl %eax, 0xdc(%rsp)
cmpl $0x0, 0xdc(%rsp)
je 0x13c094
movq 0x6ffe9(%rip), %rdi     # 0x1abfe0
leaq 0x3a146(%rip), %rsi     # 0x176144
callq 0xd05b0
movq %rax, 0x10(%rsp)
jmp 0x13c00a
movl 0xdc(%rsp), %edi
callq 0x14a260
movq %rax, 0x8(%rsp)
jmp 0x13c01d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xd05b0
movq %rax, (%rsp)
jmp 0x13c032
movq (%rsp), %rdi
movq 0x6fefb(%rip), %rsi     # 0x1abf38
callq 0xd0610
jmp 0x13c044
movl $0x1, %edi
callq 0xd0700
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0x13c085
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xd0b38
leaq 0xb7(%rsp), %rdi
callq 0xd0630
jmp 0x13c0a9
leaq 0x170(%rsp), %rdi
callq 0x13c1a0
addq $0x198, %rsp            # imm = 0x198
retq
leaq 0x170(%rsp), %rdi
callq 0x13c1a0
movq 0x168(%rsp), %rdi
callq 0xd0a10
nopw %cs:(%rax,%rax)
nopl (%rax)