// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x15e8, %rsp           # imm = 0x15E8
movq %r8, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movss %xmm1, 0x14(%rsp)
movss %xmm0, 0x10(%rsp)
movq %rdx, %rbp
movl %esi, %r13d
movl %esi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
imull %edi, %r13d
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, 0x40(%rsp)
movl %eax, 0x50(%rsp)
movl %eax, 0x60(%rsp)
movl $0x420c0000, 0x38(%rsp) # imm = 0x420C0000
movq $0x40000000, 0x30(%rsp) # imm = 0x40000000
leaq 0x278(%rsp), %rdi
movl $0x2, %esi
callq 0x409f0c
movslq %r13d, %rbx
leaq (,%rbx,4), %rax
leaq (%rax,%rax,2), %rdi
callq 0x4449d0
movq %rax, %r12
leal (%rbx,%rbx,2), %eax
movslq %eax, %rdi
callq 0x4449d0
movq %rax, %r15
leaq 0xd00e8(%rip), %rbx     # 0x4d69d0
movq %rbx, %rdi
callq 0x4165da
movq %rbx, %rdi
callq 0x4165e4
leal 0x1(%rax), %ebx
leaq 0xd015f(%rip), %rdi     # 0x4d6a61
movl %ebx, %esi
xorl %eax, %eax
callq 0x427440
leaq 0xd0156(%rip), %rdx     # 0x4d6a68
leaq 0x70(%rsp), %r14
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x427510
movq %r14, %rdi
xorl %esi, %esi
callq 0x481890
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x406a5c
movl %ebx, 0xc(%rsp)
leaq 0x34(%rbp), %r8
leaq 0x40(%rbp), %r9
movl 0x18(%rbp), %r11d
movl 0x1c(%rbp), %ebx
movl 0x20(%rbp), %r14d
subq $0x8, %rsp
leaq 0x48(%rsp), %r10
xorl %edi, %edi
movl %r13d, %esi
movq 0x20(%rsp), %rdx
movl 0x10(%rsp), %ecx
movss 0x18(%rsp), %xmm0
movss 0x1c(%rsp), %xmm1
pushq $0x8
pushq $0x1
pushq %r12
leaq 0x298(%rsp), %rax
pushq %rax
pushq %r14
pushq 0x10(%rbp)
pushq %rbx
pushq 0x8(%rbp)
pushq %r11
pushq (%rbp)
pushq 0x28(%rbp)
movq 0x80(%rsp), %r11
pushq (%r11)
movq 0x90(%rsp), %r11
pushq (%r11)
pushq %r10
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x41599b
addq $0x80, %rsp
testl %r13d, %r13d
jle 0x406a0d
movl %r13d, %eax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movss (%r12,%r14,4), %xmm0
callq 0x4166f7
movb %al, (%r15,%r14)
movss 0x4(%r12,%r14,4), %xmm0
callq 0x4166f7
movb %al, 0x1(%r15,%r14)
movss 0x8(%r12,%r14,4), %xmm0
callq 0x4166f7
movb %al, 0x2(%r15,%r14)
addq $0x3, %r14
cmpq %r14, %rbx
jne 0x4069d3
movq 0x18(%rsp), %rsi
leal (%rsi,%rsi,2), %r9d
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movl 0x8(%rsp), %edx
movl $0x3, %ecx
movq %r15, %r8
callq 0x4140aa
leaq 0xd001e(%rip), %rdi     # 0x4d6a54
movq %rbx, %rsi
xorl %eax, %eax
callq 0x427440
movl 0xc(%rsp), %ebx
cmpl $-0x1, %ebx
sete %al
addq $0x15e8, %rsp           # imm = 0x15E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x518868, %rax         # imm = 0x518868
movq (%rax), %rdi
leaq 0xcff8b(%rip), %rsi     # 0x4d69f8
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x427380
jmp 0x406a44