// File: /workspace/github_c_makefile_star2_O2/radforddc[P]icpc_siggen/icpc_fieldgen_opt.c
// Function: grid_init
int grid_init(MJD_Siggen_Setup *setup) {
  float  grid = setup->xtal_grid;
  int    L  = lrint(setup->xtal_length/grid)+3;
  int    R  = lrint(setup->xtal_radius/grid)+3;
  int    i, j;
  float  r, z;


  /* first malloc arrays in setup */
  if ((setup->impurity   = malloc(L * sizeof(*setup->impurity)))   == NULL ||
      (setup->eps        = malloc(L * sizeof(*setup->eps)))        == NULL ||
      (setup->eps_dr     = malloc(L * sizeof(*setup->eps_dr)))     == NULL ||
      (setup->eps_dz     = malloc(L * sizeof(*setup->eps_dz)))     == NULL ||
      (setup->v[0]       = malloc(L * sizeof(*setup->v[0])))       == NULL ||
      (setup->v[1]       = malloc(L * sizeof(*setup->v[1])))       == NULL ||
      (setup->dr[0]      = malloc(L * sizeof(*setup->dr[0])))      == NULL ||
      (setup->dr[1]      = malloc(L * sizeof(*setup->dr[1])))      == NULL ||
      (setup->dz[0]      = malloc(L * sizeof(*setup->dz[0])))      == NULL ||
      (setup->dz[1]      = malloc(L * sizeof(*setup->dz[1])))      == NULL ||
      (setup->undepleted = malloc(R * sizeof(*setup->undepleted))) == NULL ||
      (setup->s1         = malloc(R * sizeof(*setup->s1)))         == NULL ||
      (setup->s2         = malloc(R * sizeof(*setup->s2)))         == NULL ||
      (setup->vsave      = malloc(L * sizeof(*setup->vsave)))      == NULL ||
      (setup->point_type = malloc(L * sizeof(*setup->point_type))) == NULL) {
    printf("malloc failed\n");
    return -1;
  }
  /* start from i=1 so that i=0 can be used for reflection symmetry around r=0 or z=0 */
  for (i = 1; i < L; i++) {
    if ((setup->impurity[i]   = malloc(R * sizeof(**setup->impurity)))   == NULL ||
        (setup->v[0][i]       = malloc(R * sizeof(**setup->v[0])))       == NULL ||
	(setup->v[1][i]       = malloc(R * sizeof(**setup->v[1])))       == NULL ||
        (setup->dr[0][i]      = malloc(R * sizeof(**setup->dr[0])))      == NULL ||
	(setup->dr[1][i]      = malloc(R * sizeof(**setup->dr[1])))      == NULL ||
        (setup->dz[0][i]      = malloc(R * sizeof(**setup->dz[0])))      == NULL ||
	(setup->dz[1][i]      = malloc(R * sizeof(**setup->dz[1])))      == NULL ||
	(setup->vsave[i]      = malloc(R * sizeof(**setup->vsave)))      == NULL ||
	(setup->point_type[i] = malloc(R * sizeof(**setup->point_type))) == NULL) {
      printf("malloc failed\n");
      return -1;
    }
  }
  for (i = 1; i < L; i++) {
    if ((setup->eps[i]        = malloc(R * sizeof(**setup->eps)))    == NULL ||
        (setup->eps_dr[i]     = malloc(R * sizeof(**setup->eps_dr))) == NULL ||
        (setup->eps_dz[i]     = malloc(R * sizeof(**setup->eps_dz))) == NULL) {
      printf("malloc failed\n");
      return -1;
    }
    for (j = 0; j < R; j++)
      setup->eps[i][j] = setup->eps_dz[i][j] = setup->eps_dr[i][j] = 16.0;
  }
  for (j = 0; j < R; j++) {
    if ((setup->undepleted[j] = malloc(L * sizeof(**setup->undepleted))) == NULL) {
      printf("malloc failed\n");
      return -1;
    }
    memset(setup->undepleted[j], ' ', L);
  }

  /* set up reflection symmetry around r=0 or z=0 */
  setup->impurity[0]   = malloc(R * sizeof(**setup->impurity));
  setup->v[0][0]   = setup->v[0][2];
  setup->v[1][0]   = setup->v[1][2];
  setup->eps[0]    = setup->eps[1];
  setup->eps_dr[0] = setup->eps_dr[1];
  setup->eps_dz[0] = setup->eps_dz[1];
  setup->point_type[0] = setup->point_type[1];

  /* ------------------------------------------------------------ */
  /* weighting values for the relaxation alg. as a function of r
     in the following we divide areas and volumes by pi
     r_bin   rmax  A_top A_outside A_inside  volume  total_surf  out/top  tot/vol
     0     1/2    1/4      1         0       1/4      1.5         4        6  << special case
     1     3/2      2      3         1        2        8        3/2        4
     2     5/2      4      5         3        4       16        5/4        4
     3     7/2      6      7         5        6       24        7/6        4
     r   r+0.5     2r    2r+1      2r-1      2r       8r     (2r+1)/2r     4
     = 1+0.5/r
  */
  setup->s1[1] = 4.0;
  setup->s2[1] = 0.0;
  for (i=2; i<R; i++) {
    setup->s1[i] = 1.0 + 0.5 / (double) (i-1);   //  for r+1
    setup->s2[i] = 1.0 - 0.5 / (double) (i-1);   //  for r-1
  }
  setup->s2[1] = setup->s1[1]; // special case for reflection symm at r=0

  for (i = 1; i < L; i++) {
    for (j = 0; j < R; j++) {
      setup->dr[0][i][j] = setup->s2[j];   //  for r-1
      setup->dr[1][i][j] = setup->s1[j];   //  for r+1
      setup->dz[0][i][j] = 1;       //  for z-1
      setup->dz[1][i][j] = 1;       //  for z+1
    }
  }

  /* set up pixel point types for boundary conditions etc */
  float  d, g = 0.05 * grid, lith  = setup->Li_thickness;
  cyl_pt pt, pt1, pt2, pt3, pt4;

  setup->rmax = setup->xtal_radius - lith;
  setup->zmax = setup->xtal_length - lith;
  setup->hole_radius += lith;
  setup->hole_bullet_radius += lith;
  setup->bottom_taper_length += 0.71*lith; // add top tapers?

  for (i = 1; i < L; i++) {
    pt.z = pt3.z = pt4.z = (i-1) * grid;
    pt1.z = pt.z + g;
    pt2.z = pt.z - g;
    for (j = 1; j < R; j++) {
      pt.r = pt1.r = pt2.r = (j-1) * grid;
      pt3.r = pt.r + g;
      pt4.r = pt.r - g;
      setup->point_type[i][j] = INSIDE;

      /* see if pixel is ouside (or very nearly outside) the detector bulk */
      if (i == 1 || (pt.r >= setup->wrap_around_radius && pt.z - g < lith) ||
          outside_detector_cyl(pt1, setup) || outside_detector_cyl(pt2, setup) ||
          outside_detector_cyl(pt3, setup) || outside_detector_cyl(pt4, setup)) {

        /* check for inside ditch
           boundary condition at Ge-vacuum interface:
           epsilon0 * E_vac = espilon_Ge * E_Ge  */
        if (setup->ditch_depth > 0 && pt.z < setup->ditch_depth + grid &&
            pt.r <= setup->wrap_around_radius &&
            pt.r >= setup->wrap_around_radius - setup->ditch_thickness) {
          setup->point_type[i][j] = DITCH;
          setup->eps[i][j] = setup->eps_dz[i][j] = setup->eps_dr[i][j] = 1.0;

          /* check for inside (point) contact */
        } else if (pt.z < setup->pc_length + g && pt.r < setup->pc_radius+g) {
          setup->point_type[i][j] = PC;

        /* check for passivated area  */
        } else if (i == 1 && pt.r < setup->wrap_around_radius &&      // BEGE/ICPC
                   pt.r < setup->rmax - setup->bottom_taper_length) { // PPC
          setup->point_type[i][j] = PASSIVE;

        /* only remaining surface is HV contact */
        } else  {
          setup->point_type[i][j] = HVC;
        }
      }
    }
  }

  /* find the pixels next to the contact surfaces */
  cyl_pt dp1, dp2, dp3, dp4;
  dp1.z = dp3.r = grid;
  dp2.z = dp4.r = -grid;
  dp1.r = dp2.r = dp3.z = dp4.z = 0;
  for (i = 2; i < L-1; i++) {
    pt.z = (i-1) * grid;
    for (j = 1; j < R; j++) {
      pt.r = (j-1) * grid;
      if (setup->point_type[i][j] == INSIDE &&
          (setup->point_type[i+1][j] < INSIDE || setup->point_type[i-1][j] < INSIDE ||
           setup->point_type[i][j+1] < INSIDE || (j > 1 && setup->point_type[i][j-1] < INSIDE))) {
        setup->point_type[i][j] = CONTACT_EDGE;
        /* find distance to contact surface */
        if (setup->point_type[i+1][j] < INSIDE && (d = dist_from_contact(pt, dp1, setup)) > 0)
          setup->dz[1][i][j] = 1.0/d;
        if (setup->point_type[i-1][j] < INSIDE && (d = dist_from_contact(pt, dp2, setup)) > 0)
          setup->dz[0][i][j] = 1.0/d;
        else if (setup->point_type[i-1][j] < INSIDE &&
                 pt.r >= setup->wrap_around_radius && pt.z - grid < lith)
          setup->dz[0][i][j] = grid/(pt.z - lith);
        if (setup->point_type[i][j+1] < INSIDE && (d = dist_from_contact(pt, dp3, setup)) > 0)
          setup->dr[1][i][j] = setup->s1[j] * 1.0/d;
        if (j > 1 && setup->point_type[i][j-1] < INSIDE &&
            (d = dist_from_contact(pt, dp4, setup)) > 0)
          setup->dr[0][i][j] = setup->s2[j] * 1.0/d;
      }
    }
  }
  setup->hole_radius -= lith;
  setup->hole_bullet_radius -= lith;
  setup->bottom_taper_length -= 0.71*lith;

  /* for pixels adjacent to the ditch, set point_type to DITCH_EDGE
     and for z=0, set flag for passivated surface */
  for (i = 1; i < L; i++) {
    for (j = 1; j < R; j++) {
      setup->eps_dr[i][j-1] = (setup->eps[i][j-1] + setup->eps[i][j]) / 2.0f;
      setup->eps_dz[i-1][j] = (setup->eps[i-1][j] + setup->eps[i][j]) / 2.0f;
      if (setup->point_type[i][j] == INSIDE &&
          (setup->point_type[i-1][j] == DITCH ||
           setup->point_type[i][j-1] == DITCH ||
           setup->point_type[i][j+1] == DITCH)) setup->point_type[i][j] = DITCH_EDGE;
    }
    setup->eps_dr[i][0] = setup->eps_dr[i][1];
  }

  /* set up impurity array */
  double *imp_z, imp_ra = 0, imp_rm = 1;
  double e_over_E = 11.310; // e/epsilon; for 1 mm2, charge units 1e10 e/cm3, espilon = 16*epsilon0
  /* malloc local array */
  if ((imp_z  = malloc(L * sizeof(*imp_z))) == NULL) {
    printf("malloc failed\n");
    return -1;
  }

  if (setup->rho_z_spe[0] == 0) {
    for (i = 1; i < L; i++) {
      z = (i-1) * grid;
      imp_z[i] = e_over_E * grid*grid / 4.0 *
                 (setup->impurity_z0 +
                  setup->impurity_gradient * z * 0.1 +
                  setup->impurity_quadratic *
                  (1.0 - SQ(z - setup->xtal_length/2.0) / SQ(setup->xtal_length/2.0)));
    }
  } else if (setup->rho_z_spe[(int) setup->xtal_length] == 0) {
    printf("Error: Impurity profile spectrum is too short? rho[xtal_len = %d] = 0\n", (int) setup->xtal_length);
    return -1;
  } else {
    for (i = 1; i < L; i++)
      imp_z[i] = e_over_E * grid*grid / 4.0 * setup->rho_z_spe[(int) ((i-1) * grid)];
  }
  for (j = 1; j < R; j++) {
    r = (j-1) * grid;
    if (setup->impurity_rpower > 0.1) {
      imp_ra = setup->impurity_radial_add * e_over_E * grid*grid / 4.0 *
        pow((double) r / setup->xtal_radius, setup->impurity_rpower);
      imp_rm = 1.0 + (setup->impurity_radial_mult - 1.0f) *
        pow((double) r / setup->xtal_radius, setup->impurity_rpower);
    }
    for (i = 1; i < L; i++)  setup->impurity[i][j] = imp_z[i] * imp_rm + imp_ra;
    if (setup->point_type[1][j] == PASSIVE) {
      setup->impurity[1][j] += setup->impurity_surface * e_over_E * grid/4.0;
    }
    /* reduce charge volume for CONTACT_EDGE pixels */
    for (i = 1; i < L; i++) {
      if (setup->point_type[i][j] == CONTACT_EDGE) {
        setup->impurity[i][j] /=
          SQ(setup->dz[1][i][j]*setup->dz[0][i][j] * setup->dr[1][i][j]*setup->dr[0][i][j]);
      }
    }
  }
           
  /* free local and no-longer-needed arrays */
  free(imp_z);
  for (i = 1; i < L; i++) free(setup->eps[i]);
  free(setup->eps);

  return 0;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
movss 0x4(%rdi), %xmm0
movss 0x54(%rdi), %xmm1
movaps %xmm1, 0x20(%rsp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r13
movss 0x8(%rbx), %xmm0
divss 0x20(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %rbp
movq %r13, %rax
shlq $0x20, %rax
movabsq $0x300000000, %r14      # imm = 0x300000000
addq %rax, %r14
movq %r14, %r12
sarq $0x1d, %r12
movq %r12, %rdi
callq 0x1170
movq %rax, 0x408(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x3f0(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x3f8(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x400(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x3e0(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x3e8(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x1450(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x1458(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x1460(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x1468(%rbx)
testq %rax, %rax
je 0x2a6d
addl $0x3, %ebp
movslq %ebp, %rax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %r15
movq %r15, %rdi
callq 0x1170
movq %rax, 0x438(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r15, %rdi
callq 0x1170
movq %rax, 0x418(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r15, %rdi
callq 0x1170
movq %rax, 0x420(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x428(%rbx)
testq %rax, %rax
je 0x2a6d
movq %r12, %rdi
callq 0x1170
movq %rax, 0x430(%rbx)
testq %rax, %rax
je 0x2a6d
sarq $0x20, %r14
movq %r15, (%rsp)
pushq $0x1
popq %r15
cmpq %r14, %r15
jge 0x2a8e
movq (%rsp), %rdi
callq 0x1170
movq 0x408(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x3e0(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x3e8(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x1450(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x1458(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x1460(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x1468(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x428(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq 0x10(%rsp), %rdi
callq 0x1170
movq 0x430(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
testq %rax, %rax
jne 0x296b
leaq 0x65eb(%rip), %rdi      # 0x905f
callq 0x1070
pushq $-0x1
popq %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testl %ebp, %ebp
cmovlel %eax, %ebp
pushq $0x1
popq %r15
cmpq %r14, %r15
jge 0x2b38
movq (%rsp), %rdi
callq 0x1170
movq 0x3f0(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x3f8(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq (%rsp), %rdi
callq 0x1170
movq 0x400(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
xorl %eax, %eax
movabsq $0x4030000000000000, %rdx # imm = 0x4030000000000000
cmpq %rax, %rbp
je 0x2b30
movq 0x3f8(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movq %rdx, (%rcx,%rax,8)
movq 0x400(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movq %rdx, (%rcx,%rax,8)
movq 0x3f0(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movq %rdx, (%rcx,%rax,8)
incq %rax
jmp 0x2af9
incq %r15
jmp 0x2a99
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x2b77
movq %r14, %rdi
callq 0x1170
movq 0x438(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x2a6d
movq 0x438(%rbx), %rax
movq (%rax,%r15,8), %rdi
pushq $0x20
popq %rsi
movq %r14, %rdx
callq 0x1110
incq %r15
jmp 0x2b3b
movq (%rsp), %rdi
callq 0x1170
movq 0x408(%rbx), %rcx
movq %rax, (%rcx)
movq 0x3e0(%rbx), %rax
movq 0x10(%rax), %rcx
movq %rcx, (%rax)
movq 0x3e8(%rbx), %rax
movq 0x10(%rax), %rcx
movq %rcx, (%rax)
movq 0x3f0(%rbx), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%rax)
movq 0x3f8(%rbx), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%rax)
movq 0x400(%rbx), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%rax)
movq 0x430(%rbx), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%rax)
movq 0x418(%rbx), %rax
movabsq $0x4010000000000000, %rcx # imm = 0x4010000000000000
movq %rcx, 0x8(%rax)
movq 0x420(%rbx), %rcx
andq $0x0, 0x8(%rcx)
pushq $0x2
popq %rdx
movsd 0x5466(%rip), %xmm3     # 0x8070
movq 0x10(%rsp), %rdi
movsd 0x5449(%rip), %xmm2     # 0x8060
cmpq %rdi, %rdx
jge 0x2c46
leal -0x1(%rdx), %esi
cvtsi2sd %esi, %xmm0
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
addsd %xmm2, %xmm1
movsd %xmm1, (%rax,%rdx,8)
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
jmp 0x2c17
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rcx)
pushq $0x1
popq %rdx
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
cmpq %r14, %rdx
jge 0x2cbb
xorl %esi, %esi
cmpq %rsi, %rbp
je 0x2cb6
movsd (%rcx,%rsi,8), %xmm0
movq 0x1450(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
movsd %xmm0, (%rdi,%rsi,8)
movsd (%rax,%rsi,8), %xmm0
movq 0x1458(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
movsd %xmm0, (%rdi,%rsi,8)
movq 0x1460(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
movq %r8, (%rdi,%rsi,8)
movq 0x1468(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
movq %r8, (%rdi,%rsi,8)
incq %rsi
jmp 0x2c64
incq %rdx
jmp 0x2c5d
movaps 0x20(%rsp), %xmm4
cvtss2sd %xmm4, %xmm1
movsd 0x53b4(%rip), %xmm0     # 0x8080
movsd %xmm1, 0x60(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm3
movss 0x4c(%rbx), %xmm2
movss 0x4(%rbx), %xmm0
movss 0x8(%rbx), %xmm1
subss %xmm2, %xmm1
movss %xmm1, 0x3b4(%rbx)
subss %xmm2, %xmm0
movss %xmm0, 0x3c0(%rbx)
movss 0x28(%rbx), %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x28(%rbx)
movss 0x48(%rbx), %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x48(%rbx)
movss %xmm2, 0x1c(%rsp)
cvtss2sd %xmm2, %xmm2
cvtss2sd 0x20(%rbx), %xmm0
movsd 0x5354(%rip), %xmm1     # 0x8088
movsd %xmm2, 0xb0(%rsp)
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x20(%rbx)
pushq $0x1
popq %rbp
xorps %xmm1, %xmm1
movq 0x10(%rsp), %r9
movss %xmm3, 0x18(%rsp)
cmpq %r14, %rbp
jge 0x308d
leal -0x1(%rbp), %eax
cvtsi2ss %eax, %xmm9
mulss %xmm4, %xmm9
movaps %xmm9, %xmm0
addss %xmm3, %xmm0
movss %xmm0, 0x8c(%rsp)
movaps %xmm9, %xmm0
subss %xmm3, %xmm0
movss %xmm0, 0x68(%rsp)
pushq $0x1
popq %r15
movss %xmm9, 0x38(%rsp)
cmpq %r9, %r15
jge 0x3085
leal -0x1(%r15), %eax
cvtsi2ss %eax, %xmm10
mulss %xmm4, %xmm10
movss %xmm10, %xmm7           # xmm7 = xmm10[0],xmm7[1,2,3]
movss %xmm10, %xmm8           # xmm8 = xmm10[0],xmm8[1,2,3]
movaps %xmm10, %xmm0
addss %xmm3, %xmm0
movss %xmm0, %xmm6            # xmm6 = xmm0[0],xmm6[1,2,3]
movaps %xmm10, %xmm0
subss %xmm3, %xmm0
movss %xmm0, %xmm2            # xmm2 = xmm0[0],xmm2[1,2,3]
movq 0x430(%rbx), %rax
movq (%rax,%rbp,8), %rax
movb $0x2, (%rax,%r15)
cmpq $0x1, %rbp
je 0x2f8b
ucomiss 0x14(%rbx), %xmm10
jb 0x2e0a
movss 0x1c(%rsp), %xmm0
ucomiss 0x68(%rsp), %xmm0
ja 0x2f8b
movaps %xmm8, %xmm0
movss 0x8c(%rsp), %xmm1
movq %rbx, %rdi
movaps %xmm5, (%rsp)
movaps %xmm2, 0x40(%rsp)
movaps %xmm6, 0x50(%rsp)
movaps %xmm7, 0xa0(%rsp)
movaps %xmm8, 0x70(%rsp)
movaps %xmm10, 0x90(%rsp)
callq 0x7368
movaps 0x90(%rsp), %xmm10
movss 0x38(%rsp), %xmm9
movaps 0x70(%rsp), %xmm8
movaps 0xa0(%rsp), %xmm7
movaps 0x50(%rsp), %xmm6
movaps 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
movss 0x18(%rsp), %xmm3
movaps (%rsp), %xmm5
movq 0x10(%rsp), %r9
movaps 0x20(%rsp), %xmm4
testl %eax, %eax
jne 0x2f8b
movaps %xmm7, %xmm0
movss 0x68(%rsp), %xmm1
movq %rbx, %rdi
callq 0x7368
movaps 0x90(%rsp), %xmm10
movss 0x38(%rsp), %xmm9
movaps 0x70(%rsp), %xmm8
movaps 0xa0(%rsp), %xmm7
movaps 0x50(%rsp), %xmm6
movaps 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
movss 0x18(%rsp), %xmm3
movaps (%rsp), %xmm5
movq 0x10(%rsp), %r9
movaps 0x20(%rsp), %xmm4
testl %eax, %eax
jne 0x2f8b
movaps %xmm6, %xmm0
movaps %xmm9, %xmm1
movq %rbx, %rdi
callq 0x7368
movaps 0x90(%rsp), %xmm10
movss 0x38(%rsp), %xmm9
movaps 0x70(%rsp), %xmm8
movaps 0xa0(%rsp), %xmm7
movaps 0x50(%rsp), %xmm6
movaps 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
movss 0x18(%rsp), %xmm3
movaps (%rsp), %xmm5
movq 0x10(%rsp), %r9
movaps 0x20(%rsp), %xmm4
testl %eax, %eax
jne 0x2f8b
movaps %xmm2, %xmm0
movaps %xmm9, %xmm1
movq %rbx, %rdi
callq 0x7368
movaps 0x90(%rsp), %xmm10
movss 0x38(%rsp), %xmm9
movaps 0x70(%rsp), %xmm8
movaps 0xa0(%rsp), %xmm7
movaps 0x50(%rsp), %xmm6
movaps 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
movss 0x18(%rsp), %xmm3
movaps (%rsp), %xmm5
movq 0x10(%rsp), %r9
movaps 0x20(%rsp), %xmm4
testl %eax, %eax
je 0x302f
movss 0x18(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2fb9
addss %xmm4, %xmm0
ucomiss %xmm9, %xmm0
jbe 0x2fb9
movss 0x14(%rbx), %xmm0
ucomiss %xmm10, %xmm0
jb 0x2fb9
subss 0x1c(%rbx), %xmm0
ucomiss %xmm0, %xmm10
jae 0x303c
movss 0xc(%rbx), %xmm0
addss %xmm3, %xmm0
ucomiss %xmm9, %xmm0
jbe 0x2fe9
movss 0x10(%rbx), %xmm0
addss %xmm3, %xmm0
ucomiss %xmm10, %xmm0
jbe 0x2fe9
movq 0x430(%rbx), %rax
movq (%rax,%rbp,8), %rax
movb $0x0, (%rax,%r15)
jmp 0x302f
cmpq $0x1, %rbp
jne 0x301f
movss 0x14(%rbx), %xmm0
ucomiss %xmm10, %xmm0
jbe 0x301f
movss 0x3b4(%rbx), %xmm0
subss 0x20(%rbx), %xmm0
ucomiss %xmm10, %xmm0
jbe 0x301f
movq 0x430(%rbx), %rax
movq 0x8(%rax), %rax
movb $0x3, (%rax,%r15)
jmp 0x302f
movq 0x430(%rbx), %rax
movq (%rax,%rbp,8), %rax
movb $0x1, (%rax,%r15)
movss %xmm10, %xmm5           # xmm5 = xmm10[0],xmm5[1,2,3]
incq %r15
jmp 0x2d9f
movq 0x430(%rbx), %rax
movq (%rax,%rbp,8), %rax
movb $0x5, (%rax,%r15)
movq 0x3f8(%rbx), %rax
movq (%rax,%rbp,8), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax,%r15,8)
movq 0x400(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rcx, (%rax,%r15,8)
movq 0x3f0(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rcx, (%rax,%r15,8)
jmp 0x302f
incq %rbp
jmp 0x2d5f
movaps 0x50bc(%rip), %xmm0     # 0x8150
xorps %xmm4, %xmm0
movaps %xmm0, 0x70(%rsp)
addl $0x2, %r13d
movslq %r13d, %rax
movq %rax, 0x38(%rsp)
pushq $0x2
popq %r13
cmpq 0x38(%rsp), %r13
jge 0x3392
leal -0x1(%r13), %eax
cvtsi2ss %eax, %xmm0
mulss %xmm4, %xmm0
leaq 0x1(%r13), %rax
movq %rax, 0x40(%rsp)
movaps %xmm0, %xmm1
subss %xmm4, %xmm1
movss %xmm1, 0x90(%rsp)
movss %xmm0, 0x50(%rsp)
subss 0x1c(%rsp), %xmm0
movaps %xmm4, %xmm1
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
xorl %ebp, %ebp
movq %rbp, %r15
incq %rbp
cmpq %r9, %rbp
jge 0x3388
cvtsi2ss %r15d, %xmm0
mulss %xmm4, %xmm0
movss %xmm0, %xmm5            # xmm5 = xmm0[0],xmm5[1,2,3]
movq 0x430(%rbx), %rcx
movq (%rcx,%r13,8), %rax
cmpb $0x2, 0x1(%rax,%r15)
jne 0x30fb
movq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
cmpb $0x2, 0x1(%rdx,%r15)
jl 0x3154
movq -0x8(%rcx,%r13,8), %rcx
cmpb $0x2, 0x1(%rcx,%r15)
jl 0x3154
cmpb $0x2, 0x2(%rax,%r15)
jge 0x336e
movaps %xmm0, 0xa0(%rsp)
movb $0x7, 0x1(%rax,%r15)
movq 0x430(%rbx), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpb $0x1, 0x1(%rax,%r15)
movaps %xmm5, (%rsp)
jg 0x31c9
xorps %xmm2, %xmm2
movaps %xmm5, %xmm0
movss 0x50(%rsp), %xmm1
movaps %xmm4, %xmm3
movq %rbx, %rdi
callq 0x4eb3
movaps (%rsp), %xmm5
movaps 0x20(%rsp), %xmm4
ucomiss 0x4f97(%rip), %xmm0     # 0x813c
jbe 0x31c9
cvtss2sd %xmm0, %xmm0
movsd 0x4ead(%rip), %xmm1     # 0x8060
divsd %xmm0, %xmm1
movq 0x1468(%rbx), %rax
movq (%rax,%r13,8), %rax
movsd %xmm1, 0x8(%rax,%r15,8)
movq 0x430(%rbx), %rax
movq -0x8(%rax,%r13,8), %rcx
cmpb $0x1, 0x1(%rcx,%r15)
jg 0x328a
xorps %xmm2, %xmm2
movaps %xmm5, %xmm0
movss 0x50(%rsp), %xmm1
movaps 0x70(%rsp), %xmm3
movq %rbx, %rdi
callq 0x4eb3
ucomiss 0x4f3b(%rip), %xmm0     # 0x813c
jbe 0x3237
cvtss2sd %xmm0, %xmm0
movsd 0x4e51(%rip), %xmm1     # 0x8060
divsd %xmm0, %xmm1
movq 0x1460(%rbx), %rax
movq (%rax,%r13,8), %rax
movsd %xmm1, 0x8(%rax,%r15,8)
movq 0x430(%rbx), %rax
movaps 0x20(%rsp), %xmm4
movaps (%rsp), %xmm5
jmp 0x328a
movq 0x430(%rbx), %rax
movq -0x8(%rax,%r13,8), %rcx
cmpb $0x1, 0x1(%rcx,%r15)
movaps 0x20(%rsp), %xmm4
movaps (%rsp), %xmm5
jg 0x328a
movaps 0xa0(%rsp), %xmm0
ucomiss 0x14(%rbx), %xmm0
jb 0x328a
movss 0x1c(%rsp), %xmm0
ucomiss 0x90(%rsp), %xmm0
jbe 0x328a
movq 0x1460(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x8(%rcx,%r15,8)
movq (%rax,%r13,8), %rax
cmpb $0x1, 0x2(%rax,%r15)
jg 0x32e7
xorps %xmm3, %xmm3
movaps %xmm5, %xmm0
movss 0x50(%rsp), %xmm1
movaps %xmm4, %xmm2
movq %rbx, %rdi
callq 0x4eb3
movaps (%rsp), %xmm5
movaps 0x20(%rsp), %xmm4
ucomiss 0x4e7f(%rip), %xmm0     # 0x813c
jbe 0x32e7
movq 0x418(%rbx), %rax
movsd 0x8(%rax,%r15,8), %xmm1
cvtss2sd %xmm0, %xmm0
divsd %xmm0, %xmm1
movq 0x1458(%rbx), %rax
movq (%rax,%r13,8), %rax
movsd %xmm1, 0x8(%rax,%r15,8)
cmpq $0x2, %rbp
movq 0x10(%rsp), %r9
jb 0x30fb
movq 0x430(%rbx), %rax
movq (%rax,%r13,8), %rax
cmpb $0x1, (%rax,%r15)
jg 0x30fb
xorps %xmm3, %xmm3
movaps %xmm5, %xmm0
movss 0x50(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
movq %rbx, %rdi
callq 0x4eb3
movaps (%rsp), %xmm5
movq 0x10(%rsp), %r9
movaps 0x20(%rsp), %xmm4
ucomiss 0x4e01(%rip), %xmm0     # 0x813c
jbe 0x30fb
movq 0x420(%rbx), %rax
movsd 0x8(%rax,%r15,8), %xmm1
cvtss2sd %xmm0, %xmm0
divsd %xmm0, %xmm1
movq 0x1450(%rbx), %rax
movq (%rax,%r13,8), %rax
movsd %xmm1, 0x8(%rax,%r15,8)
jmp 0x30fb
cmpq $0x2, %rbp
jb 0x30fb
cmpb $0x1, (%rax,%r15)
jg 0x30fb
jmp 0x3154
movq 0x40(%rsp), %r13
jmp 0x30ac
movss 0x28(%rbx), %xmm0
movss 0x48(%rbx), %xmm1
movss 0x1c(%rsp), %xmm2
subss %xmm2, %xmm0
movss %xmm0, 0x28(%rbx)
subss %xmm2, %xmm1
movss %xmm1, 0x48(%rbx)
cvtss2sd 0x20(%rbx), %xmm0
movsd 0xb0(%rsp), %xmm1
mulsd 0x4cc6(%rip), %xmm1     # 0x8090
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x20(%rbx)
pushq $0x1
popq %rax
movq %rax, %rcx
movsd 0x4c8b(%rip), %xmm1     # 0x8070
cmpq %r14, %rcx
jge 0x349c
movq %rax, %rdx
cmpq %r9, %rdx
jge 0x3480
movq 0x3f0(%rbx), %rsi
movq (%rsi,%rcx,8), %rdi
movsd -0x8(%rdi,%rdx,8), %xmm0
addsd (%rdi,%rdx,8), %xmm0
movq 0x3f8(%rbx), %r8
mulsd %xmm1, %xmm0
movq (%r8,%rcx,8), %r8
movsd %xmm0, -0x8(%r8,%rdx,8)
movq -0x8(%rsi,%rcx,8), %rsi
movsd (%rsi,%rdx,8), %xmm0
addsd (%rdi,%rdx,8), %xmm0
mulsd %xmm1, %xmm0
movq 0x400(%rbx), %rsi
movq -0x8(%rsi,%rcx,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
movq 0x430(%rbx), %rdi
movq (%rdi,%rcx,8), %rsi
cmpb $0x2, (%rsi,%rdx)
jne 0x3478
movq -0x8(%rdi,%rcx,8), %rdi
cmpb $0x5, (%rdi,%rdx)
je 0x3474
cmpb $0x5, -0x1(%rsi,%rdx)
je 0x3474
cmpb $0x5, 0x1(%rsi,%rdx)
jne 0x3478
movb $0x6, (%rsi,%rdx)
incq %rdx
jmp 0x33f1
movq 0x3f8(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd 0x8(%rdx), %xmm0
movsd %xmm0, (%rdx)
incq %rcx
jmp 0x33e5
movq %r12, %rdi
callq 0x1170
testq %rax, %rax
je 0x2a6d
movq %rax, %r15
movss 0x44c(%rbx), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jne 0x3574
jp 0x3574
movsd 0x4bc6(%rip), %xmm0     # 0x8098
movsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd 0x4bb8(%rip), %xmm0     # 0x80a0
pushq $0x1
popq %rax
movsd 0x4b35(%rip), %xmm1     # 0x8028
movsd 0x4b65(%rip), %xmm2     # 0x8060
movaps 0x20(%rsp), %xmm7
movsd 0x4b67(%rip), %xmm8     # 0x8070
cmpq %r14, %rax
jge 0x35f4
leal -0x1(%rax), %ecx
cvtsi2ss %ecx, %xmm3
cvtss2sd 0x58(%rbx), %xmm4
mulss %xmm7, %xmm3
cvtss2sd %xmm3, %xmm5
mulss 0x5c(%rbx), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
cvtss2sd 0x60(%rbx), %xmm4
cvtss2sd 0x4(%rbx), %xmm6
mulsd %xmm8, %xmm6
subsd %xmm6, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm6, %xmm6
divsd %xmm6, %xmm5
movaps %xmm2, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm4, %xmm6
addsd %xmm3, %xmm6
mulsd %xmm0, %xmm6
movsd %xmm6, (%r15,%rax,8)
incq %rax
jmp 0x3509
cvttss2si 0x4(%rbx), %esi
movslq %esi, %rax
movss 0x44c(%rbx,%rax,4), %xmm1
ucomiss %xmm0, %xmm1
jne 0x359f
jp 0x359f
leaq 0x59ea(%rip), %rdi      # 0x8f7d
xorl %eax, %eax
callq 0x10f0
jmp 0x2a79
movsd 0x4af1(%rip), %xmm0     # 0x8098
movsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd 0x4ae3(%rip), %xmm0     # 0x80a0
pushq $0x1
popq %rax
movaps 0x20(%rsp), %xmm2
cmpq %r14, %rax
jge 0x35f4
leal -0x1(%rax), %ecx
cvtsi2ss %ecx, %xmm1
mulss %xmm2, %xmm1
cvttss2si %xmm1, %ecx
movslq %ecx, %rcx
cvtss2sd 0x44c(%rbx,%rcx,4), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r15,%rax,8)
incq %rax
jmp 0x35c5
xorpd %xmm6, %xmm6
pushq $0x1
popq %r12
movsd 0x4a24(%rip), %xmm3     # 0x8028
movsd 0x4a8c(%rip), %xmm4     # 0x8098
movsd 0x4a8c(%rip), %xmm5     # 0x80a0
movq %r12, %r13
movsd 0x4a41(%rip), %xmm0     # 0x8060
movq 0x10(%rsp), %rsi
cmpq %rsi, %r13
jge 0x37d9
cvtss2sd 0x70(%rbx), %xmm1
ucomisd %xmm3, %xmm1
jbe 0x36ee
leal -0x1(%r13), %eax
cvtsi2ss %eax, %xmm0
mulss 0x20(%rsp), %xmm0
cvtss2sd 0x68(%rbx), %xmm3
mulsd %xmm4, %xmm3
movsd 0x60(%rsp), %xmm2
mulsd %xmm2, %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm5, %xmm3
movsd %xmm3, 0x40(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rsp)
cvtss2sd 0x8(%rbx), %xmm2
divsd %xmm2, %xmm0
callq 0x10b0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movss 0x6c(%rbx), %xmm0
addss 0x4aa5(%rip), %xmm0     # 0x8140
cvtss2sd 0x8(%rbx), %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
cvtss2sd 0x70(%rbx), %xmm1
callq 0x10b0
movsd 0x40(%rsp), %xmm6
movsd 0x49d5(%rip), %xmm5     # 0x80a0
movsd 0x49c5(%rip), %xmm4     # 0x8098
movsd 0x494d(%rip), %xmm3     # 0x8028
movq 0x10(%rsp), %rsi
mulsd 0x50(%rsp), %xmm0
addsd 0x4972(%rip), %xmm0     # 0x8060
movq %r12, %rax
cmpq %r14, %rax
jge 0x371a
movsd (%r15,%rax,8), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm6, %xmm1
movq 0x408(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
movsd %xmm1, (%rcx,%r13,8)
incq %rax
jmp 0x36f1
movq 0x430(%rbx), %rax
movq 0x8(%rax), %rcx
cmpb $0x3, (%rcx,%r13)
jne 0x3756
cvtss2sd 0x64(%rbx), %xmm1
mulsd %xmm4, %xmm1
mulsd 0x60(%rsp), %xmm1
mulsd %xmm5, %xmm1
movq 0x408(%rbx), %rcx
movq 0x8(%rcx), %rcx
addsd (%rcx,%r13,8), %xmm1
movsd %xmm1, (%rcx,%r13,8)
movq %r12, %rcx
cmpq %r14, %rcx
jge 0x37d1
movq (%rax,%rcx,8), %rdx
cmpb $0x7, (%rdx,%r13)
jne 0x37cc
movq 0x1468(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd (%rdx,%r13,8), %xmm1
movq 0x1460(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
mulsd (%rdx,%r13,8), %xmm1
movq 0x1458(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
mulsd (%rdx,%r13,8), %xmm1
movq 0x1450(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
mulsd (%rdx,%r13,8), %xmm1
mulsd %xmm1, %xmm1
movq 0x408(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd (%rdx,%r13,8), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, (%rdx,%r13,8)
incq %rcx
jmp 0x3759
incq %r13
jmp 0x3624
movq %r15, %rdi
callq 0x1030
pushq $0x1
popq %r15
movq 0x3f0(%rbx), %rdi
cmpq %r14, %r15
jge 0x37ff
movq (%rdi,%r15,8), %rdi
callq 0x1030
incq %r15
jmp 0x37e5
callq 0x1030
xorl %eax, %eax
jmp 0x2a7c