// File: /workspace/github_cpp_makefile_star2_O1/IsaacLaw12[P]RayTracer/./src/Image.cpp
// Function: Image::save_image(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Image::save_image(std::string file_name){
    std::ofstream output(file_name);

    if (focus_blur){
        // Blur the rgb matrices based on their distance t_values
        std::cout << "Adding focus blur\n";
        apply_focus_blur();
    }

    if (anti_alias > 0){
        std::cout << "Anti-aliasing image\n";
        apply_anti_alias();
    }

    output << "P3" << "\n";
    output << orig_width << " " << orig_height << " 255" << "\n";
    int red, green, blue;
    for (int i=orig_height-1;i>=0; i--){
        for (int j=0; j<orig_width; j++){
            red = convert_255(red_pixels(j, i));
            green = convert_255(green_pixels(j, i));
            blue = convert_255(blue_pixels(j, i));
            output << red << " " << green << " " << blue << " ";
        }
        output << "\n";
    }
    output.close();
    std::cout << "Image saved at: " << file_name << "\n";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %r14
leaq 0x18(%rsp), %rdi
movq %rsi, (%rsp)
movl $0x10, %edx
callq 0x3510
cmpb $0x1, (%r14)
jne 0x3de5
movq 0x1c1fc(%rip), %rdi     # 0x1ffc8
leaq 0x1227d(%rip), %rsi     # 0x16050
movl $0x12, %edx
callq 0x32f0
movq %r14, %rdi
callq 0x40f6
cmpl $0x0, 0x4(%r14)
jle 0x3e0c
movq 0x1c1d5(%rip), %rdi     # 0x1ffc8
leaq 0x12269(%rip), %rsi     # 0x16063
movl $0x14, %edx
callq 0x32f0
movq %r14, %rdi
callq 0x42b2
leaq 0x12265(%rip), %rsi     # 0x16078
leaq 0x18(%rsp), %rdi
movl $0x2, %edx
callq 0x32f0
leaq 0x12e4a(%rip), %rsi     # 0x16c73
leaq 0x18(%rsp), %rdi
movl $0x1, %edx
callq 0x32f0
movl 0x8(%r14), %esi
leaq 0x18(%rsp), %rdi
callq 0x3490
movq %rax, %r15
leaq 0x13ffc(%rip), %rsi     # 0x17e4c
movl $0x1, %edx
movq %rax, %rdi
callq 0x32f0
movl 0xc(%r14), %esi
movq %r15, %rdi
callq 0x3490
movq %rax, %r15
leaq 0x12208(%rip), %rsi     # 0x1607b
movl $0x4, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x12dec(%rip), %rsi     # 0x16c73
movl $0x1, %edx
movq %r15, %rdi
callq 0x32f0
movl 0xc(%r14), %ebx
leaq -0x8(,%rbx,8), %r13
movsd 0x12188(%rip), %xmm2    # 0x16030
movsd 0x12188(%rip), %xmm3    # 0x16038
leaq 0x13f95(%rip), %r12     # 0x17e4c
testl %ebx, %ebx
jle 0x402a
cmpl $0x0, 0x8(%r14)
jle 0x3ff8
xorl %r15d, %r15d
movq 0x20(%r14), %rax
cmpq %r15, %rax
jle 0x40bb
cmpq %rbx, 0x28(%r14)
jl 0x40bb
imulq %r13, %rax
addq 0x18(%r14), %rax
movapd %xmm2, %xmm1
minsd (%rax,%r15,8), %xmm1
xorpd %xmm0, %xmm0
maxsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
movq 0x38(%r14), %rax
cmpq %r15, %rax
jle 0x40bb
cmpq %rbx, 0x40(%r14)
jl 0x40bb
imulq %r13, %rax
addq 0x30(%r14), %rax
movapd %xmm2, %xmm1
minsd (%rax,%r15,8), %xmm1
xorpd %xmm4, %xmm4
maxsd %xmm1, %xmm4
mulsd %xmm3, %xmm4
movsd %xmm4, 0x10(%rsp)
movq 0x50(%r14), %rax
cmpq %r15, %rax
jle 0x40bb
cmpq %rbx, 0x58(%r14)
jl 0x40bb
cvttsd2si %xmm0, %esi
imulq %r13, %rax
addq 0x48(%r14), %rax
movapd %xmm2, %xmm0
minsd (%rax,%r15,8), %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x3490
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x32f0
cvttsd2si 0x10(%rsp), %esi
movq %rbp, %rdi
callq 0x3490
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x32f0
cvttsd2si 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x3490
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x32f0
incq %r15
movslq 0x8(%r14), %rax
cmpq %rax, %r15
movsd 0x12046(%rip), %xmm2    # 0x16030
movsd 0x12046(%rip), %xmm3    # 0x16038
jl 0x3ecd
decq %rbx
addq $-0x8, %r13
movl $0x1, %edx
leaq 0x18(%rsp), %rdi
leaq 0x12c63(%rip), %rsi     # 0x16c73
callq 0x32f0
movsd 0x1201b(%rip), %xmm3    # 0x16038
movsd 0x1200b(%rip), %xmm2    # 0x16030
jmp 0x3eb7
leaq 0x18(%rsp), %rdi
callq 0x3380
movq 0x1bf8d(%rip), %rdi     # 0x1ffc8
leaq 0x1203e(%rip), %rsi     # 0x16080
movl $0x10, %edx
callq 0x32f0
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x1bf6a(%rip), %rdi     # 0x1ffc8
callq 0x32f0
leaq 0x12c09(%rip), %rsi     # 0x16c73
movl $0x1, %edx
movq %rax, %rdi
callq 0x32f0
movq 0x1bf3a(%rip), %rax     # 0x1ffb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x20(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x18(%rsp,%rcx)
callq 0x3260
leaq 0x110(%rsp), %rdi
callq 0x30e0
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x123d1(%rip), %rdi     # 0x16493
leaq 0x123ff(%rip), %rsi     # 0x164c8
leaq 0x12421(%rip), %rcx     # 0x164f1
movl $0x16d, %edx            # imm = 0x16D
callq 0x31a0
jmp 0x40e0
jmp 0x40e0
jmp 0x40e0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x33c0
movq %rbx, %rdi
callq 0x34b0
nop