// File: /workspace/github_cpp_makefile_star2_O3/daltonbr[P]RayTracing/./src/main.cpp
// Function: main
int main()
{
    // const char* inputFileName = (const char*)"foo.png";//"chapter5b.ppm";
    // const char* outputFileName = (const char*)"foo.out.png";
    // generate_png(inputFileName, outputFileName);

    int nx = 2000;
    int ny = 1000;
    int ns = 1000;
    std::cout << "P3\n" << nx << " " << ny << "\n255\n";

    hitable *list[5];
    list[0] = new sphere(vec3(0, 0, -1), 0.5, new lambertian(vec3(0.5, 0.0, 1.0)));
    list[1] = new sphere(vec3(0.75, -0.25, -1.5), 0.25, new lambertian(vec3(0.1, 0.7, 0.3)));
    // A giant sphere to act as a ground (or a planet)
    
    list[2] = new sphere(vec3(0, -100.5, -1), 100, new lambertian(vec3(0.8, 0.6, 0.2)));
    list[3] = new sphere(vec3(1, 0, -1), 0.5, new metal(vec3(0.8, 0.6, 0.2), 0.3));
    list[4] = new sphere(vec3(-1, 0, -1), 0.5, new metal(vec3(0.8, 0.8, 0.8), 0.8));
    // rose gold sphere
    //list[5] = new sphere(vec3(-0.25, -0.125, -0.25), 0.125, new metal(vec3(0.718, 0.431, 0.475)));
    hitable *world = new hitable_list(list, 5);

    camera cam;

    for (int j = ny - 1; j >= 0; j--)
    {
        for (int i = 0; i < nx; i++)
        {
            vec3 col = vec3(0, 0, 0);
            for (int s = 0; s < ns; s++)
            {
                float u = float(i + drand48()) / float(nx);
                float v = float(j + drand48()) / float(ny);
                ray r = cam.get_ray(u, v);
                vec3 p = r.point_at_parameter(2.0);
                col += color(r, world, 0);
            }
            col /= float(ns);
            col = vec3( sqrt(col[0]), sqrt(col[1]), sqrt(col[2]) );
            int ir = int (255.99 * col[0]);
            int ig = int (255.99 * col[1]);
            int ib = int (255.99 * col[2]);
            
            std::cout << ir << " " << ig << " " << ib << "\n";
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x17021(%rip), %rbx     # 0x1dfd8
leaq 0x123d3(%rip), %rsi     # 0x19391
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2100
movq %rbx, %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x21c0
movq %rax, %rbx
leaq 0x12c53(%rip), %rsi     # 0x19c35
movl $0x1, %edx
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x21c0
leaq 0x12392(%rip), %rsi     # 0x19395
movl $0x5, %edx
movq %rax, %rdi
callq 0x2100
movl $0x20, %edi
callq 0x20c0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20c0
leaq 0x16d2a(%rip), %r12     # 0x1dd58
movq %r12, (%rax)
movq $0x3f000000, 0x8(%rax)  # imm = 0x3F000000
movl $0x3f800000, 0x10(%rax) # imm = 0x3F800000
leaq 0x16c89(%rip), %r14     # 0x1dcd0
movq %r14, (%rbx)
movq $0x0, 0x8(%rbx)
movabsq $0x3f000000bf800000, %r15 # imm = 0x3F000000BF800000
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x90(%rbp)
movl $0x20, %edi
callq 0x20c0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20c0
movq %r12, (%rax)
movabsq $0x3f3333333dcccccd, %rcx # imm = 0x3F3333333DCCCCCD
movq %rcx, 0x8(%rax)
movl $0x3e99999a, 0x10(%rax) # imm = 0x3E99999A
movq %r14, (%rbx)
movsd 0xfffb(%rip), %xmm0     # 0x170a0
movsd %xmm0, 0x8(%rbx)
movabsq $0x3e800000bfc00000, %rcx # imm = 0x3E800000BFC00000
movq %rcx, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x88(%rbp)
movl $0x20, %edi
callq 0x20c0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20c0
movq %r12, (%rax)
movabsq $0x3f19999a3f4ccccd, %rcx # imm = 0x3F19999A3F4CCCCD
movq %rcx, 0x8(%rax)
movl $0x3e4ccccd, 0x10(%rax) # imm = 0x3E4CCCCD
movq %r14, (%rbx)
movsd 0xffb3(%rip), %xmm0     # 0x170b0
movsd %xmm0, 0x8(%rbx)
movabsq $0x42c80000bf800000, %rcx # imm = 0x42C80000BF800000
movq %rcx, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x80(%rbp)
movl $0x20, %edi
callq 0x20c0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20c0
leaq 0x16c62(%rip), %r12     # 0x1dd98
movq %r12, (%rax)
movaps 0xff80(%rip), %xmm0     # 0x170c0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0xfeb9(%rip), %xmm0     # 0x17008
movlps %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x78(%rbp)
movl $0x20, %edi
callq 0x20c0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20c0
movq %r12, (%rax)
movaps 0xff50(%rip), %xmm0     # 0x170d0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0xfe75(%rip), %xmm0     # 0x17004
movlpd %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
leaq -0x90(%rbp), %r14
movq %rbx, 0x20(%r14)
movl $0x18, %edi
callq 0x20c0
movq %rax, %rbx
leaq 0x16b45(%rip), %rax     # 0x1dd00
movq %rax, (%rbx)
movq %r14, 0x8(%rbx)
movl $0x5, 0x10(%rbx)
movl $0x3e7, %eax            # imm = 0x3E7
leaq -0x68(%rbp), %r14
movl %eax, -0x38(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x50(%rbp)
xorpd %xmm0, %xmm0
xorl %r13d, %r13d
movsd %xmm0, -0x48(%rbp)
xorps %xmm3, %xmm3
movl $0x3e8, %r15d           # imm = 0x3E8
xorps %xmm2, %xmm2
xorps %xmm1, %xmm1
movss %xmm3, -0x34(%rbp)
movss %xmm2, -0x30(%rbp)
movss %xmm1, -0x2c(%rbp)
callq 0x20a0
addsd -0x48(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0xfe27(%rip), %xmm0     # 0x17048
movss %xmm0, -0x3c(%rbp)
callq 0x20a0
addsd -0x50(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0xfe10(%rip), %xmm0     # 0x1704c
movss -0x3c(%rbp), %xmm2
movaps %xmm2, %xmm1
mulss 0xfe04(%rip), %xmm1     # 0x17050
xorps %xmm3, %xmm3
mulss %xmm3, %xmm2
addss 0xfdf9(%rip), %xmm1     # 0x17054
addss 0xfda1(%rip), %xmm2     # 0x17004
movaps %xmm2, %xmm4
movaps %xmm0, %xmm2
mulss %xmm3, %xmm2
addss %xmm0, %xmm0
addss %xmm2, %xmm1
addss %xmm4, %xmm0
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
addss %xmm4, %xmm2
movq $0x0, -0x68(%rbp)
movl $0x0, -0x60(%rbp)
movlps %xmm1, -0x5c(%rbp)
movss %xmm2, -0x54(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6e72
movss -0x34(%rbp), %xmm3
movss -0x30(%rbp), %xmm2
addss %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
addss %xmm0, %xmm2
movss -0x2c(%rbp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x2c(%rbp), %xmm1
decl %r15d
jne 0x71fc
mulss 0xfd5d(%rip), %xmm3     # 0x1703c
ucomiss 0xfd72(%rip), %xmm3     # 0x17058
xorps %xmm1, %xmm1
jb 0x72f9
xorps %xmm0, %xmm0
sqrtss %xmm3, %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x7313
movaps %xmm3, %xmm0
movss %xmm2, -0x30(%rbp)
callq 0x21e0
movss -0x30(%rbp), %xmm2
movss %xmm0, -0x34(%rbp)
xorps %xmm1, %xmm1
mulss 0xfd21(%rip), %xmm2     # 0x1703c
ucomiss %xmm1, %xmm2
jb 0x7329
xorps %xmm3, %xmm3
sqrtss %xmm2, %xmm3
jmp 0x7337
movaps %xmm2, %xmm0
callq 0x21e0
movaps %xmm0, %xmm3
xorps %xmm1, %xmm1
movss -0x2c(%rbp), %xmm0
mulss 0xfcf8(%rip), %xmm0     # 0x1703c
ucomiss %xmm1, %xmm0
jb 0x734f
sqrtss %xmm0, %xmm0
jmp 0x735e
movss %xmm3, -0x2c(%rbp)
callq 0x21e0
movss -0x2c(%rbp), %xmm3
xorps %xmm1, %xmm1
cvtss2sd -0x34(%rbp), %xmm1
movsd 0x11f0a(%rip), %xmm2    # 0x19278
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, -0x30(%rbp)
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movq 0x16c3a(%rip), %rdi     # 0x1dfd8
callq 0x21c0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x12880(%rip), %r15     # 0x19c35
movq %r15, %rsi
callq 0x2100
movq %r12, %rdi
movl -0x30(%rbp), %esi
callq 0x21c0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2100
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x21c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f9e(%rip), %rsi     # 0x19393
callq 0x2100
movsd -0x48(%rbp), %xmm0
addsd 0x11e61(%rip), %xmm0    # 0x19268
incl %r13d
cmpl $0x7d0, %r13d           # imm = 0x7D0
jne 0x71e8
movl -0x38(%rbp), %eax
subl $0x1, %eax
jae 0x71d2
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x743c
jmp 0x743c
jmp 0x743c
jmp 0x743c
movq %rax, %r14
movl $0x20, %esi
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x21d0