// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/math.c
// Function: mat4_rotateAxis
void mat4_rotateAxis(float *out,const float *axis,
                     float angle,bool norm,bool mul) {
  float axis2[3];
  float mat[16];
  float u,v,w,L,u2,v2,w2;

  mat4_identity(mat);

  if(norm) {
    vec3_normal(axis2,axis);
  } else {
    axis2[0]=axis[0];
    axis2[1]=axis[1];
    axis2[2]=axis[2];
  }

  u=axis2[0];
  v=axis2[1];
  w=axis2[2];

  L=(u*u+v*v+w*w);

  u2=axis2[0]*axis2[0];
  v2=axis2[1]*axis2[1];
  w2=axis2[2]*axis2[2];

  mat[0]=(u2+(v2+w2)*cosf(angle))/L;
  mat[1]=(u*v*(1.0f-cosf(angle))-w*sqrtf(L)*sinf(angle))/L;
  mat[2]=(u*w*(1.0f-cosf(angle))+v*sqrtf(L)*sinf(angle))/L;

  mat[4]=(u*v*(1.0f-cosf(angle))+w*sqrtf(L)*sinf(angle))/L;
  mat[5]=(v2+(u2+w2)*cosf(angle))/L;
  mat[6]=(v*w*(1.0f-cosf(angle))-u*sqrtf(L)*sinf(angle))/L;

  mat[8]=(u*w*(1.0f-cosf(angle))-v*sqrtf(L)*sinf(angle))/L;
  mat[9]=(v*w*(1.0f-cosf(angle))+u*sqrtf(L)*sinf(angle))/L;
  mat[10]=(w2+(u2+v2)*cosf(angle))/L;

  //
  if(mul) {
    mat4_mul(out,out,mat);
  } else {
    memcpy(out,mat,sizeof(mat));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %ecx, %ebp
movl %edx, %r15d
movss %xmm0, (%rsp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x40700a
testl %r15d, %r15d
je 0x407610
leaq 0x12c(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x406f42
movq %r15, %r14
movss 0x8(%r14), %xmm0
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, %xmm1
mulss %xmm0, %xmm1
movaps %xmm1, 0xa0(%rsp)
xorps 0xcc61c(%rip), %xmm0    # 0x4d3c50
movaps %xmm0, 0x80(%rsp)
movsd (%r14), %xmm0
movaps %xmm0, 0x70(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movaps %xmm0, 0x20(%rsp)
movaps 0x70(%rsp), %xmm1
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
movaps %xmm0, 0x30(%rsp)
mulss %xmm0, %xmm1
movaps %xmm1, 0x10(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movss 0xcaddf(%rip), %xmm1    # 0x4d2460
movss %xmm1, 0x40(%rsp)
subss %xmm0, %xmm1
movaps %xmm1, 0x60(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movaps %xmm0, 0x50(%rsp)
movaps 0x20(%rsp), %xmm0
unpcklps 0x10(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
movaps %xmm0, 0x20(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movss 0xcada0(%rip), %xmm1    # 0x4d2460
subss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movss %xmm0, 0x4(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movss 0xcad74(%rip), %xmm1    # 0x4d2460
subss %xmm0, %xmm1
movaps %xmm1, 0xf0(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movss %xmm0, 0x8(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movaps 0x30(%rsp), %xmm4
movaps %xmm4, %xmm5
mulss %xmm4, %xmm5
movaps %xmm5, %xmm1
movaps 0xa0(%rsp), %xmm2
addss %xmm2, %xmm1
unpcklps 0x60(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movaps 0x70(%rsp), %xmm3
movaps %xmm3, %xmm6
mulss %xmm3, %xmm6
addss %xmm5, %xmm6
movaps %xmm5, %xmm7
movaps %xmm5, 0x100(%rsp)
addss %xmm2, %xmm6
movaps %xmm2, %xmm5
mulps 0x20(%rsp), %xmm1
sqrtss %xmm6, %xmm2
movaps 0x80(%rsp), %xmm8
mulss %xmm2, %xmm8
movaps %xmm2, %xmm9
movaps %xmm2, 0x90(%rsp)
movlhps %xmm3, %xmm8            # xmm8 = xmm8[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm8     # xmm8 = xmm8[2,0],xmm3[2,3]
movaps 0x50(%rsp), %xmm2
movlhps %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm2     # xmm2 = xmm2[2,0],xmm3[2,3]
movaps %xmm3, %xmm10
mulps %xmm8, %xmm2
addps %xmm2, %xmm1
movaps %xmm2, %xmm3
movaps %xmm2, 0x50(%rsp)
movaps %xmm6, 0x60(%rsp)
movaps %xmm6, %xmm2
shufps $0x0, %xmm6, %xmm2      # xmm2 = xmm2[0,0],xmm6[0,0]
divps %xmm2, %xmm1
movaps %xmm2, %xmm8
movaps %xmm2, 0x80(%rsp)
movlps %xmm1, 0xb0(%rsp)
movaps %xmm4, %xmm1
mulss %xmm9, %xmm1
mulss 0x4(%rsp), %xmm1
movaps 0x110(%rsp), %xmm2
movaps %xmm2, %xmm4
shufps $0x0, %xmm2, %xmm4      # xmm4 = xmm4[0,0],xmm2[0,0]
mulps %xmm10, %xmm4
movaps %xmm4, 0x20(%rsp)
movss 0xc(%rsp), %xmm10
mulss %xmm4, %xmm10
addss %xmm1, %xmm10
divss %xmm6, %xmm10
movss %xmm10, 0xb8(%rsp)
mulss %xmm9, %xmm2
mulss 0x8(%rsp), %xmm2
movaps %xmm3, %xmm1
addss %xmm5, %xmm1
movaps 0x10(%rsp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movaps 0xf0(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
mulps %xmm3, %xmm1
movaps %xmm2, %xmm0
unpcklps %xmm7, %xmm0            # xmm0 = xmm0[0],xmm7[0],xmm0[1],xmm7[1]
addps %xmm1, %xmm0
divps %xmm8, %xmm0
movlps %xmm0, 0xc0(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movss 0x40(%rsp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x40(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movaps 0x90(%rsp), %xmm1
mulss 0x70(%rsp), %xmm1
mulss %xmm0, %xmm1
movaps 0x20(%rsp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss 0x40(%rsp), %xmm0
subss %xmm1, %xmm0
divss 0x60(%rsp), %xmm0
movss %xmm0, 0xc8(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movaps %xmm0, 0x10(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movaps %xmm0, 0x40(%rsp)
movaps 0x30(%rsp), %xmm0
xorps 0xcc389(%rip), %xmm0    # 0x4d3c50
movaps %xmm0, 0x30(%rsp)
movss (%rsp), %xmm0
callq 0x401080
movaps 0x10(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps 0xcc37b(%rip), %xmm0    # 0x4d3c60
subps %xmm1, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps 0x90(%rsp), %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
movaps 0x30(%rsp), %xmm0
unpcklps 0x70(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
mulps %xmm1, %xmm0
movaps %xmm0, 0x30(%rsp)
movss (%rsp), %xmm0
callq 0x401120
movaps 0x40(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
mulps 0x30(%rsp), %xmm1
movaps 0x10(%rsp), %xmm0
mulps 0x20(%rsp), %xmm0
addps %xmm1, %xmm0
divps 0x80(%rsp), %xmm0
movlps %xmm0, 0xd0(%rsp)
movaps 0x50(%rsp), %xmm0
addss 0x100(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movss (%rsp), %xmm0
callq 0x401080
mulss 0x50(%rsp), %xmm0
addss 0xa0(%rsp), %xmm0
divss 0x60(%rsp), %xmm0
movss %xmm0, 0xd8(%rsp)
testb %bpl, %bpl
je 0x407993
leaq 0xb0(%rsp), %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x407086
jmp 0x4079c2
movaps 0xb0(%rsp), %xmm0
movaps 0xc0(%rsp), %xmm1
movaps 0xd0(%rsp), %xmm2
movaps 0xe0(%rsp), %xmm3
movups %xmm3, 0x30(%rbx)
movups %xmm2, 0x20(%rbx)
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
popq %r15
popq %rbp
retq