// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/utils.c
// Function: renderScene2
void renderScene2(int updateFrom,int updateTo,
                 int width, int height,
                 float aspect,float yFov,
                 const float *minBound,const float *maxBound,
                 const float *origin,
                 const float *rotMat,
                 struct Ray *rayStack,
                 struct KdTraverseNode *traverseStack,
                 struct KdNode *rootNode,
                 struct Triangle *triangles,int trianglesNum,
                 struct Sphere *spheres,int spheresNum,
                 struct PointLight *pointLights,int pointLightsNum,


                 sobol_state_t *qrnd,


                 float *canvas,

                 int maxBounces,int maxSplits) {

  int denom=maxBounces*maxSplits;
  float glossyRatio=(denom!=0)?(1.0f/(float)denom)*0.2f:0.0f;


  float d;
  int i;

  //
  d=1.0f/tanf(yFov/2.0f);

  //
  int raycastsNum;


  for(i=updateFrom;i<updateTo;i++) {
    int x,y;
    float u,v,px,py;
    float pixelCol[3]={0.0f,0.0f,0.0f};

    raycastsNum=1;

    rayStack[raycastsNum-1].bounces=0;
    rayStack[raycastsNum-1].origin[0]=origin[0];
    rayStack[raycastsNum-1].origin[1]=origin[1];
    rayStack[raycastsNum-1].origin[2]=origin[2];
    rayStack[raycastsNum-1].ratio=1.0f;

    x=i%width;
    y=i/width;
    u=x/(float)width;
    v=1.0f-y/(float)height; //flip
    px=2.0f*u-1.0f;
    py=2.0f*v-1.0f;

    float bla[3]={px*aspect,py,-d};//rhs


    mat3_mulVector(rayStack[raycastsNum-1].vec,rotMat,bla);
    vec3_normal(rayStack[raycastsNum-1].vec,rayStack[raycastsNum-1].vec);

    while(raycastsNum > 0) {
      float curCol[3]={0.0f,0.0f,0.0f};
      float nor[3],colPt[3];
      float illumCol[3]={0.0f,0.0f,0.0f};
      float specCol[3]={0.0f,0.0f,0.0f};
      struct Material *material;

      //
      raycastsNum--;
      struct Ray ray=rayStack[raycastsNum];

      if(!intersectSceneObject(&ray,traverseStack,minBound,maxBound,rootNode,
                               triangles,trianglesNum,spheres,spheresNum,
                               colPt,nor,&material)) {

        break;
      }

      calcLights(&ray,material,colPt,nor,
                 traverseStack,minBound,maxBound,rootNode,
                 triangles,trianglesNum,spheres,spheresNum,
                 pointLights,pointLightsNum,illumCol,specCol);

      //
      curCol[0]=(material->col[0]*illumCol[0]+specCol[0]);
      curCol[1]=material->col[1]*illumCol[1]+specCol[1];
      curCol[2]=material->col[2]*illumCol[2]+specCol[2];

      curCol[0]*=ray.ratio;
      curCol[1]*=ray.ratio;
      curCol[2]*=ray.ratio;

      pixelCol[0]+=curCol[0];
      pixelCol[1]+=curCol[1];
      pixelCol[2]+=curCol[2];




      ///here



    }

    //
    canvas[(i-updateFrom)*3]=pixelCol[0];
    canvas[(i-updateFrom)*3+1]=pixelCol[1];
    canvas[(i-updateFrom)*3+2]=pixelCol[2];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl 0x80(%rbp), %eax
movl 0x78(%rbp), %eax
movq 0x70(%rbp), %rax
movq 0x68(%rbp), %rax
movl 0x60(%rbp), %eax
movq 0x58(%rbp), %rax
movl 0x50(%rbp), %eax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x2c(%rbp)
movl %esi, -0x30(%rbp)
movl %edx, -0x34(%rbp)
movl %ecx, -0x38(%rbp)
movss %xmm0, -0x3c(%rbp)
movss %xmm1, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movl 0x78(%rbp), %eax
imull 0x80(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x424ed6
cvtsi2ssl -0x54(%rbp), %xmm1
movss 0xbe5c8(%rip), %xmm0    # 0x4e3484
divss %xmm1, %xmm0
movss 0xbfa78(%rip), %xmm1    # 0x4e4940
mulss %xmm1, %xmm0
movss %xmm0, -0xfc(%rbp)
jmp 0x424ee3
xorps %xmm0, %xmm0
movss %xmm0, -0xfc(%rbp)
jmp 0x424ee3
movss -0xfc(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x40(%rbp), %xmm0
movss 0xbfa0f(%rip), %xmm1    # 0x4e490c
divss %xmm1, %xmm0
callq 0x426640
movaps %xmm0, %xmm1
movss 0xbe573(%rip), %xmm0    # 0x4e3484
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x4253fc
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
movl $0x1, -0x64(%rbp)
movq 0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x0, 0x18(%rax)
movq 0x10(%rbp), %rax
movss (%rax), %xmm0
movq 0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
movq 0x10(%rbp), %rax
movss 0x4(%rax), %xmm0
movq 0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
movq 0x10(%rbp), %rax
movss 0x8(%rax), %xmm0
movq 0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movq 0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movss 0xbe4a3(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x1c(%rax)
movl -0x60(%rbp), %eax
cltd
idivl -0x34(%rbp)
movl %edx, -0x68(%rbp)
movl -0x60(%rbp), %eax
cltd
idivl -0x34(%rbp)
movl %eax, -0x6c(%rbp)
cvtsi2ssl -0x68(%rbp), %xmm0
cvtsi2ssl -0x34(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x70(%rbp)
cvtsi2ssl -0x6c(%rbp), %xmm1
cvtsi2ssl -0x38(%rbp), %xmm0
divss %xmm0, %xmm1
movss 0xbe461(%rip), %xmm0    # 0x4e3484
subss %xmm1, %xmm0
movss %xmm0, -0x74(%rbp)
movss -0x70(%rbp), %xmm0
addss %xmm0, %xmm0
movss 0xbfbc7(%rip), %xmm1    # 0x4e4c04
addss %xmm1, %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x74(%rbp), %xmm0
addss %xmm0, %xmm0
movss 0xbfbad(%rip), %xmm1    # 0x4e4c04
addss %xmm1, %xmm0
movss %xmm0, -0x7c(%rbp)
movss -0x78(%rbp), %xmm0
mulss -0x3c(%rbp), %xmm0
movss %xmm0, -0x94(%rbp)
movss -0x7c(%rbp), %xmm0
movss %xmm0, -0x90(%rbp)
movss -0x5c(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x8c(%rbp)
movq 0x20(%rbp), %rdi
movl -0x64(%rbp), %eax
subl $0x1, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
addq $0xc, %rdi
movq 0x18(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x40da30
movq 0x20(%rbp), %rdi
movl -0x64(%rbp), %eax
subl $0x1, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
addq $0xc, %rdi
movq 0x20(%rbp), %rsi
movl -0x64(%rbp), %eax
subl $0x1, %eax
cltq
shlq $0x5, %rax
addq %rax, %rsi
addq $0xc, %rsi
callq 0x40ca00
cmpl $0x0, -0x64(%rbp)
jle 0x425394
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
leaq -0xc4(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
movl -0x64(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x64(%rbp)
movq 0x20(%rbp), %rax
movslq -0x64(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xf8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xf0(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0xe8(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xe0(%rbp)
movq 0x28(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq 0x30(%rbp), %r8
movq 0x38(%rbp), %r9
movl 0x40(%rbp), %r15d
movq 0x48(%rbp), %r14
movl 0x50(%rbp), %ebx
leaq -0xb8(%rbp), %r11
leaq -0xac(%rbp), %r10
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
movl %r15d, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x422d20
testb $0x1, %al
jne 0x4251de
jmp 0x425394
movq -0xd8(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
leaq -0xac(%rbp), %rcx
movq 0x28(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x50(%rbp), %rax
movq 0x30(%rbp), %rdi
movq %rdi, -0x110(%rbp)
movq 0x38(%rbp), %r13
movl 0x40(%rbp), %r12d
movq 0x48(%rbp), %r15
movl 0x50(%rbp), %r14d
movq 0x58(%rbp), %rbx
movl 0x60(%rbp), %r11d
leaq -0xc4(%rbp), %r10
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x108(%rbp)
leaq -0xf8(%rbp), %rdi
movq %rax, (%rsp)
movq -0x110(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x108(%rbp), %rax
movq %r13, 0x10(%rsp)
movl %r12d, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %r14d, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movl %r11d, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x423020
movq -0xd8(%rbp), %rax
movss (%rax), %xmm0
movss -0xc4(%rbp), %xmm2
movss -0xd0(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xa0(%rbp)
movq -0xd8(%rbp), %rax
movss 0x4(%rax), %xmm0
movss -0xc0(%rbp), %xmm2
movss -0xcc(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x9c(%rbp)
movq -0xd8(%rbp), %rax
movss 0x8(%rax), %xmm0
movss -0xbc(%rbp), %xmm2
movss -0xc8(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x98(%rbp)
movss -0xdc(%rbp), %xmm0
mulss -0xa0(%rbp), %xmm0
movss %xmm0, -0xa0(%rbp)
movss -0xdc(%rbp), %xmm0
mulss -0x9c(%rbp), %xmm0
movss %xmm0, -0x9c(%rbp)
movss -0xdc(%rbp), %xmm0
mulss -0x98(%rbp), %xmm0
movss %xmm0, -0x98(%rbp)
movss -0xa0(%rbp), %xmm0
addss -0x88(%rbp), %xmm0
movss %xmm0, -0x88(%rbp)
movss -0x9c(%rbp), %xmm0
addss -0x84(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x98(%rbp), %xmm0
addss -0x80(%rbp), %xmm0
movss %xmm0, -0x80(%rbp)
jmp 0x4250f3
movss -0x88(%rbp), %xmm0
movq 0x70(%rbp), %rax
movl -0x60(%rbp), %ecx
subl -0x2c(%rbp), %ecx
imull $0x3, %ecx, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x84(%rbp), %xmm0
movq 0x70(%rbp), %rax
movl -0x60(%rbp), %ecx
subl -0x2c(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x80(%rbp), %xmm0
movq 0x70(%rbp), %rax
movl -0x60(%rbp), %ecx
subl -0x2c(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x424f20
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop