// File: /workspace/github_cpp_makefile_star2_O1/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 0x1812f(%rip), %rbx     # 0x1efd8
leaq 0x134e9(%rip), %rsi     # 0x1a399
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2110
movq %rbx, %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x21d0
movq %rax, %rbx
leaq 0x13d85(%rip), %rsi     # 0x1ac59
movl $0x1, %edx
movq %rax, %rdi
callq 0x2110
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x21d0
leaq 0x134a8(%rip), %rsi     # 0x1a39d
movl $0x5, %edx
movq %rax, %rdi
callq 0x2110
movl $0x20, %edi
callq 0x20d0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20d0
leaq 0x17e38(%rip), %r12     # 0x1ed58
movq %r12, (%rax)
movq $0x3f000000, 0x8(%rax)  # imm = 0x3F000000
movl $0x3f800000, 0x10(%rax) # imm = 0x3F800000
leaq 0x17daf(%rip), %r14     # 0x1ece8
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 0x20d0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20d0
movq %r12, (%rax)
movabsq $0x3f3333333dcccccd, %rcx # imm = 0x3F3333333DCCCCCD
movq %rcx, 0x8(%rax)
movl $0x3e99999a, 0x10(%rax) # imm = 0x3E99999A
movq %r14, (%rbx)
movsd 0x11109(%rip), %xmm0    # 0x180a0
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 0x20d0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20d0
movq %r12, (%rax)
movabsq $0x3f19999a3f4ccccd, %rcx # imm = 0x3F19999A3F4CCCCD
movq %rcx, 0x8(%rax)
movl $0x3e4ccccd, 0x10(%rax) # imm = 0x3E4CCCCD
movq %r14, (%rbx)
movsd 0x110c1(%rip), %xmm0    # 0x180b0
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 0x20d0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20d0
leaq 0x17d70(%rip), %r12     # 0x1ed98
movq %r12, (%rax)
movaps 0x1108e(%rip), %xmm0    # 0x180c0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0x10fc7(%rip), %xmm0    # 0x18008
movlps %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x78(%rbp)
movl $0x20, %edi
callq 0x20d0
movq %rax, %rbx
movl $0x18, %edi
callq 0x20d0
movq %r12, (%rax)
movaps 0x1105e(%rip), %xmm0    # 0x180d0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0x10f83(%rip), %xmm0    # 0x18004
movlpd %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
leaq -0x90(%rbp), %r14
movq %rbx, 0x20(%r14)
movl $0x18, %edi
callq 0x20d0
movq %rax, %rbx
leaq 0x17c6b(%rip), %rax     # 0x1ed18
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 0x20b0
addsd -0x48(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0x10f35(%rip), %xmm0    # 0x18048
movss %xmm0, -0x3c(%rbp)
callq 0x20b0
addsd -0x50(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0x10f1e(%rip), %xmm0    # 0x1804c
movss -0x3c(%rbp), %xmm2
movaps %xmm2, %xmm1
mulss 0x10f12(%rip), %xmm1    # 0x18050
xorps %xmm3, %xmm3
mulss %xmm3, %xmm2
addss 0x10f07(%rip), %xmm1    # 0x18054
addss 0x10eaf(%rip), %xmm2    # 0x18004
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 0x6d50
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 0x70ee
mulss 0x10e6b(%rip), %xmm3    # 0x1803c
ucomiss 0x10e80(%rip), %xmm3    # 0x18058
xorps %xmm1, %xmm1
jb 0x71eb
xorps %xmm0, %xmm0
sqrtss %xmm3, %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x7205
movaps %xmm3, %xmm0
movss %xmm2, -0x30(%rbp)
callq 0x21f0
movss -0x30(%rbp), %xmm2
movss %xmm0, -0x34(%rbp)
xorps %xmm1, %xmm1
mulss 0x10e2f(%rip), %xmm2    # 0x1803c
ucomiss %xmm1, %xmm2
jb 0x721b
xorps %xmm3, %xmm3
sqrtss %xmm2, %xmm3
jmp 0x7229
movaps %xmm2, %xmm0
callq 0x21f0
movaps %xmm0, %xmm3
xorps %xmm1, %xmm1
movss -0x2c(%rbp), %xmm0
mulss 0x10e06(%rip), %xmm0    # 0x1803c
ucomiss %xmm1, %xmm0
jb 0x7241
sqrtss %xmm0, %xmm0
jmp 0x7250
movss %xmm3, -0x2c(%rbp)
callq 0x21f0
movss -0x2c(%rbp), %xmm3
xorps %xmm1, %xmm1
cvtss2sd -0x34(%rbp), %xmm1
movsd 0x13020(%rip), %xmm2    # 0x1a280
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 0x17d48(%rip), %rdi     # 0x1efd8
callq 0x21d0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x139b2(%rip), %r15     # 0x1ac59
movq %r15, %rsi
callq 0x2110
movq %r12, %rdi
movl -0x30(%rbp), %esi
callq 0x21d0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2110
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x21d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x130b4(%rip), %rsi     # 0x1a39b
callq 0x2110
movsd -0x48(%rbp), %xmm0
addsd 0x12f77(%rip), %xmm0    # 0x1a270
incl %r13d
cmpl $0x7d0, %r13d           # imm = 0x7D0
jne 0x70da
movl -0x38(%rbp), %eax
subl $0x1, %eax
jae 0x70c4
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x732e
jmp 0x732e
jmp 0x732e
jmp 0x732e
movq %rax, %r14
movl $0x20, %esi
movq %rbx, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x21e0