// File: /workspace/github_c_makefile_star2_O2/markpeerdeman[P]mbemm/src/emath/scale.c
// Function: init_scale
void init_scale(mesh theMesh)
{ /* This function calculates the maximum values of the tractions and displacements in the
   * input deck, and finds the radius of the bounding sphere of the mesh
   */
  double cx=0.0;
  double cy=0.0;
  double cz=0.0;
  double radius=0.0;
  double r;
  point q;
  int nr_points=0;
  restraint di;
  restraint tr;

  /* First the gmax value is calculated: */
  q = (point)point_dll(theMesh->mesh_p,START,0);
  while (q!=(point)NULL)
  { nr_points++;
    cx+=q->x;
    cy+=q->y;
    cz+=q->z;
    q=q->NEXT;
  }
  cx = cx / (double)nr_points;
  cy = cy / (double)nr_points;
  cz = cz / (double)nr_points;

  q = (point)point_dll(theMesh->mesh_p,START,0);
  while (q!=(point)NULL)
  { r = sqrt((cx-q->x)*(cx-q->x)+(cy-q->y)*(cy-q->y)+(cz-q->z)*(cz-q->z));
    if (r>radius) radius=r;
    q=q->NEXT;
  }
  gmax=radius;

  /* Then the dmax value is calculated: */
   dmax = 0.0;
   di = (restraint)restraint_dll(theMesh->mesh_d,START,0);
   while (di!=(restraint)NULL)
   { if (fabs(di->u1)>dmax) dmax=fabs(di->u1);
     if (fabs(di->u2)>dmax) dmax=fabs(di->u2);
     if (fabs(di->u3)>dmax) dmax=fabs(di->u3);
     di=di->NEXT; 
   }

   /* Finally, the tmax value is calculated: */
   tmax = 0.0;
   tr = (restraint)restraint_dll(theMesh->mesh_t,START,0);
   while (tr!=(restraint)NULL)
   { if (fabs(tr->f1)>tmax) tmax=fabs(tr->f1);
     if (fabs(tr->f2)>tmax) tmax=fabs(tr->f2);
     if (fabs(tr->f3)>tmax) tmax=fabs(tr->f3);
     tr=tr->NEXT; 
   }

   if ( (dmax<1.0E-20)&&(tmax<1.0E-20))
   { dmax = 1.0E-11; tmax= 1.0; }

   /* dmax=dmax/20.0; */

}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xc14c
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testq %rax, %rax
je 0x8d03
addsd 0x20(%rax), %xmm2
incl %ebp
movupd 0x28(%rax), %xmm0
addpd %xmm0, %xmm1
movq 0x8(%rax), %rax
jmp 0x8ce8
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
divsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc14c
movapd 0x10(%rsp), %xmm5
movsd 0x8(%rsp), %xmm4
movapd 0x20(%rsp), %xmm3
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x8d95
movapd %xmm4, %xmm1
subsd 0x20(%rax), %xmm1
movapd %xmm5, %xmm2
subsd 0x28(%rax), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
movapd %xmm3, %xmm2
subsd 0x30(%rax), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
sqrtsd %xmm2, %xmm1
maxsd %xmm0, %xmm1
movq 0x8(%rax), %rax
movapd %xmm1, %xmm0
jmp 0x8d4f
movsd %xmm0, 0xbad3(%rip)     # 0x14870
andq $0x0, 0xbad3(%rip)      # 0x14878
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc3a0
movsd 0xbabe(%rip), %xmm0     # 0x14878
movapd 0x424e(%rip), %xmm2     # 0xd010
testq %rax, %rax
je 0x8e1e
movsd 0x30(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8de2
movsd %xmm1, 0xba9a(%rip)     # 0x14878
movapd %xmm1, %xmm0
movsd 0x38(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8dfd
movsd %xmm1, 0xba7f(%rip)     # 0x14878
movapd %xmm1, %xmm0
movsd 0x40(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e18
movsd %xmm1, 0xba64(%rip)     # 0x14878
movapd %xmm1, %xmm0
movq 0x8(%rax), %rax
jmp 0x8dc2
andq $0x0, 0xba5a(%rip)      # 0x14880
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc3a0
movapd 0x41d5(%rip), %xmm2     # 0xd010
movsd 0xba3d(%rip), %xmm0     # 0x14880
testq %rax, %rax
je 0x8e9f
movsd 0x18(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e63
movsd %xmm1, 0xba21(%rip)     # 0x14880
movapd %xmm1, %xmm0
movsd 0x20(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e7e
movsd %xmm1, 0xba06(%rip)     # 0x14880
movapd %xmm1, %xmm0
movsd 0x28(%rax), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e99
movsd %xmm1, 0xb9eb(%rip)     # 0x14880
movapd %xmm1, %xmm0
movq 0x8(%rax), %rax
jmp 0x8e43
movsd 0x53d1(%rip), %xmm1     # 0xe278
ucomisd 0xb9c9(%rip), %xmm1     # 0x14878
jbe 0x8ed9
ucomisd %xmm0, %xmm1
jbe 0x8ed9
movabsq $0x3da5fd7fe1796495, %rax # imm = 0x3DA5FD7FE1796495
movq %rax, 0xb9b0(%rip)      # 0x14878
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xb9a7(%rip)      # 0x14880
addq $0x38, %rsp
popq %rbx
popq %rbp
retq