// File: srajangarg[P]raytracer/src/main.cpp
// Function: main
int
main(int argc, char ** argv)
{
  if (argc < 3)
  {
    std::cout << "Usage: " << argv[0] << " scene.scd output.png [max_trace_depth]" << std::endl;
    return -1;
  }

  if (argc >= 4)
    max_trace_depth = atoi(argv[3]);
  if (argc >= 5)
    smooth_normals = (atoi(argv[4]) == 1);

  cout << "Max trace depth = " << max_trace_depth << endl;
  if (smooth_normals)
    cout << "Using smooth normals for triangle meshes" << endl;

  // Load the scene from the disk file
  scene = new Scene(argv[1]);

  // Setup the world object, containing the data from the scene
  world = new World();
  importSceneToWorld(scene->getRoot(), identity3D(), 0);
  world->printStats();

  // Set up the output framebuffer
  frame = new Frame(IMAGE_WIDTH, IMAGE_HEIGHT);

  // Render the world
  renderWithRaytracing();

  // Save the output to an image file
  frame->save(argv[2]);
  std::cout << "Image saved!" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x4296b
movq 0x196a2(%rip), %rdi     # 0x5bfc8
leaq 0x64fe(%rip), %rsi      # 0x48e2b
callq 0x53e0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x53e0
movq %rax, %rdi
leaq 0x64e8(%rip), %rsi      # 0x48e33
callq 0x53e0
movq %rax, %rdi
movq 0x19656(%rip), %rsi     # 0x5bfb0
callq 0x5440
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42bc9
cmpl $0x4, -0x8(%rbp)
jl 0x42984
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x5620
movl %eax, 0x1a2cc(%rip)     # 0x5cc50
cmpl $0x5, -0x8(%rbp)
jl 0x429a5
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x5620
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movb %al, 0x1a4eb(%rip)      # 0x5ce90
movq 0x1961c(%rip), %rdi     # 0x5bfc8
leaq 0x64a8(%rip), %rsi      # 0x48e5b
callq 0x53e0
movq %rax, %rdi
movl 0x1a28f(%rip), %esi     # 0x5cc50
callq 0x56f0
movq %rax, %rdi
movq 0x195e0(%rip), %rsi     # 0x5bfb0
callq 0x5440
testb $0x1, 0x1a4b4(%rip)     # 0x5ce90
je 0x42a00
movq 0x195e3(%rip), %rdi     # 0x5bfc8
leaq 0x6482(%rip), %rsi      # 0x48e6e
callq 0x53e0
movq %rax, %rdi
movq 0x195b5(%rip), %rsi     # 0x5bfb0
callq 0x5440
movl $0x10, %edi
callq 0x5400
movq %rax, -0x108(%rbp)
movb $0x1, -0x45(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x100(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x5730
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x13590
jmp 0x42a4d
movq -0x108(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x8560
jmp 0x42a5f
movq -0x108(%rbp), %rax
movb $0x0, -0x45(%rbp)
movq %rax, 0x1a37f(%rip)     # 0x5cdf0
leaq -0x30(%rbp), %rdi
callq 0x5290
leaq -0x31(%rbp), %rdi
callq 0x5460
movl $0x70, %edi
callq 0x5400
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x110(%rbp)
callq 0x3f4a0
jmp 0x42aa1
movq -0x110(%rbp), %rax
movq %rax, 0x1a349(%rip)     # 0x5cdf8
movq 0x1a33a(%rip), %rdi     # 0x5cdf0
callq 0x8680
movq %rax, -0x128(%rbp)
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x9f60
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
xorl %edx, %edx
callq 0x41a10
movq 0x1a307(%rip), %rdi     # 0x5cdf8
callq 0x3f700
movl $0x20, %edi
callq 0x5400
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x118(%rbp)
movl $0x200, %edx            # imm = 0x200
movl %edx, %esi
callq 0x3aba0
jmp 0x42b1b
movq -0x118(%rbp), %rax
movq %rax, 0x1a35f(%rip)     # 0x5ce88
callq 0x41850
movq 0x1a353(%rip), %rax     # 0x5ce88
movq %rax, -0x140(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x138(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x5730
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x13590
jmp 0x42b7a
movq -0x140(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3ad70
jmp 0x42b8f
leaq -0xe8(%rbp), %rdi
callq 0x5290
leaq -0xe9(%rbp), %rdi
callq 0x5460
movq 0x1941a(%rip), %rdi     # 0x5bfc8
leaq 0x62e2(%rip), %rsi      # 0x48e97
callq 0x53e0
movq %rax, %rdi
movq 0x193ec(%rip), %rsi     # 0x5bfb0
callq 0x5440
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x42bf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5290
leaq -0x31(%rbp), %rdi
callq 0x5460
testb $0x1, -0x45(%rbp)
jne 0x42c09
jmp 0x42c1a
movq -0x108(%rbp), %rdi
movl $0x10, %esi
callq 0x5410
jmp 0x42c8c
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x70, %esi
callq 0x5410
jmp 0x42c8c
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x20, %esi
callq 0x5410
jmp 0x42c8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x42c80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x5290
leaq -0xe9(%rbp), %rdi
callq 0x5460
movq -0x40(%rbp), %rdi
callq 0x5720
nopw %cs:(%rax,%rax)
nop