// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xcf07
testq %rax, %rax
je 0x9a32
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
incl %ebp
addsd 0x20(%rax), %xmm2
movupd 0x28(%rax), %xmm0
addpd %xmm0, %xmm1
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x9a05
movsd %xmm2, (%rsp)
movapd %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
jmp 0x9a45
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcf07
testq %rax, %rax
movapd 0x10(%rsp), %xmm2
movsd (%rsp), %xmm3
xorpd %xmm0, %xmm0
je 0x9b1a
movq %rax, %r14
movsd 0x8(%rsp), %xmm0
divsd %xmm0, %xmm3
movapd %xmm2, %xmm4
divsd %xmm0, %xmm4
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
divsd %xmm0, %xmm2
xorpd %xmm5, %xmm5
xorpd %xmm6, %xmm6
movapd %xmm2, 0x10(%rsp)
movsd %xmm3, (%rsp)
movapd %xmm4, 0x20(%rsp)
movapd %xmm3, %xmm1
subsd 0x20(%r14), %xmm1
movapd %xmm4, %xmm0
subsd 0x28(%r14), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd 0x30(%r14), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm5, %xmm0
jb 0x9ae3
sqrtsd %xmm0, %xmm0
jmp 0x9b09
movsd %xmm6, 0x8(%rsp)
callq 0x11b0
movsd 0x8(%rsp), %xmm6
xorpd %xmm5, %xmm5
movapd 0x20(%rsp), %xmm4
movsd (%rsp), %xmm3
movapd 0x10(%rsp), %xmm2
maxsd %xmm6, %xmm0
movq 0x8(%r14), %r14
movapd %xmm0, %xmm6
testq %r14, %r14
jne 0x9aa5
movsd %xmm0, 0xbd5e(%rip)     # 0x15880
movq $0x0, 0xbd5b(%rip) # 0x15888
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd1d1
testq %rax, %rax
je 0x9ba9
movsd 0xbd41(%rip), %xmm1     # 0x15888
movapd 0x44c1(%rip), %xmm0     # 0xe010
movsd 0x30(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9b6a
movsd %xmm2, 0xbd22(%rip)     # 0x15888
movapd %xmm2, %xmm1
movsd 0x38(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9b85
movsd %xmm2, 0xbd07(%rip)     # 0x15888
movapd %xmm2, %xmm1
movsd 0x40(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9ba0
movsd %xmm2, 0xbcec(%rip)     # 0x15888
movapd %xmm2, %xmm1
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x9b4f
movq $0x0, 0xbcdc(%rip) # 0x15890
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd1d1
testq %rax, %rax
je 0x9c30
movsd 0xbcc2(%rip), %xmm1     # 0x15890
movapd 0x443a(%rip), %xmm0     # 0xe010
movsd 0x18(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9bf1
movsd %xmm2, 0xbca3(%rip)     # 0x15890
movapd %xmm2, %xmm1
movsd 0x20(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9c0c
movsd %xmm2, 0xbc88(%rip)     # 0x15890
movapd %xmm2, %xmm1
movsd 0x28(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9c27
movsd %xmm2, 0xbc6d(%rip)     # 0x15890
movapd %xmm2, %xmm1
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x9bd6
movsd 0x5678(%rip), %xmm0     # 0xf2b0
ucomisd 0xbc48(%rip), %xmm0     # 0x15888
jbe 0x9c6e
ucomisd 0xbc46(%rip), %xmm0     # 0x15890
jbe 0x9c6e
movabsq $0x3da5fd7fe1796495, %rax # imm = 0x3DA5FD7FE1796495
movq %rax, 0xbc2b(%rip)      # 0x15888
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xbc22(%rip)      # 0x15890
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq