// File: /workspace/github_c_makefile_star2_O1/markpeerdeman[P]mbemm/src/emath/contactc.c
// Function: makelocalsystem
void makelocalsystem(matrix tramat, point p)
{ double min; 
  double max;
  double tmp;
  int smallest;
  int largest;
  int middle;
  int sum;
  double len;
  /* STEP 1: copy the contents of the normal vector to the first matrix column: */
             M(tramat,1,1)=p->n1;
             M(tramat,2,1)=p->n2;
             M(tramat,3,1)=p->n3;
  /* STEP 2: construct a vector perpendicular to the normal vector: */
  /*      a: find minimum and maximum components: */
             min=fabs(p->n1); max=min; smallest=1; largest=1; 
             tmp=fabs(p->n2); if (tmp<min) { min=tmp; smallest=2; }
                              if (tmp>max) { max=tmp; largest=2; }
             tmp=fabs(p->n3); if (tmp<min) { min=tmp; smallest=3; }
                              if (tmp>max) { max=tmp; largest=3; }
             sum=smallest+largest;
             if (sum==3) middle=3; else
             if (sum==4) middle=2; else
             if (sum==5) middle=1; 
  /*      b: Put the results in the second matrix column and swap something: */
             M(tramat,smallest,2)=  0.0;
             M(tramat,middle,2)  = -M(tramat,largest,1);
             M(tramat,largest,2) =  M(tramat,middle,1);
             len=sqrt(M(tramat,middle,2)*M(tramat,middle,2)+M(tramat,largest,2)*M(tramat,largest,2));
             M(tramat,middle,2)=M(tramat,middle,2)/len;
             M(tramat,largest,2)=M(tramat,largest,2)/len;
             /* ^ moet genormeerd worden! */
  /* STEP 3: The third base vector is calculated as the vectorproduct of the
             two other vectors: */
             M(tramat,1,3) = p->n2*M(tramat,2,3)-p->n3*M(tramat,2,2);
             M(tramat,2,3) = p->n3*M(tramat,2,1)-p->n1*M(tramat,2,3);
             M(tramat,3,3) = p->n1*M(tramat,2,2)-p->n2*M(tramat,2,1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x68(%rsi), %xmm0
movq 0x8(%rdi), %rax
movq (%rax), %rcx
movsd %xmm0, (%rcx)
movsd 0x70(%rsi), %xmm0
movq 0x8(%rax), %rcx
movsd %xmm0, (%rcx)
movsd 0x78(%rsi), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, (%rcx)
movdqu 0x68(%rsi), %xmm0
movdqa 0x67c7(%rip), %xmm2     # 0xe010
pand %xmm2, %xmm0
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
xorl %ecx, %ecx
ucomisd %xmm1, %xmm0
seta %cl
incl %ecx
movq 0x78(%rsi), %xmm3
pand %xmm2, %xmm3
movapd %xmm1, %xmm2
xorl %r15d, %r15d
ucomisd %xmm0, %xmm1
seta %r15b
minsd %xmm0, %xmm2
incl %r15d
ucomisd %xmm3, %xmm2
movl $0x3, %edx
cmoval %edx, %ecx
maxsd %xmm0, %xmm1
ucomisd %xmm1, %xmm3
cmoval %edx, %r15d
leal (%rcx,%r15), %edx
addl $-0x3, %edx
movl $0x2, %esi
subq %rdx, %rsi
xorl %r12d, %r12d
cmpl $0x3, %edx
cmovbq %rsi, %r12
movq -0x8(%rax,%rcx,8), %rcx
movq $0x0, 0x8(%rcx)
decl %r15d
movq (%rax,%r15,8), %rcx
movsd (%rcx), %xmm0
xorps 0x6754(%rip), %xmm0     # 0xe020
movq (%rax,%r12,8), %rax
movlps %xmm0, 0x8(%rax)
movsd (%rax), %xmm1
movsd %xmm1, 0x8(%rcx)
movsd 0x8(%rax), %xmm0
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x78fe
sqrtsd %xmm0, %xmm0
jmp 0x7903
callq 0x11b0
movq 0x8(%r14), %rax
movq (%rax,%r12,8), %rcx
movsd 0x8(%rcx), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx)
movq (%rax,%r15,8), %rcx
movsd 0x8(%rcx), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx)
movsd 0x70(%rbx), %xmm0
movq 0x8(%rax), %rcx
movsd 0x8(%rcx), %xmm1
mulsd 0x78(%rbx), %xmm1
mulsd 0x10(%rcx), %xmm0
movq (%rax), %rdx
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rdx)
movsd (%rcx), %xmm0
movsd 0x10(%rcx), %xmm1
mulsd 0x68(%rbx), %xmm1
movsd 0x78(%rbx), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rcx)
movsd 0x68(%rbx), %xmm1
mulsd 0x70(%rbx), %xmm0
mulsd 0x8(%rcx), %xmm1
subsd %xmm0, %xmm1
movq 0x10(%rax), %rax
movsd %xmm1, 0x10(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq