// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %rbx
movl 0x18(%rdi), %edx
movq %rsi, %rdi
movl $0x2, %esi
callq 0xcf07
movq %rax, %r14
movl 0x1c(%rbx), %edx
movq %r12, %rdi
movl $0x2, %esi
callq 0xcf07
movq %rax, %r15
movl 0x20(%rbx), %edx
movq %r12, %rdi
movl $0x2, %esi
callq 0xcf07
movq %rax, %r12
movsd 0x20(%r15), %xmm1
movsd 0x28(%r15), %xmm0
subsd 0x20(%rax), %xmm1
subsd 0x28(%rax), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x30(%r15), %xmm0
subsd 0x30(%rax), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jb 0xd5d8
sqrtsd %xmm0, %xmm0
jmp 0xd5e1
callq 0x11b0
xorpd %xmm2, %xmm2
movsd %xmm0, 0x88(%rbx)
movsd 0x20(%r14), %xmm1
movsd 0x28(%r14), %xmm0
subsd 0x20(%r12), %xmm1
subsd 0x28(%r12), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x30(%r14), %xmm0
subsd 0x30(%r12), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0xd630
sqrtsd %xmm0, %xmm0
jmp 0xd635
callq 0x11b0
movsd %xmm0, 0x90(%rbx)
movsd 0x20(%r15), %xmm1
movsd 0x28(%r15), %xmm0
subsd 0x20(%r14), %xmm1
subsd 0x28(%r14), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x30(%r15), %xmm0
subsd 0x30(%r14), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xd685
sqrtsd %xmm0, %xmm0
jmp 0xd68a
callq 0x11b0
movsd %xmm0, 0x98(%rbx)
movsd 0x20(%r15), %xmm1
movsd 0x28(%r15), %xmm2
movsd 0x20(%r14), %xmm3
movsd 0x28(%r14), %xmm4
subsd %xmm3, %xmm1
movsd 0x20(%r12), %xmm5
movsd 0x28(%r12), %xmm6
subsd %xmm3, %xmm5
mulsd %xmm1, %xmm5
subsd %xmm4, %xmm2
subsd %xmm4, %xmm6
mulsd %xmm2, %xmm6
addsd %xmm5, %xmm6
movsd 0x30(%r15), %xmm2
movsd 0x30(%r14), %xmm3
subsd %xmm3, %xmm2
movsd 0x30(%r12), %xmm1
subsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm6, %xmm1
divsd %xmm0, %xmm1
divsd 0x90(%rbx), %xmm1
movapd %xmm1, %xmm0
callq 0x10f0
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 0x10f0
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 0x10f0
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 0xd3b5
movsd 0x70(%rbx), %xmm0
movsd 0x90(%rbx), %xmm1
mulsd 0x98(%rbx), %xmm1
movsd %xmm1, (%rsp)
callq 0x1170
mulsd (%rsp), %xmm0
mulsd 0xbe4(%rip), %xmm0      # 0xe468
movsd %xmm0, 0xb8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq