// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq 0x116d7(%rip), %rdi     # 0x17fd8
leaq 0xca91(%rip), %rsi      # 0x13399
callq 0x20b0
movq %rax, %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x21c0
leaq 0xd31c(%rip), %rsi      # 0x13c3d
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x21c0
leaq 0xca60(%rip), %rsi      # 0x1339d
movq %rax, %rdi
callq 0x20b0
pushq $0x20
popq %rdi
callq 0x20d0
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x20d0
leaq 0x113f9(%rip), %r12     # 0x17d58
movq %r12, (%rax)
movq $0x3f000000, 0x8(%rax)  # imm = 0x3F000000
movl $0x3f800000, 0x10(%rax) # imm = 0x3F800000
leaq 0x11370(%rip), %r14     # 0x17ce8
movq %r14, (%rbx)
andq $0x0, 0x8(%rbx)
movabsq $0x3f000000bf800000, %r15 # imm = 0x3F000000BF800000
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x80(%rbp)
pushq $0x20
popq %rdi
callq 0x20d0
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x20d0
movq %r12, (%rax)
movabsq $0x3f3333333dcccccd, %rcx # imm = 0x3F3333333DCCCCCD
movq %rcx, 0x8(%rax)
movl $0x3e99999a, 0x10(%rax) # imm = 0x3E99999A
movq %r14, (%rbx)
movsd 0xa6c4(%rip), %xmm0     # 0x11090
movsd %xmm0, 0x8(%rbx)
movabsq $0x3e800000bfc00000, %rcx # imm = 0x3E800000BFC00000
movq %rcx, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x78(%rbp)
pushq $0x20
popq %rdi
callq 0x20d0
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x20d0
movq %r12, (%rax)
movabsq $0x3f19999a3f4ccccd, %rcx # imm = 0x3F19999A3F4CCCCD
movq %rcx, 0x8(%rax)
movl $0x3e4ccccd, 0x10(%rax) # imm = 0x3E4CCCCD
movq %r14, (%rbx)
movsd 0xa683(%rip), %xmm0     # 0x110a0
movsd %xmm0, 0x8(%rbx)
movabsq $0x42c80000bf800000, %rcx # imm = 0x42C80000BF800000
movq %rcx, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x70(%rbp)
pushq $0x20
popq %rdi
callq 0x20d0
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x20d0
leaq 0x11346(%rip), %r12     # 0x17d98
movq %r12, (%rax)
movaps 0xa654(%rip), %xmm0     # 0x110b0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0xa59d(%rip), %xmm0     # 0x11008
movlps %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rbx, -0x68(%rbp)
pushq $0x20
popq %rdi
callq 0x20d0
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x20d0
movq %r12, (%rax)
movaps 0xa628(%rip), %xmm0     # 0x110c0
movups %xmm0, 0x8(%rax)
movq %r14, (%rbx)
movss 0xa55d(%rip), %xmm0     # 0x11004
movlps %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
leaq -0x80(%rbp), %r14
movq %rbx, 0x20(%r14)
pushq $0x18
popq %rdi
callq 0x20d0
movq %rax, %rbx
leaq 0x1124b(%rip), %rax     # 0x17d18
movq %rax, (%rbx)
movq %r14, 0x8(%rbx)
movl $0x5, 0x10(%rbx)
movaps 0xa5ee(%rip), %xmm0     # 0x110d0
leaq -0xc8(%rbp), %r14
movups %xmm0, 0x10(%r14)
movaps 0xa5eb(%rip), %xmm0     # 0x110e0
movups %xmm0, 0x20(%r14)
movapd 0xa5ee(%rip), %xmm0     # 0x110f0
movupd %xmm0, (%r14)
movl $0x3e7, %eax            # imm = 0x3E7
leaq -0x98(%rbp), %r15
testl %eax, %eax
js 0x6d07
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x58(%rbp)
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl %eax, -0x44(%rbp)
cmpl $0x7d0, %ecx            # imm = 0x7D0
je 0x6d00
movl %ecx, -0x48(%rbp)
xorpd %xmm0, %xmm0
movl $0x3e8, %r12d           # imm = 0x3E8
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
subl $0x1, %r12d
movss %xmm0, -0x2c(%rbp)
movss %xmm2, -0x34(%rbp)
jb 0x6bec
movss %xmm3, -0x30(%rbp)
callq 0x20a0
addsd -0x40(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0xa4c4(%rip), %xmm0     # 0x11044
movss %xmm0, -0x4c(%rbp)
callq 0x20a0
addsd -0x58(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm1
divss 0xa4ad(%rip), %xmm1     # 0x11048
movq %r15, %rdi
movq %r14, %rsi
movss -0x4c(%rbp), %xmm0
callq 0x10ab4
movq %r15, %rdi
movss 0xa496(%rip), %xmm0     # 0x1104c
callq 0x10a5e
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x67df
movss -0x30(%rbp), %xmm3
movss -0x34(%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
jmp 0x6b51
mulss 0xa444(%rip), %xmm3     # 0x11038
ucomiss 0xa411(%rip), %xmm3     # 0x1100c
jb 0x6c03
sqrtss %xmm3, %xmm0
jmp 0x6c10
movaps %xmm3, %xmm0
callq 0x21e0
movss -0x34(%rbp), %xmm2
movss %xmm0, -0x30(%rbp)
mulss 0xa41b(%rip), %xmm2     # 0x11038
ucomiss 0xa3e8(%rip), %xmm2     # 0x1100c
jb 0x6c2c
sqrtss %xmm2, %xmm3
jmp 0x6c37
movaps %xmm2, %xmm0
callq 0x21e0
movaps %xmm0, %xmm3
movss -0x2c(%rbp), %xmm0
mulss 0xa3f4(%rip), %xmm0     # 0x11038
ucomiss 0xa3c1(%rip), %xmm0     # 0x1100c
jb 0x6c53
sqrtss %xmm0, %xmm0
jmp 0x6c62
movss %xmm3, -0x2c(%rbp)
callq 0x21e0
movss -0x2c(%rbp), %xmm3
cvtss2sd -0x30(%rbp), %xmm1
movsd 0xc611(%rip), %xmm2     # 0x13280
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
cvtss2sd %xmm3, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r13d
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movq 0x1133e(%rip), %rdi     # 0x17fd8
callq 0x21c0
movq %rax, %rdi
leaq 0xcf94(%rip), %r12      # 0x13c3d
movq %r12, %rsi
callq 0x20b0
movq %rax, %rdi
movl %r13d, %esi
callq 0x21c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x20b0
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x21c0
movq %rax, %rdi
leaq 0xc6bf(%rip), %rsi      # 0x1339b
callq 0x20b0
movsd -0x40(%rbp), %xmm0
addsd 0xc582(%rip), %xmm0     # 0x13270
movsd %xmm0, -0x40(%rbp)
movl -0x48(%rbp), %ecx
incl %ecx
movl -0x44(%rbp), %eax
jmp 0x6b32
decl %eax
jmp 0x6b13
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6d23
jmp 0x6d23
jmp 0x6d23
jmp 0x6d23
movq %rax, %r14
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x21d0