// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xcc2f
testq %rax, %rax
je 0x9951
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 0x9923
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
jmp 0x9965
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcc2f
testq %rax, %rax
movapd 0x10(%rsp), %xmm5
movsd 0x8(%rsp), %xmm6
xorpd %xmm2, %xmm2
je 0x99ef
movsd (%rsp), %xmm1
divsd %xmm1, %xmm6
movapd %xmm5, %xmm0
divsd %xmm1, %xmm0
unpckhpd %xmm5, %xmm5            # xmm5 = xmm5[1,1]
divsd %xmm1, %xmm5
xorpd %xmm1, %xmm1
movapd %xmm6, %xmm2
subsd 0x20(%rax), %xmm2
movapd %xmm0, %xmm3
subsd 0x28(%rax), %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
movapd %xmm5, %xmm4
subsd 0x30(%rax), %xmm4
addsd %xmm3, %xmm2
mulsd %xmm4, %xmm4
addsd %xmm2, %xmm4
xorps %xmm2, %xmm2
sqrtsd %xmm4, %xmm2
maxsd %xmm1, %xmm2
movq 0x8(%rax), %rax
movapd %xmm2, %xmm1
testq %rax, %rax
jne 0x99a8
movsd %xmm2, 0xbe89(%rip)     # 0x15880
movq $0x0, 0xbe86(%rip) # 0x15888
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcee9
testq %rax, %rax
je 0x9a7e
movsd 0xbe6c(%rip), %xmm1     # 0x15888
movapd 0x45ec(%rip), %xmm0     # 0xe010
movsd 0x30(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9a3f
movsd %xmm2, 0xbe4d(%rip)     # 0x15888
movapd %xmm2, %xmm1
movsd 0x38(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9a5a
movsd %xmm2, 0xbe32(%rip)     # 0x15888
movapd %xmm2, %xmm1
movsd 0x40(%rax), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x9a75
movsd %xmm2, 0xbe17(%rip)     # 0x15888
movapd %xmm2, %xmm1
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x9a24
movq $0x0, 0xbe07(%rip) # 0x15890
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcee9
movsd 0xbdf2(%rip), %xmm0     # 0x15890
testq %rax, %rax
je 0x9b05
movapd 0x4565(%rip), %xmm1     # 0xe010
movsd 0x18(%rax), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x9ac6
movsd %xmm2, 0xbdce(%rip)     # 0x15890
movapd %xmm2, %xmm0
movsd 0x20(%rax), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x9ae1
movsd %xmm2, 0xbdb3(%rip)     # 0x15890
movapd %xmm2, %xmm0
movsd 0x28(%rax), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x9afc
movsd %xmm2, 0xbd98(%rip)     # 0x15890
movapd %xmm2, %xmm0
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x9aab
movsd 0x57a3(%rip), %xmm1     # 0xf2b0
ucomisd 0xbd73(%rip), %xmm1     # 0x15888
jbe 0x9b3f
ucomisd %xmm0, %xmm1
jbe 0x9b3f
movabsq $0x3da5fd7fe1796495, %rax # imm = 0x3DA5FD7FE1796495
movq %rax, 0xbd5a(%rip)      # 0x15888
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xbd51(%rip)      # 0x15890
addq $0x28, %rsp
popq %rbx
popq %rbp
retq