// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/main.c
// Function: create_screenshot
bool create_screenshot(int canvasWidth, int canvasHeight,
                       struct Scene *scene,float aspectRatio,float yFov,
                       struct Ray **rayStacks,
                       struct KdTraverseNode **traverseStacks) {
  int canvasSize=canvasWidth*canvasHeight;

  float viewRot[9]={1.0f,0.0f,0.0f,
                    0.0f,1.0f,0.0f,
                    0.0f,0.0f, 1.0f};

  float viewPos[3]={2.0f,0.0f, 35.0f};
  // float viewPos[3]={0.0f,0.0f, 0.0f};

  sobol_state_t qrnd;
  sobol_init(&qrnd,2);

  float *canvas;
  canvas=(float*)malloc(sizeof(float)*canvasSize*3);

  //

  unsigned char *bitmap;
  bitmap=(unsigned char*)malloc(canvasSize*3);


  //
  createDir("output");
  int fileNum=lastFileNum("output")+1;
  printf("fn %i\n",fileNum);
  char fn[512];
  snprintf(fn,sizeof(fn),"output/output%04i.png",fileNum);

  if(access(fn, F_OK )!=-1) {
    fprintf(stderr,"'%s' already exists.\n",fn);
    return false;
  }
  renderScene(0,canvasSize,
              canvasWidth,canvasHeight,
              aspectRatio,yFov,
              scene->minBound,scene->maxBound,
              viewPos,
              viewRot,
              rayStacks[0],
              traverseStacks[0],
              scene->rootNode,
              scene->triangles,scene->trianglesNum,
              scene->spheres,scene->spheresNum,
              scene->pointLights, scene->pointLightsNum,

              &qrnd,

              canvas,
              RAY_MAX_BOUNCES,RAY_MAX_SPLITS);


  //
  int i;

  for(i=0;i<canvasSize;i++) {
    bitmap[i*3]=floatToByte(canvas[i*3]);
    bitmap[i*3+1]=floatToByte(canvas[i*3+1]);
    bitmap[i*3+2]=floatToByte(canvas[i*3+2]);
  }

  stbi_write_png(fn,canvasWidth,canvasHeight,3,bitmap,canvasWidth*3);

  printf("Wrote '%s'.\n",fn);
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16a8, %rsp           # imm = 0x16A8
movl %edi, -0x30(%rbp)
movl %esi, -0x34(%rbp)
movq %rdx, -0x40(%rbp)
movss %xmm0, -0x44(%rbp)
movss %xmm1, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movl -0x30(%rbp), %eax
imull -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x4010e0
movss 0xd8102(%rip), %xmm0    # 0x4e3484
movss %xmm0, -0x80(%rbp)
movss 0xd80f5(%rip), %xmm0    # 0x4e3484
movss %xmm0, -0x70(%rbp)
movss 0xd80e8(%rip), %xmm0    # 0x4e3484
movss %xmm0, -0x60(%rbp)
movq 0xd9808(%rip), %rax     # 0x4e4bb0
movq %rax, -0x8c(%rbp)
movl 0xd9803(%rip), %eax     # 0x4e4bb8
movl %eax, -0x84(%rbp)
leaq -0x1400(%rbp), %rdi
movl $0x2, %esi
callq 0x410b70
movslq -0x5c(%rbp), %rax
shlq $0x2, %rax
imulq $0x3, %rax, %rdi
callq 0x452d20
movq %rax, -0x1408(%rbp)
imull $0x3, -0x5c(%rbp), %eax
movslq %eax, %rdi
callq 0x452d20
movq %rax, -0x1410(%rbp)
leaq 0xd9572(%rip), %rdi     # 0x4e4970
callq 0x4245c0
leaq 0xd9566(%rip), %rdi     # 0x4e4970
callq 0x4245e0
addl $0x1, %eax
movl %eax, -0x1414(%rbp)
movl -0x1414(%rbp), %esi
leaq 0xd95e0(%rip), %rdi     # 0x4e4a05
movb $0x0, %al
callq 0x435930
leaq -0x1620(%rbp), %rdi
movl -0x1414(%rbp), %ecx
movl $0x200, %esi            # imm = 0x200
leaq 0xd95c7(%rip), %rdx     # 0x4e4a0c
movb $0x0, %al
callq 0x435a00
leaq -0x1620(%rbp), %rdi
xorl %esi, %esi
callq 0x48fbd0
cmpl $-0x1, %eax
je 0x40b487
movq $0x526c68, %rax         # imm = 0x526C68
movq (%rax), %rdi
leaq -0x1620(%rbp), %rdx
leaq 0xd9521(%rip), %rsi     # 0x4e4998
movb $0x0, %al
callq 0x435870
movb $0x0, -0x29(%rbp)
jmp 0x40b6ad
movl -0x5c(%rbp), %esi
movl -0x30(%rbp), %edx
movl -0x34(%rbp), %ecx
movss -0x44(%rbp), %xmm0
movss -0x48(%rbp), %xmm1
movq -0x40(%rbp), %r8
addq $0x34, %r8
movq -0x40(%rbp), %r9
addq $0x40, %r9
leaq -0x8c(%rbp), %rax
leaq -0x80(%rbp), %rdi
movq %rdi, -0x1650(%rbp)
movq -0x50(%rbp), %rdi
movq (%rdi), %rdi
movq %rdi, -0x1648(%rbp)
movq -0x58(%rbp), %rdi
movq (%rdi), %rdi
movq %rdi, -0x1640(%rbp)
movq -0x40(%rbp), %rdi
movq 0x28(%rdi), %rdi
movq %rdi, -0x1638(%rbp)
movq -0x40(%rbp), %rdi
movq (%rdi), %r13
movq -0x40(%rbp), %rdi
movl 0x18(%rdi), %r12d
movq -0x40(%rbp), %rdi
movq 0x8(%rdi), %r15
movq -0x40(%rbp), %rdi
movl 0x1c(%rdi), %r14d
movq -0x40(%rbp), %rdi
movq 0x10(%rdi), %rbx
movq -0x40(%rbp), %rdi
movl 0x20(%rdi), %r11d
movq -0x1408(%rbp), %rdi
movq %rdi, -0x1630(%rbp)
xorl %edi, %edi
leaq -0x1400(%rbp), %r10
movq %rax, (%rsp)
movq -0x1650(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x1648(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x1640(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x1638(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x1630(%rbp), %rax
movq %r13, 0x28(%rsp)
movl %r12d, 0x30(%rsp)
movq %r15, 0x38(%rsp)
movl %r14d, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movl %r11d, 0x50(%rsp)
movq %r10, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movl $0x1, 0x68(%rsp)
movl $0x8, 0x70(%rsp)
callq 0x4232c0
movl $0x0, -0x1624(%rbp)
movl -0x1624(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x40b671
movq -0x1408(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x424770
movb %al, %dl
movq -0x1410(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x1408(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x424770
movb %al, %dl
movq -0x1410(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x1408(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x424770
movb %al, %dl
movq -0x1410(%rbp), %rax
imull $0x3, -0x1624(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x1624(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1624(%rbp)
jmp 0x40b5af
leaq -0x1620(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movq -0x1410(%rbp), %r8
imull $0x3, -0x30(%rbp), %r9d
movl $0x3, %ecx
callq 0x420640
leaq -0x1620(%rbp), %rsi
leaq 0xd9356(%rip), %rdi     # 0x4e49f8
movb $0x0, %al
callq 0x435930
movb $0x1, -0x29(%rbp)
movb -0x29(%rbp), %al
andb $0x1, %al
addq $0x16a8, %rsp           # imm = 0x16A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)