// File: /workspace/github_c_makefile_star2_O2/markpeerdeman[P]mbemm/src/general/tril.c
// Function: TRILcompletion
void TRILcompletion( const element theTRIL, const point thepointlist )
{ /* This function completes the tril data after reading the input deck */
  point p1, p2, p3;

  p1 = (point)point_dll(thepointlist,SEARCH,theTRIL->p1);
  p2 = (point)point_dll(thepointlist,SEARCH,theTRIL->p2);
  p3 = (point)point_dll(thepointlist,SEARCH,theTRIL->p3);

  /* calculate the lengths of the element sides: */
  theTRIL->z1 = sqrt( (p2->x-p3->x)*(p2->x-p3->x) +
					  (p2->y-p3->y)*(p2->y-p3->y) +
					  (p2->z-p3->z)*(p2->z-p3->z) );

  theTRIL->z2 = sqrt( (p1->x-p3->x)*(p1->x-p3->x) +
					  (p1->y-p3->y)*(p1->y-p3->y) +
					  (p1->z-p3->z)*(p1->z-p3->z) );

  theTRIL->z3 = sqrt( (p2->x-p1->x)*(p2->x-p1->x) +
					  (p2->y-p1->y)*(p2->y-p1->y) +
					  (p2->z-p1->z)*(p2->z-p1->z) );

  /* calculate the corner angles: */
  theTRIL->alpha1 = acos( ( (p2->x-p1->x)*(p3->x-p1->x) +
					        (p2->y-p1->y)*(p3->y-p1->y) +
					        (p2->z-p1->z)*(p3->z-p1->z) ) /
					        theTRIL->z3 / theTRIL->z2 );

  theTRIL->alpha2 = acos( ( (p3->x-p2->x)*(p1->x-p2->x) +
					        (p3->y-p2->y)*(p1->y-p2->y) +
					        (p3->z-p2->z)*(p1->z-p2->z) ) /
					        theTRIL->z1 / theTRIL->z3 );

  theTRIL->alpha3 = acos( ( (p1->x-p3->x)*(p2->x-p3->x) +
					        (p1->y-p3->y)*(p2->y-p3->y) +
					        (p1->z-p3->z)*(p2->z-p3->z) ) /
					        theTRIL->z2 / theTRIL->z1 );

  /* copy the node coordinates into the element structure: */
  theTRIL->p1x=p1->x;
  theTRIL->p1y=p1->y;
  theTRIL->p1z=p1->z;
  theTRIL->p2x=p2->x;
  theTRIL->p2y=p2->y;
  theTRIL->p2z=p2->z;
  theTRIL->p3x=p3->x;
  theTRIL->p3y=p3->y;
  theTRIL->p3z=p3->z;

  fastTRILnormal(theTRIL);
  theTRIL->area = theTRIL->z2 * theTRIL->z3 * sin(theTRIL->alpha1) * 0.5;
/*
  printf("TEST 1: DATA FOR ELEMENT %d:\n",theTRIL->label);
  printf("        node labels: %3d %3d %3d\n",theTRIL->p1,theTRIL->p2,theTRIL->p3);
  printf("        node coordinates:\n");
  printf("             node %3d, \t%f \t%f \t%f\n",theTRIL->p1,(float)theTRIL->p1x,
   (float)theTRIL->p1y, (float)theTRIL->p1z);
  printf("             node %3d, \t%f \t%f \t%f\n",theTRIL->p2,(float)theTRIL->p2x,
   (float)theTRIL->p2y, (float)theTRIL->p2z);
  printf("             node %3d, \t%f \t%f \t%f\n",theTRIL->p3,(float)theTRIL->p3x,
   (float)theTRIL->p3y, (float)theTRIL->p3z);
  printf("        side lenghts are: z1: %f, z2: %f, z3: %f\n",(float)theTRIL->z1,
	(float)theTRIL->z2,(float)theTRIL->z3);
  printf("        element area is %f\n",(float)theTRIL->area);
  printf("        normal vector is %f %f %f\n",(float)theTRIL->nx,(float)theTRIL->ny,
	(float)theTRIL->nz);
  printf("        angles alpha1, alpha2 and alpha3 are: %f %f %f\n",
	(float)theTRIL->alpha1,(float)theTRIL->alpha2,(float)theTRIL->alpha3); */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl 0x18(%rdi), %edx
pushq $0x2
popq %rbp
movq %rsi, %rdi
movl %ebp, %esi
callq 0xc14c
movq %rax, %r14
movl 0x1c(%rbx), %edx
movq %r12, %rdi
movl %ebp, %esi
callq 0xc14c
movq %rax, %r15
movl 0x20(%rbx), %edx
movq %r12, %rdi
movl %ebp, %esi
callq 0xc14c
movq %rax, %r12
movsd 0x20(%r15), %xmm4
movsd 0x28(%r15), %xmm6
movsd 0x20(%rax), %xmm1
movsd 0x28(%rax), %xmm2
movsd 0x30(%r15), %xmm3
movsd 0x30(%rax), %xmm0
movsd 0x20(%r14), %xmm7
movsd 0x28(%r14), %xmm9
movsd 0x30(%r14), %xmm5
movapd %xmm4, %xmm8
unpcklpd %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0]
movapd %xmm1, %xmm10
unpcklpd %xmm1, %xmm10           # xmm10 = xmm10[0],xmm1[0]
subpd %xmm10, %xmm8
movapd %xmm6, %xmm10
unpcklpd %xmm9, %xmm10           # xmm10 = xmm10[0],xmm9[0]
movapd %xmm2, %xmm11
unpcklpd %xmm2, %xmm11           # xmm11 = xmm11[0],xmm2[0]
subpd %xmm11, %xmm10
mulpd %xmm10, %xmm10
mulpd %xmm8, %xmm8
addpd %xmm10, %xmm8
movapd %xmm3, %xmm10
unpcklpd %xmm5, %xmm10           # xmm10 = xmm10[0],xmm5[0]
movapd %xmm0, %xmm11
unpcklpd %xmm0, %xmm11           # xmm11 = xmm11[0],xmm0[0]
subpd %xmm11, %xmm10
mulpd %xmm10, %xmm10
addpd %xmm8, %xmm10
sqrtpd %xmm10, %xmm8
movupd %xmm8, 0x88(%rbx)
subsd %xmm7, %xmm4
subsd %xmm9, %xmm6
subsd %xmm9, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm6, %xmm6
subsd %xmm7, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm4
addsd %xmm6, %xmm4
subsd %xmm5, %xmm3
subsd %xmm5, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
movsd %xmm3, 0x98(%rbx)
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
divsd %xmm3, %xmm0
unpckhpd %xmm8, %xmm8            # xmm8 = xmm8[1,1]
divsd %xmm8, %xmm0
callq 0x10e0
movsd %xmm0, 0x70(%rbx)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x20(%r15), %xmm2
movsd 0x28(%r15), %xmm3
subsd %xmm2, %xmm0
movsd 0x20(%r14), %xmm4
movsd 0x28(%r14), %xmm5
subsd %xmm2, %xmm4
mulsd %xmm0, %xmm4
subsd %xmm3, %xmm1
subsd %xmm3, %xmm5
mulsd %xmm1, %xmm5
addsd %xmm4, %xmm5
movsd 0x30(%r12), %xmm1
movsd 0x30(%r15), %xmm2
subsd %xmm2, %xmm1
movsd 0x30(%r14), %xmm0
subsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm5, %xmm0
divsd 0x88(%rbx), %xmm0
divsd 0x98(%rbx), %xmm0
callq 0x10e0
movsd %xmm0, 0x78(%rbx)
movsd 0x20(%r14), %xmm0
movsd 0x28(%r14), %xmm1
movsd 0x20(%r12), %xmm2
movsd 0x28(%r12), %xmm3
subsd %xmm2, %xmm0
movsd 0x20(%r15), %xmm4
movsd 0x28(%r15), %xmm5
subsd %xmm2, %xmm4
mulsd %xmm0, %xmm4
subsd %xmm3, %xmm1
subsd %xmm3, %xmm5
mulsd %xmm1, %xmm5
addsd %xmm4, %xmm5
movsd 0x30(%r14), %xmm1
movsd 0x30(%r12), %xmm2
subsd %xmm2, %xmm1
movsd 0x30(%r15), %xmm0
subsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm5, %xmm0
divsd 0x90(%rbx), %xmm0
divsd 0x88(%rbx), %xmm0
callq 0x10e0
movsd %xmm0, 0x80(%rbx)
movups 0x20(%r14), %xmm0
movups %xmm0, 0x28(%rbx)
movsd 0x30(%r14), %xmm0
movsd %xmm0, 0x38(%rbx)
movups 0x20(%r15), %xmm0
movups %xmm0, 0x40(%rbx)
movsd 0x30(%r15), %xmm0
movsd %xmm0, 0x50(%rbx)
movups 0x20(%r12), %xmm0
movups %xmm0, 0x58(%rbx)
movsd 0x30(%r12), %xmm0
movsd %xmm0, 0x68(%rbx)
movq %rbx, %rdi
callq 0xc559
movsd 0x70(%rbx), %xmm0
movsd 0x90(%rbx), %xmm1
mulsd 0x98(%rbx), %xmm1
movsd %xmm1, 0x8(%rsp)
callq 0x1160
mulsd 0x8(%rsp), %xmm0
mulsd 0xaab(%rip), %xmm0      # 0xd460
movsd %xmm0, 0xb8(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq