// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/main.c
// Function: main
int main(int argc, char *argv[]) {
  double startTime;
  startTime=timer();

  int canvasWidth=1280;
  int canvasHeight=720;

  int i;

#ifdef __EMSCRIPTEN__

  canvasWidth=640;
  canvasHeight=480;
#else

  char mode='p';


  for(i=1;i<argc;i++) {
    if(argv[i][0]=='-' && argv[i][1]=='m' &&
       (argv[i][2]=='v' || argv[i][2]=='p' || argv[i][2]=='g')
       && argv[i][3]==0) {
      mode=argv[i][2];
    } else if(argv[i][0]=='-' && argv[i][1]=='w') {
      canvasWidth=atoi(&argv[i][2]);
    } else if(argv[i][0]=='-' && argv[i][1]=='h') {
      canvasHeight=atoi(&argv[i][2]);
    } else {
      //err
    }
  }
#endif
  int canvasSize=canvasWidth*canvasHeight;




  float aspectRatio=(float)canvasWidth/(float)canvasHeight;
  float yFov=(float)M_PI_4;


  struct Scene scene;

  if(!initScene(&scene)) {
#ifdef _MSC_VER
  system("pause");
#endif

    return 1;
  }


  //

  struct Ray **rayStacks;
  struct KdTraverseNode **traverseStacks;

  rayStacks=(struct Ray**)malloc(sizeof(void*)*(WORKER_THREADS+1));
  traverseStacks=(struct KdTraverseNode**)malloc(sizeof(void*)*(WORKER_THREADS+1));

  for(i=0;i<WORKER_THREADS+1;i++) {
    traverseStacks[i]=(struct KdTraverseNode*)
      malloc(sizeof(struct KdTraverseNode)*scene.kdtreeDepth);
    rayStacks[i]=(struct Ray*)malloc(sizeof(struct Ray)*RAY_MAX_DEPTH);
  }



  //
  printf("Init took %g seconds.\n",timer()-startTime);
  startTime=timer();


#ifdef __EMSCRIPTEN__
  struct EmData emData;
 emData.canvasWidth=canvasWidth;
 emData.canvasHeight=canvasHeight;
 emData.aspectRatio=aspectRatio;
 emData.yFov=yFov;
 emData.traverseStacks=traverseStacks;
 emData.rayStacks=rayStacks;
 emData.pixelIndex=0;
 emData.scene=&scene;
 emscripten_set_canvas_size(canvasWidth,canvasHeight);
 em_canvas_paint_init(canvasWidth,canvasHeight);

 emscripten_set_main_loop_arg(em_main_loop,&emData,0,1);
#else
 //
 if(mode=='v') {
   printf("generating video.\n");
   create_video(canvasWidth,canvasHeight,&scene,aspectRatio,yFov,
                rayStacks,traverseStacks
                );
 } else if(mode=='p') {
   printf("generating picture.\n");
   create_screenshot(canvasWidth,canvasHeight,&scene,aspectRatio,yFov,
                     rayStacks,traverseStacks
                     );
 } else if(mode=='b') {
   printf("generating picture (bi directional lighting test).\n");
   create_screenshot2(canvasWidth,canvasHeight,&scene,aspectRatio,yFov,
                     rayStacks,traverseStacks
                     );
 } else if(mode=='g') {
   printf("generating gbuffer.\n");
   create_gbuffer(canvasWidth,canvasHeight,&scene,aspectRatio,yFov,
                  rayStacks,traverseStacks);
 }

#endif

 printf("Output took %g seconds.\n",timer()-startTime);



#ifdef _MSC_VER
  system("pause");
#endif
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, %al
callq 0x420bd0
movsd %xmm0, -0x18(%rbp)
movl $0x500, -0x1c(%rbp)     # imm = 0x500
movl $0x2d0, -0x20(%rbp)     # imm = 0x2D0
movb $0x70, -0x25(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x40c5de
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x40c542
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x6d, %eax
jne 0x40c542
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x76, %eax
je 0x40c516
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x70, %eax
je 0x40c516
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x67, %eax
jne 0x40c542
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x3(%rax), %eax
cmpl $0x0, %eax
jne 0x40c542
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb 0x2(%rax), %al
movb %al, -0x25(%rbp)
jmp 0x40c5ce
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x40c585
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x77, %eax
jne 0x40c585
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x2, %rdi
callq 0x433b90
movl %eax, -0x1c(%rbp)
jmp 0x40c5cc
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x40c5c8
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x68, %eax
jne 0x40c5c8
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x2, %rdi
callq 0x433b90
movl %eax, -0x20(%rbp)
jmp 0x40c5ca
jmp 0x40c5ca
jmp 0x40c5cc
jmp 0x40c5ce
jmp 0x40c5d0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x40c49e
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
cvtsi2ssl -0x1c(%rbp), %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x30(%rbp)
movss 0xd8361(%rip), %xmm0    # 0x4e4964
movss %xmm0, -0x34(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x40c0d0
testb $0x1, %al
jne 0x40c624
movl $0x1, -0x4(%rbp)
jmp 0x40c7f6
movl $0x8, %edi
callq 0x452d20
movq %rax, -0x90(%rbp)
movl $0x8, %edi
callq 0x452d20
movq %rax, -0x98(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jge 0x40c699
movslq -0x58(%rbp), %rdi
shlq $0x4, %rdi
callq 0x452d20
movq %rax, %rdx
movq -0x98(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x100, %edi            # imm = 0x100
callq 0x452d20
movq %rax, %rdx
movq -0x90(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x40c64d
movb $0x0, %al
callq 0x420bd0
subsd -0x18(%rbp), %xmm0
leaq 0xd83f5(%rip), %rdi     # 0x4e4aa1
movb $0x1, %al
callq 0x435930
movb $0x0, %al
callq 0x420bd0
movsd %xmm0, -0x18(%rbp)
movsbl -0x25(%rbp), %eax
cmpl $0x76, %eax
jne 0x40c705
leaq 0xd83e9(%rip), %rdi     # 0x4e4ab8
movb $0x0, %al
callq 0x435930
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %r8
leaq -0x88(%rbp), %rdx
callq 0x40acd0
jmp 0x40c7d5
movsbl -0x25(%rbp), %eax
cmpl $0x70, %eax
jne 0x40c74b
leaq 0xd83b6(%rip), %rdi     # 0x4e4acb
movb $0x0, %al
callq 0x435930
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %r8
leaq -0x88(%rbp), %rdx
callq 0x40b330
jmp 0x40c7d3
movsbl -0x25(%rbp), %eax
cmpl $0x62, %eax
jne 0x40c78e
leaq 0xd8385(%rip), %rdi     # 0x4e4ae0
movb $0x0, %al
callq 0x435930
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %r8
leaq -0x88(%rbp), %rdx
callq 0x40b6d0
jmp 0x40c7d1
movsbl -0x25(%rbp), %eax
cmpl $0x67, %eax
jne 0x40c7cf
leaq 0xd8376(%rip), %rdi     # 0x4e4b14
movb $0x0, %al
callq 0x435930
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %r8
leaq -0x88(%rbp), %rdx
callq 0x40ba70
jmp 0x40c7d1
jmp 0x40c7d3
jmp 0x40c7d5
movb $0x0, %al
callq 0x420bd0
subsd -0x18(%rbp), %xmm0
leaq 0xd8341(%rip), %rdi     # 0x4e4b29
movb $0x1, %al
callq 0x435930
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)