// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/math.c
// Function: mat4_lookAt
void mat4_lookAt(float *out,
                 float px,float py,float pz,
                 float ax,float ay,float az,
                 float ux,float uy,float uz) {
  //untested

  float eye[3]={px,py,pz};
  float at[3]={ax,ay,az};
  float up[3]={ux,uy,uz};

  float zaxis[3],xaxis[3],yaxis[3];

  vec3_sub(zaxis,at,eye);
  vec3_normal(zaxis,zaxis);

  vec3_cross(xaxis,zaxis,up);
  vec3_normal(xaxis,xaxis);

  vec3_cross(yaxis,xaxis,zaxis);
  vec3_normal(yaxis,yaxis);

  out[0]=xaxis[0];
  out[1]=yaxis[0];
  out[2]=zaxis[0];
  out[3]=0.0f;

  out[4]=xaxis[1];
  out[5]=yaxis[1];
  out[6]=zaxis[1];
  out[7]=0.0f;


  out[8]=xaxis[2];
  out[9]=yaxis[2];
  out[10]=zaxis[2];
  out[11]=0.0f;

  out[12]=-vec3_dot(xaxis,eye);
  out[13]=-vec3_dot(yaxis,eye);
  out[14]=-vec3_dot(zaxis,eye);
  out[15]=1.0f;

  //wrong handed? row major?
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movaps %xmm7, (%rsp)
movaps %xmm6, 0x10(%rsp)
movaps %xmm2, 0x90(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rdi, %rbx
unpcklps %xmm4, %xmm3            # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
movaps %xmm0, %xmm4
unpcklps %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subps %xmm4, %xmm3
leaq 0xc8(%rsp), %r14
movlps %xmm3, (%r14)
subss %xmm2, %xmm5
movss %xmm5, 0x8(%r14)
movq %r14, %rdi
movq %r14, %rsi
callq 0x406f42
movss (%r14), %xmm2
movaps %xmm2, 0x30(%rsp)
movsd 0x4(%r14), %xmm1
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
movaps %xmm0, 0x60(%rsp)
movaps %xmm2, %xmm4
shufps $0xd4, %xmm1, %xmm4     # xmm4 = xmm4[0,1],xmm1[1,3]
shufps $0x52, %xmm1, %xmm4     # xmm4 = xmm4[2,0],xmm1[1,1]
movaps %xmm4, 0x50(%rsp)
movaps %xmm1, %xmm3
movss 0xf0(%rsp), %xmm0
movaps %xmm2, %xmm1
movaps (%rsp), %xmm2
mulss %xmm2, %xmm1
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
mulps %xmm4, %xmm2
movaps %xmm2, %xmm4
movaps 0x10(%rsp), %xmm2
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movaps %xmm3, 0x20(%rsp)
mulps %xmm3, %xmm0
subps %xmm4, %xmm0
mulss %xmm3, %xmm2
subss %xmm2, %xmm1
leaq 0xb8(%rsp), %r14
movlps %xmm0, (%r14)
movss %xmm1, 0x8(%r14)
movq %r14, %rdi
movq %r14, %rsi
callq 0x406f42
movss (%r14), %xmm2
movsd 0x4(%r14), %xmm1
movaps %xmm1, (%rsp)
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
movaps %xmm0, 0x10(%rsp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm4
movaps %xmm2, 0x40(%rsp)
shufps $0xd4, %xmm1, %xmm0     # xmm0 = xmm0[0,1],xmm1[1,3]
shufps $0x52, %xmm1, %xmm0     # xmm0 = xmm0[2,0],xmm1[1,1]
movaps 0x20(%rsp), %xmm2
mulps %xmm2, %xmm0
movaps 0x50(%rsp), %xmm3
mulps %xmm1, %xmm3
subps %xmm0, %xmm3
movaps 0x30(%rsp), %xmm0
mulss %xmm1, %xmm0
movaps %xmm4, %xmm1
mulss %xmm2, %xmm1
subss %xmm0, %xmm1
leaq 0xa8(%rsp), %r14
movlps %xmm3, (%r14)
movss %xmm1, 0x8(%r14)
movq %r14, %rdi
movq %r14, %rsi
callq 0x406f42
movaps 0x40(%rsp), %xmm4
movss %xmm4, (%rbx)
movss (%r14), %xmm0
movss %xmm0, 0x4(%rbx)
movaps 0x30(%rsp), %xmm7
movss %xmm7, 0x8(%rbx)
andl $0x0, 0xc(%rbx)
movaps (%rsp), %xmm3
movss %xmm3, 0x10(%rbx)
movss 0x4(%r14), %xmm1
movss %xmm1, 0x14(%rbx)
movaps 0x20(%rsp), %xmm8
movss %xmm8, 0x18(%rbx)
andl $0x0, 0x1c(%rbx)
movaps 0x10(%rsp), %xmm2
movss %xmm2, 0x20(%rbx)
movss 0x8(%r14), %xmm2
movss %xmm2, 0x24(%rbx)
movaps 0x60(%rsp), %xmm6
movss %xmm6, 0x28(%rbx)
andl $0x0, 0x2c(%rbx)
movlhps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm1     # xmm1 = xmm1[2,0],xmm3[2,3]
movaps %xmm3, %xmm9
movaps 0x70(%rsp), %xmm5
movaps %xmm5, %xmm3
shufps $0x0, %xmm5, %xmm3      # xmm3 = xmm3[0,0],xmm5[0,0]
mulps %xmm1, %xmm3
movaps %xmm4, %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps 0x80(%rsp), %xmm4
movaps %xmm4, %xmm0
shufps $0x0, %xmm4, %xmm0      # xmm0 = xmm0[0,0],xmm4[0,0]
mulps %xmm1, %xmm0
addps %xmm3, %xmm0
shufps $0xd4, %xmm9, %xmm2     # xmm2 = xmm2[0,1],xmm9[1,3]
shufps $0x52, %xmm9, %xmm2     # xmm2 = xmm2[2,0],xmm9[1,1]
movaps 0x90(%rsp), %xmm1
mulss %xmm1, %xmm6
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
mulps %xmm2, %xmm1
addps %xmm0, %xmm1
movaps 0xcb36e(%rip), %xmm0    # 0x4d3c50
xorps %xmm0, %xmm1
movlps %xmm1, 0x30(%rbx)
movaps %xmm8, %xmm2
mulss %xmm5, %xmm2
movaps %xmm7, %xmm1
mulss %xmm4, %xmm1
addss %xmm2, %xmm1
addss %xmm6, %xmm1
xorps %xmm0, %xmm1
movss %xmm1, 0x38(%rbx)
movl $0x3f800000, 0x3c(%rbx) # imm = 0x3F800000
addq $0xd8, %rsp
popq %rbx
popq %r14
retq