// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/kdtree.c
// Function: calcSaCost
bool calcSaCost(int axis,float edget,int nAbove,int nBelow,
                float invTotalSa,const float *minBound,const float *maxBound,
                float emptyBonus,float traversalCost,float isectCost,
                float *cost) {

  float belowSa,aboveSa,pBelow,pAbove,eb,diag[3];
  int otherAxis0,otherAxis1;

  if(!(edget > minBound[axis] && edget < maxBound[axis])) {
    return false;
  }

  diag[0]=maxBound[0]-minBound[0];
  diag[1]=maxBound[1]-minBound[1];
  diag[2]=maxBound[2]-minBound[2];

  otherAxis0=(axis+1)%3;
  otherAxis1=(axis+2)%3;

  belowSa=2.0f*(diag[otherAxis0]*diag[otherAxis1]+
                (edget-minBound[axis])*
                (diag[otherAxis0]+diag[otherAxis1]));
  aboveSa=2.0f*(diag[otherAxis0]*diag[otherAxis1]+
                (maxBound[axis]-edget)*
                (diag[otherAxis0]+diag[otherAxis1]));

  pBelow=belowSa*invTotalSa;
  pAbove=aboveSa*invTotalSa;

  eb=(nAbove==0 || nBelow==0)?emptyBonus:0.0f;
  *cost=traversalCost+isectCost*(1.0f-eb)*
    (pBelow*(float)nBelow+pAbove*(float)nAbove);

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movss %xmm2, -0x2c(%rbp)
movss %xmm3, -0x30(%rbp)
movss %xmm4, -0x34(%rbp)
movq %r9, -0x40(%rbp)
movss -0xc(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
ucomiss (%rax,%rcx,4), %xmm0
jbe 0x409abc
movss -0xc(%rbp), %xmm1
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
ja 0x409ac5
movb $0x0, -0x1(%rbp)
jmp 0x409c71
movq -0x28(%rbp), %rax
movss (%rax), %xmm0
movq -0x20(%rbp), %rax
subss (%rax), %xmm0
movss %xmm0, -0x60(%rbp)
movq -0x28(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x20(%rbp), %rax
subss 0x4(%rax), %xmm0
movss %xmm0, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x20(%rbp), %rax
subss 0x8(%rax), %xmm0
movss %xmm0, -0x58(%rbp)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x64(%rbp)
movl -0x8(%rbp), %eax
addl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x68(%rbp)
movslq -0x64(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm1
movslq -0x68(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm2
movss -0xc(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movslq -0x64(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm3
movslq -0x68(%rbp), %rax
addss -0x60(%rbp,%rax,4), %xmm3
mulss %xmm3, %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0xdad94(%rip), %xmm0    # 0x4e490c
mulss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
movslq -0x64(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm1
movslq -0x68(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm2
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
subss -0xc(%rbp), %xmm0
movslq -0x64(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm3
movslq -0x68(%rbp), %rax
addss -0x60(%rbp,%rax,4), %xmm3
mulss %xmm3, %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0xdad3d(%rip), %xmm0    # 0x4e490c
mulss %xmm1, %xmm0
movss %xmm0, -0x48(%rbp)
movss -0x44(%rbp), %xmm0
mulss -0x18(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x48(%rbp), %xmm0
mulss -0x18(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x409c02
cmpl $0x0, -0x14(%rbp)
jne 0x409c0e
movss -0x2c(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
jmp 0x409c18
xorps %xmm0, %xmm0
movss %xmm0, -0x6c(%rbp)
jmp 0x409c18
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x30(%rbp), %xmm1
movss -0x34(%rbp), %xmm0
movss 0xd9850(%rip), %xmm2    # 0x4e3484
subss -0x54(%rbp), %xmm2
mulss %xmm2, %xmm0
movss -0x4c(%rbp), %xmm2
cvtsi2ssl -0x14(%rbp), %xmm4
movss -0x50(%rbp), %xmm3
cvtsi2ssl -0x10(%rbp), %xmm5
mulss %xmm5, %xmm3
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x40(%rbp), %rax
movss %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopl (%rax,%rax)