// File: /workspace/github_c_makefile_star2_O1/radforddc[P]icpc_siggen/mjd_fieldgen.c
// Function: main
int main(int argc, char **argv)
{

  MJD_Siggen_Setup setup, setup1, setup2;

  float BV;      // bias voltage
  int   WV = 0;  // 0: do not write the V and E values to ppc_ev.dat
                 // 1: write the V and E values to ppc_ev.dat
                 // 2: write the V and E values for both +r, -r (for gnuplot, NOT for siggen)
  int   WD = 0;  // 0: do not write out depletion surface
                 // 1: write out depletion surface to depl_<HV>.dat

  int   i, j, k;
  FILE  *fp;


  if (argc < 2 || argc%2 != 0 || read_config(argv[1], &setup)) {
    printf("Usage: %s <config_file_name> [options]\n"
           "   Possible options:\n"
	   "      -b bias_volts\n"
	   "      -w {0,1}  (do_not/do write the field file)\n"
	   "      -d {0,1}  (do_not/do write the depletion surface)\n"
	   "      -p {0,1}  (do_not/do write the WP file)\n"
           "      -r rho_spectrum_file_name\n"
           "      -z <rho_spectrum_offset_mm>\n", argv[0]);
    return 1;
  }
  strncpy(setup.config_file_name, argv[1], sizeof(setup.config_file_name));

  if (setup.xtal_grid < 0.001) setup.xtal_grid = 0.5;
  BV = setup.xtal_HV;
  WV = setup.write_field;
  setup.rho_z_spe[0] = 0;

  for (i=2; i<argc-1; i++) {
    if (strstr(argv[i], "-b")) {
      BV = setup.xtal_HV = atof(argv[++i]);   // bias volts
    } else if (strstr(argv[i], "-w")) {
      WV = atoi(argv[++i]);               // write-out options
    } else if (strstr(argv[i], "-d")) {
      WD = atoi(argv[++i]);               // write-out options
    } else if (strstr(argv[i], "-p")) {
      setup.write_WP = atoi(argv[++i]);   // weighting-potential options
    } else if (strstr(argv[i], "-r")) {
      if (!(fp = fopen(argv[++i], "r"))) {   // impurity-profile-spectrum file name
        printf("\nERROR: cannot open impurity profile spectrum file %s\n\n", argv[i]);
        return 1;
      }
      if (strstr(argv[i], ".spe")) fread(setup.rho_z_spe, 36, 1, fp); // skip over .spe-format header
      for (j=0; j<1024; j++) setup.rho_z_spe[j] = 0;
      fread(setup.rho_z_spe, sizeof(setup.rho_z_spe), 1, fp);
      fclose(fp);
    } else if (strstr(argv[i], "-z")) {
      j = atoi(argv[++i]);
      if (j >= 199) {
        printf("Error; rho_spectrum_offset_mm = %d is too large! max = 200\n", j);
        return 1;
      }
      for (k=j; k <200; k++) setup.rho_z_spe[k-j] = setup.rho_z_spe[k];
    } else if (strstr(argv[i], "-g") || strstr(argv[i], "-o")) { // ignore these
      continue;
    } else {
      printf("Possible options:\n"
	     "      -b bias_volts\n"
	     "      -w {0,1,2} (for WV options)\n"
	     "      -p {0,1}   (for WP options)\n"
             "      -r rho_spectrum_file_name\n"
             "      -z <rho_spectrum_offset_mm>\n");
      return 1;
    }
  }

  if (setup.inner_taper_length > setup.hole_length) {
    setup.inner_taper_length = setup.hole_length;
    printf(" Warning: inner_taper_length limited to hole_length = %.1f\n", setup.hole_length);
  }

  if (setup.verbosity >= CHATTY && setup.rho_z_spe[0] != 0) {
    printf(" z(mm)   rho\n");
    for (j=0; j < (int) setup.xtal_length; j++)
      printf(" %3d  %7.3f\n", j, setup.rho_z_spe[j]);
  }

  if (setup.xtal_length/setup.xtal_grid * setup.xtal_radius/setup.xtal_grid > 2500*2500) {
    printf("Error: Crystal size divided by grid size is too large!\n");
    return 1;
  }
  if (WV < 0 || WV > 2) WV = 0;

  /* -------------- give details of detector geometry */
  if (setup.verbosity >= CHATTY) {
    printf("\n\n"
           "      Crystal: Radius x Length: %.1f x %.1f mm\n",
	   setup.xtal_radius, setup.xtal_length);
    if (setup.hole_length > 0) {
      if (setup.inner_taper_length > 0)
        printf("    Core hole: Radius x length: %.1f x %.1f mm,"
               " taper %.1f x %.1f mm (%2.f degrees)\n",
               setup.hole_radius, setup.hole_length,
               setup.inner_taper_width, setup.inner_taper_length, setup.taper_angle);
      else
        printf("    Core hole: Radius x length: %.1f x %.1f mm\n",
               setup.hole_radius, setup.hole_length);
    }
    printf("Point contact: Radius x length: %.1f x %.1f mm\n",
           setup.pc_radius, setup.pc_length);
    if (setup.ditch_depth > 0) {
      printf("  Wrap-around: Radius x ditch x gap:  %.1f x %.1f x %.1f mm\n",
             setup.wrap_around_radius, setup.ditch_depth, setup.ditch_thickness);
    }
    printf("         Bias: %.0f V\n", BV);
  }
    
  if ((BV < 0 && setup.impurity_z0 < 0) || (BV > 0 && setup.impurity_z0 > 0)) {
    printf("ERROR: Expect bias and impurity to be opposite sign!\n");
    return 1;
  } 
  if (setup.impurity_z0 > 0) {
    // swap polarity for n-type material; this lets me assume all voltages are positive
    BV = -BV;
    setup.xtal_HV *= -1.0;
    setup.impurity_z0         *= -1.0;
    setup.impurity_gradient   *= -1.0;
    setup.impurity_quadratic  *= -1.0;
    setup.impurity_surface    *= -1.0;
    setup.impurity_radial_add *= -1.0;
  }
  /* use an adaptive grid; start out coarse and then refine the grid */
  memcpy(&setup1, &setup, sizeof(setup));
  memcpy(&setup2, &setup, sizeof(setup));
  setup1.xtal_grid *= 9.0;
  setup2.xtal_grid *= 3.0;
  if (grid_init(&setup1) != 0 ||
      grid_init(&setup2) != 0 ||
      grid_init(&setup)  != 0) {
    printf("failed to init field calculations\n");
    return 1;
  }

  /* -------------- calculate electric potential/field */
  if (setup.write_field) {
    setup1.write_field = 0; // no need to save intermediate calculations
    setup2.write_field = 0;
    if (setup.xtal_grid > 0.4) {
      ev_calc(&setup2, NULL);
    } else {
      ev_calc(&setup1, NULL);
      ev_calc(&setup2, &setup1);
    }
    ev_calc(&setup, &setup2);
  }

  /* -------------- calculate weighting potential */
  if (setup.write_WP) {
    setup1.write_WP = 0; // no need to save intermediate calculations
    setup2.write_WP = 0;
    if (setup.xtal_grid > 0.4) {
      wp_calc(&setup2, NULL);
    } else {
      wp_calc(&setup1, NULL);
      wp_calc(&setup2, &setup1);
    }
    wp_calc(&setup, &setup2);
  }

  /* -------------- calculate capacitance
     1/2 * epsilon * integral(E^2) = 1/2 * C * V^2
     so    C = epsilon * integral(E^2) / V^2    V = 1 volt
  */
  double esum, esum2, pi=3.14159, Epsilon=(8.85*16.0/1000.0);  // permittivity of Ge in pF/mm
  float  E_r, E_z;
  float  grid = setup.xtal_grid;
  int    r, z, test;
  int    L  = lrint(setup.xtal_length/grid)+1;
  int    R  = lrint(setup.xtal_radius/grid)+1;
  int    LC = lrint(setup.pc_length/grid)+1;
  int    RC = lrint(setup.pc_radius/grid)+1;

  if (setup.write_WP) {
    esum = esum2 = test = 0;
    for (z=1; z<L; z++) {
      for (r=2; r<R; r++) {
        E_r = setup.eps_dr[z][r]/16.0 * (setup.v[1][z][r] - setup.v[1][z][r+1])/(0.1*grid);
        E_z = setup.eps_dz[z][r]/16.0 * (setup.v[1][z][r] - setup.v[1][z+1][r])/(0.1*grid);
        esum += (E_r*E_r + E_z*E_z) * (double) (r-1);
        if ((r == RC   && z <= LC)   || (r <= RC   && z == LC)   ||
            (r == RC+1 && z <= LC+1) || (r <= RC+1 && z == LC+1)) { // average over two different surfaces
          if (setup.point_type[z+1][r+1] == PC) test = 1;
          esum2 += 0.5 * sqrt(E_r*E_r + E_z*E_z) * (double) (r-1);  // 0.5 since averaging over 2 surfaces
        }
      }
    }
    esum  *= 2.0 * pi * 0.01 * Epsilon * pow(grid, 3.0);
    // Epsilon is in pF/mm
    // 0.01 converts (V/cm)^2 to (V/mm)^2, pow() converts to grid^3 to mm3
    esum2 *= 2.0 * pi * 0.1 * Epsilon * pow(grid, 2.0);
    // 0.1 converts (V/cm) to (V/mm),  grid^2 to  mm2
    printf("  >>  Calculated capacitance at %.0f V: %.3lf pF\n", BV, esum);
    if (!test)
      printf("  >>  Alternative calculation of capacitance: %.3lf pF\n", esum2);
  }

  /* -------------- estimate depletion voltage */
  double min = BV, min2 = BV, dV, dW, testv;
  int    vminr=0, vminz=0;
  int    dz[4] = {1, -1, 0, 0}, dr[4] = {0, 0, 1, -1};
  if (setup.write_WP) {
    if (setup.fully_depleted) {
      // find minimum potential
      for (z=1; z<LC+2; z++) {
        for (r=1; r<RC+2; r++) {
          if (setup.vsave[z][r] > 0 &&
              min > setup.vsave[z][r] / (1.0 - setup.v[1][z][r])) {
            min = setup.vsave[z][r] / (1.0 - setup.v[1][z][r]);
          }
        }
      }
      /* check for bubble depletion / pinch-off by seeing how much the bias
         must be reduced for any pixel to be in a local potential minimum  */
      for (z=LC+2; z<L-2; z++) {
        for (r=1; r<R-2; r++) {
          if (setup.point_type[z][r] == INSIDE && setup.v[1][z][r] > 0.0001) {
            testv = -1;
            for (i=0; i<4; i++) {
              if (r==1 && i==2) break;  // do not check dr for r=1 (=0.0)
              dV = setup.vsave[z+dz[i]][r+dr[i]]  - setup.vsave[z][r];  // potential
              dW = setup.v[1][z+dz[i]][r+dr[i]]   - setup.v[1][z][r];   // WP
              if (dW*grid > 0.00001 && dV < 0 && testv < -dV/dW) testv = -dV/dW;
            }
            if (testv >= 0 && min2 > testv) {
              min2 = testv;
              vminr = r; vminz = z;
            }
          }
        }
      }
      if (min2 < min) {
        printf("Estimated pinch-off voltage = %.0f V\n", BV - min);
        printf(" min2 = %.1f at (r,z) = (%.1f, %.1f), so\n",
               min2, (vminr-1)*grid, (vminz-1)*grid);
        printf("   Full depletion (max pinch-off voltage) = %.0f\n", BV - min2);
        min = min2;
      } else {
        printf("Estimated depletion voltage = %.0f V\n", BV - min);
      }
    }

    printf("Minimum bulk field = %.2f V/cm at (r,z) = (%.1f, %.1f) mm\n\n",
           setup.Emin, setup.rmin, setup.zmin);
  }

#ifdef EMIN_OVERBIAS
  // calculate a new minimum electric field at a specified bias above depletion (usually 500 V)

  if (min > 0) {
    double db = EMIN_OVERBIAS - min;
    int k = 3.0/grid;
    float E, ez, er, r, z;
    // adjust potential
    for (j = 1; j < R; j++) {
      for (i = 1; i < L; i++) {
        setup.vsave[i][j] -= db * setup.v[1][i][j];
      }
    }
    setup.Emin = 99999.9;
    setup.rmin = setup.zmin = 999.9;
    /* calculate new field */
    for (j = 1; j < R-k-1; j++) {
      r = (j-1) * grid;
      for (i = k+1; i < L-k-1; i++) {
        z = (i-1) * grid;
        if (setup.point_type[i][j]     != INSIDE ||
            setup.point_type[i + k][j] != INSIDE ||  // point is at least 3 mm from a boundary
            setup.point_type[i - k][j] != INSIDE ||
            setup.point_type[i][j + k] != INSIDE ||
            (j > k+1 && setup.point_type[i][j - k] != INSIDE)) continue;
        // calc E
        er = 0;
        if (j>1) er = (setup.vsave[i][j-1] - setup.vsave[i][j+1])/(0.2*grid);
        ez = (setup.vsave[i-1][j] - setup.vsave[i+1][j])/(0.2*grid);
        E = sqrt(er*er + ez*ez);
        /* check for minimum field inside bulk of detector */
        if (E > 0.1 && E < setup.Emin) {
          setup.Emin = E;
          setup.rmin = r;
          setup.zmin = z;
        }
      }
    }
    printf("Minimum bulk field at %.0fV (%dV overbias) is %.2f V/cm at (r,z) = (%.1f, %.1f) mm\n\n",
           BV-min+EMIN_OVERBIAS, EMIN_OVERBIAS, setup.Emin, setup.rmin, setup.zmin);
  }
#endif
 
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x41b8, %rsp           # imm = 0x41B8
movq %rsi, %rbx
movl %edi, %ebp
cmpl $0x2, %edi
setl %al
movl %ebp, %ecx
orb %al, %cl
testb $0x1, %cl
jne 0x1336
movq 0x8(%rbx), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x65c8
testl %eax, %eax
je 0x1360
movq (%rbx), %rsi
leaq 0x6e40(%rip), %rdi      # 0x8180
xorl %eax, %eax
callq 0x10f0
movl $0x1, %ebp
movl %ebp, %eax
addq $0x41b8, %rsp           # imm = 0x41B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1528(%rsp), %r14
movq 0x8(%rbx), %rsi
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
callq 0x1040
cvtss2sd -0x142c(%r14), %xmm0
movsd 0x6c7e(%rip), %xmm1     # 0x8008
ucomisd %xmm0, %xmm1
jbe 0x139b
movl $0x3f000000, 0xfc(%rsp) # imm = 0x3F000000
movss 0x11c(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movl $0x0, 0x4f4(%rsp)
cmpl $0x4, %ebp
jl 0x1594
leaq 0x4f4(%rsp), %r15
decl %ebp
movl $0x2, %r13d
movslq %r13d, %r12
movq (%rbx,%r12,8), %r14
movq %r14, %rdi
leaq 0x6ecc(%rip), %rsi      # 0x82aa
callq 0x11f0
testq %rax, %rax
je 0x140b
leal 0x1(%r12), %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x1090
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movss %xmm0, 0x11c(%rsp)
jmp 0x1436
movq %r14, %rdi
leaq 0x6e98(%rip), %rsi      # 0x82ad
callq 0x11f0
testq %rax, %rax
jne 0x1433
movq %r14, %rdi
leaq 0x6e87(%rip), %rsi      # 0x82b0
callq 0x11f0
testq %rax, %rax
je 0x1443
incl %r13d
incl %r13d
cmpl %ebp, %r13d
jl 0x13cd
jmp 0x1594
movq %r14, %rdi
leaq 0x6e66(%rip), %rsi      # 0x82b3
callq 0x11f0
testq %rax, %rax
je 0x146d
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x11c0
movl %eax, 0x128(%rsp)
jmp 0x1436
movq %r14, %rdi
leaq 0x6e3f(%rip), %rsi      # 0x82b6
callq 0x11f0
testq %rax, %rax
je 0x1500
movq 0x8(%rbx,%r12,8), %rdi
leaq 0x6e2a(%rip), %rsi      # 0x82b7
callq 0x11b0
movq 0x8(%rbx,%r12,8), %rsi
testq %rax, %rax
je 0x18ec
movq %rax, %r14
movq %rsi, %rdi
leaq 0x6e44(%rip), %rsi      # 0x82f1
callq 0x11f0
testq %rax, %rax
je 0x14cc
movl $0x24, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1080
incl %r13d
movl $0x1000, %edx           # imm = 0x1000
movq %r15, %rdi
xorl %esi, %esi
callq 0x1110
movl $0x1000, %esi           # imm = 0x1000
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1080
movq %r14, %rdi
callq 0x10c0
jmp 0x1436
movq %r14, %rdi
leaq 0x6dec(%rip), %rsi      # 0x82f6
callq 0x11f0
testq %rax, %rax
je 0x1558
movq 0x8(%rbx,%r12,8), %rdi
callq 0x11c0
cmpl $0xc6, %eax
jg 0x18f8
incl %r13d
cltq
leaq 0x1(%rax), %rcx
movq %r15, %rdx
movq %rcx, %rsi
movss (%rdx,%rax,4), %xmm0
movss %xmm0, (%rdx)
addq $0x4, %rdx
incq %rsi
cmpl $0xc8, %ecx
movq %rsi, %rcx
jne 0x1538
jmp 0x1436
movq %r14, %rdi
leaq 0x6dd3(%rip), %rsi      # 0x8335
callq 0x11f0
testq %rax, %rax
jne 0x1436
movq %r14, %rdi
leaq 0x6dbe(%rip), %rsi      # 0x8338
callq 0x11f0
testq %rax, %rax
jne 0x1436
leaq 0x744f(%rip), %rdi      # 0x89de
jmp 0x18a2
movss 0xcc(%rsp), %xmm0
movss 0xdc(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x15c6
movss %xmm0, 0xdc(%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x6d7c(%rip), %rdi      # 0x833b
movb $0x1, %al
callq 0x10f0
cmpl $0x2, 0xa8(%rsp)
jl 0x1630
movss 0x4f4(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x15e3
jnp 0x1630
leaq 0x7359(%rip), %rdi      # 0x8943
callq 0x1070
cvttss2si 0xac(%rsp), %eax
testl %eax, %eax
jle 0x1630
xorl %ebx, %ebx
leaq 0x6d72(%rip), %r14      # 0x8377
xorps %xmm0, %xmm0
cvtss2sd 0x4f4(%rsp,%rbx,4), %xmm0
movq %r14, %rdi
movl %ebx, %esi
movb $0x1, %al
callq 0x10f0
cvttss2si 0xac(%rsp), %eax
incq %rbx
cltq
cmpq %rax, %rbx
jl 0x1605
movss 0xac(%rsp), %xmm1
movss 0xb0(%rsp), %xmm0
movss 0xfc(%rsp), %xmm2
movaps %xmm1, %xmm3
divss %xmm2, %xmm3
mulss %xmm0, %xmm3
divss %xmm2, %xmm3
ucomiss 0x6a97(%rip), %xmm3     # 0x80f8
jbe 0x166f
leaq 0x733d(%rip), %rdi      # 0x89a7
jmp 0x18a2
cmpl $0x2, 0xa8(%rsp)
jl 0x1776
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
leaq 0x6cf8(%rip), %rdi      # 0x8384
movb $0x2, %al
callq 0x10f0
movss 0xcc(%rsp), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x16fd
movss 0xdc(%rsp), %xmm3
ucomiss 0x6a54(%rip), %xmm3     # 0x8108
xorps %xmm0, %xmm0
cvtss2sd 0xd0(%rsp), %xmm0
cvtss2sd %xmm1, %xmm1
jbe 0x16ef
xorps %xmm2, %xmm2
cvtss2sd 0xe4(%rsp), %xmm2
cvtss2sd %xmm3, %xmm3
cvtss2sd 0xd8(%rsp), %xmm4
leaq 0x6cd0(%rip), %rdi      # 0x83b6
movb $0x5, %al
callq 0x10f0
jmp 0x16fd
leaq 0x6d15(%rip), %rdi      # 0x840b
movb $0x2, %al
callq 0x10f0
xorps %xmm0, %xmm0
cvtss2sd 0xb8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0xb4(%rsp), %xmm1
leaq 0x6d1f(%rip), %rdi      # 0x843b
movb $0x2, %al
callq 0x10f0
movss 0xc0(%rsp), %xmm1
ucomiss 0x69d5(%rip), %xmm1     # 0x8108
jbe 0x175f
xorps %xmm0, %xmm0
cvtss2sd 0xbc(%rsp), %xmm0
cvtss2sd %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0xc4(%rsp), %xmm2
leaq 0x6d13(%rip), %rdi      # 0x846b
movb $0x3, %al
callq 0x10f0
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
leaq 0x6d39(%rip), %rdi      # 0x84a8
movb $0x1, %al
callq 0x10f0
xorps %xmm1, %xmm1
ucomiss 0x10(%rsp), %xmm1
movss 0x100(%rsp), %xmm0
jbe 0x178e
ucomiss %xmm0, %xmm1
ja 0x179d
movaps 0x10(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x17a9
ucomiss %xmm1, %xmm0
jbe 0x17a9
leaq 0x71ce(%rip), %rdi      # 0x8972
jmp 0x18a2
ucomiss %xmm1, %xmm0
jbe 0x180f
movaps 0x696b(%rip), %xmm1     # 0x8120
movss 0x104(%rsp), %xmm2
movss 0x110(%rsp), %xmm3
movss 0x11c(%rsp), %xmm4
xorps %xmm1, %xmm4
movss %xmm4, 0x11c(%rsp)
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movhps 0x108(%rsp), %xmm0      # xmm0 = xmm0[0,1],mem[0,1]
xorps 0x6932(%rip), %xmm0     # 0x8120
movaps 0x10(%rsp), %xmm2
xorps %xmm1, %xmm2
movaps %xmm2, 0x10(%rsp)
movups %xmm0, 0x100(%rsp)
xorps %xmm1, %xmm3
movss %xmm3, 0x110(%rsp)
leaq 0x2c08(%rsp), %rbx
leaq 0xa8(%rsp), %r14
movl $0x15b0, %edx           # imm = 0x15B0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1160
leaq 0x1658(%rsp), %r15
movl $0x15b0, %edx           # imm = 0x15B0
movq %r15, %rdi
movq %r14, %rsi
callq 0x1160
movss 0x54(%rbx), %xmm0
mulss 0x68a8(%rip), %xmm0     # 0x80fc
movss %xmm0, 0x54(%rbx)
movss 0x54(%r15), %xmm0
mulss 0x6899(%rip), %xmm0     # 0x8100
movss %xmm0, 0x54(%r15)
movq %rbx, %rdi
callq 0x2094
testl %eax, %eax
jne 0x189b
leaq 0x1658(%rsp), %rdi
callq 0x2094
testl %eax, %eax
jne 0x189b
leaq 0xa8(%rsp), %rdi
callq 0x2094
testl %eax, %eax
je 0x18ac
leaq 0x70ae(%rip), %rdi      # 0x8950
callq 0x1070
jmp 0x1347
cmpl $0x0, 0x124(%rsp)
je 0x1944
xorl %eax, %eax
movl %eax, 0x2c84(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0xfc(%rsp), %xmm0
movl %eax, 0x16d4(%rsp)
ucomisd 0x6732(%rip), %xmm0     # 0x8010
jbe 0x190d
leaq 0x1658(%rsp), %rdi
xorl %esi, %esi
jmp 0x192a
leaq 0x69c6(%rip), %rdi      # 0x82b9
jmp 0x1340
leaq 0x69fa(%rip), %rdi      # 0x82f9
movl %eax, %esi
xorl %eax, %eax
callq 0x10f0
jmp 0x1347
leaq 0x2c08(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x331d
leaq 0x1658(%rsp), %rdi
movq %rbx, %rsi
callq 0x331d
leaq 0xa8(%rsp), %rdi
leaq 0x1658(%rsp), %rsi
callq 0x331d
cmpl $0x0, 0x128(%rsp)
je 0x19b7
xorl %eax, %eax
movl %eax, 0x2c88(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0xfc(%rsp), %xmm0
movl %eax, 0x16d8(%rsp)
ucomisd 0x669e(%rip), %xmm0     # 0x8010
jbe 0x1980
leaq 0x1658(%rsp), %rdi
xorl %esi, %esi
jmp 0x199d
leaq 0x2c08(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40cf
leaq 0x1658(%rsp), %rdi
movq %rbx, %rsi
callq 0x40cf
leaq 0xa8(%rsp), %rdi
leaq 0x1658(%rsp), %rsi
callq 0x40cf
movss 0xac(%rsp), %xmm0
movss 0xfc(%rsp), %xmm1
movss %xmm1, 0x4(%rsp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, 0x28(%rsp)
movss 0xb0(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r14
movss 0xb4(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r15
movss 0xb8(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r12
cmpl $0x0, 0x128(%rsp)
je 0x1d7a
movq 0x28(%rsp), %rax
incl %eax
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rsp), %xmm0
cmpl $0x2, %eax
movsd %xmm0, 0x50(%rsp)
jl 0x1d09
movq %r14, 0x68(%rsp)
leal 0x1(%r14), %esi
leal 0x1(%r15), %ecx
leal 0x1(%r12), %edx
movsd 0x659f(%rip), %xmm4     # 0x8018
mulsd %xmm0, %xmm4
movq %r12, 0x58(%rsp)
leal 0x2(%r12), %r11d
movq %r15, 0x60(%rsp)
leal 0x2(%r15), %r13d
movl %edx, %r15d
movslq %edx, %rbx
movslq %r11d, %rbp
movslq %r13d, %rdx
movq %rdx, 0x20(%rsp)
movl %ecx, %edx
movq %rdx, 0x40(%rsp)
movslq %ecx, %rcx
movq %rcx, 0xa0(%rsp)
movl %eax, %eax
movq %rax, 0x70(%rsp)
movl %esi, 0x4c(%rsp)
movl %esi, %eax
movq %rax, 0x98(%rsp)
xorpd %xmm6, %xmm6
movl $0x0, 0x8(%rsp)
movl $0x1, %r14d
movsd 0x653e(%rip), %xmm7     # 0x8020
movsd 0x653d(%rip), %xmm8     # 0x8028
xorpd %xmm5, %xmm5
xorps %xmm3, %xmm3
movsd %xmm4, 0x80(%rsp)
movq %rbp, 0x78(%rsp)
cmpl $0x3, 0x4c(%rsp)
jl 0x1cd0
movl $0x2, %r12d
cmpq %r13, %r14
sete %al
cmpq 0x20(%rsp), %r14
setle %cl
cmpq 0x40(%rsp), %r14
sete %dl
cmpq 0xa0(%rsp), %r14
setle %sil
movq 0x490(%rsp), %rdi
movq 0x4a0(%rsp), %r8
movq (%r8,%r14,8), %r8
movsd (%r8,%r12,8), %xmm0
mulsd %xmm7, %xmm0
movq (%rdi,%r14,8), %r8
movq 0x8(%rdi,%r14,8), %rdi
movsd (%r8,%r12,8), %xmm1
movapd %xmm1, %xmm2
subsd 0x8(%r8,%r12,8), %xmm2
mulsd %xmm0, %xmm2
divsd %xmm4, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movq 0x4a8(%rsp), %r8
movq (%r8,%r14,8), %r8
movsd (%r8,%r12,8), %xmm2
mulsd %xmm7, %xmm2
subsd (%rdi,%r12,8), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm4, %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
leal -0x1(%r12), %edi
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
cmpq %r12, %r15
sete %r10b
cmpq %rbx, %r12
setle %r9b
cmpq %r12, %r11
sete %r8b
cmpq %rbp, %r12
setle %dil
testb %sil, %r10b
jne 0x1bf5
andb %dl, %r9b
jne 0x1bf5
andb %cl, %r8b
jne 0x1bf5
andb %al, %dil
je 0x1cb7
movq 0x4d8(%rsp), %rax
movq 0x8(%rax,%r14,8), %rax
cmpb $0x0, 0x1(%rax,%r12)
movl 0x8(%rsp), %eax
movl $0x1, %ecx
cmovel %ecx, %eax
movl %eax, 0x8(%rsp)
ucomisd %xmm6, %xmm1
jb 0x1c2a
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x1caa
movapd %xmm1, %xmm0
movsd %xmm3, 0x30(%rsp)
movsd %xmm5, 0x38(%rsp)
movq %rbx, %rbp
movq %r15, %rbx
movq %r13, %r15
movq %r11, %r13
movsd %xmm1, 0x90(%rsp)
movsd %xmm2, 0x88(%rsp)
callq 0x11e0
movsd 0x88(%rsp), %xmm2
movsd 0x90(%rsp), %xmm1
movsd 0x63b0(%rip), %xmm8     # 0x8028
movsd 0x63a0(%rip), %xmm7     # 0x8020
xorpd %xmm6, %xmm6
movq %r13, %r11
movq %r15, %r13
movq %rbx, %r15
movq %rbp, %rbx
movq 0x78(%rsp), %rbp
movsd 0x38(%rsp), %xmm5
movsd 0x80(%rsp), %xmm4
movsd 0x30(%rsp), %xmm3
mulsd %xmm8, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm0, %xmm3
incq %r12
mulsd %xmm2, %xmm1
addsd %xmm1, %xmm5
cmpq %r12, 0x98(%rsp)
jne 0x1b11
incq %r14
cmpq 0x70(%rsp), %r14
jne 0x1b00
movsd %xmm3, 0x30(%rsp)
cmpl $0x0, 0x8(%rsp)
sete %bl
movq 0x68(%rsp), %r14
movq 0x60(%rsp), %r15
movq 0x58(%rsp), %r12
movsd 0x50(%rsp), %xmm0
movsd %xmm5, 0x38(%rsp)
jmp 0x1d1a
movb $0x1, %bl
xorps %xmm1, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd %xmm1, 0x38(%rsp)
movsd 0x630e(%rip), %xmm1     # 0x8030
callq 0x10b0
mulsd 0x6309(%rip), %xmm0     # 0x8038
movsd 0x38(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
leaq 0x6776(%rip), %rdi      # 0x84bf
movb $0x2, %al
callq 0x10f0
testb %bl, %bl
je 0x1d7a
movsd 0x50(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x62da(%rip), %xmm0     # 0x8040
mulsd 0x30(%rsp), %xmm0
leaq 0x677e(%rip), %rdi      # 0x84f1
movb $0x1, %al
callq 0x10f0
xorl %ebp, %ebp
cmpl $0x0, 0x128(%rsp)
je 0x134c
cmpl $0x0, 0x4e8(%rsp)
je 0x205d
cvtss2sd 0x10(%rsp), %xmm11
addl $0x3, %r15d
movaps %xmm11, %xmm1
cmpl $0x2, %r15d
jl 0x1e20
addl $0x3, %r12d
movq 0x490(%rsp), %rax
movq 0x4d0(%rsp), %rcx
movl %r15d, %edx
movl $0x1, %esi
xorps %xmm0, %xmm0
movsd 0x6274(%rip), %xmm2     # 0x8048
movaps %xmm11, %xmm1
cmpl $0x2, %r12d
jl 0x1e18
movq (%rcx,%rsi,8), %rdi
movl $0x1, %r8d
movsd (%rdi,%r8,8), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1e10
movq (%rax,%rsi,8), %r9
movapd %xmm2, %xmm4
subsd (%r9,%r8,8), %xmm4
divsd %xmm4, %xmm3
ucomisd %xmm3, %xmm1
jbe 0x1e10
movapd %xmm3, %xmm1
incq %r8
cmpq %r8, %r12
jne 0x1de8
incq %rsi
cmpq %rdx, %rsi
jne 0x1dd8
movq 0x28(%rsp), %rax
decl %eax
movq %rax, 0x28(%rsp)
cmpl %eax, %r15d
jge 0x1fbe
decl %r14d
movq 0x4d8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x490(%rsp), %rcx
movq 0x4d0(%rsp), %rdx
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rsp), %xmm0
movslq %r15d, %rdi
movq $0x0, 0x10(%rsp)
movsd 0x61de(%rip), %xmm2     # 0x8050
movsd 0x61de(%rip), %xmm3     # 0x8058
xorps %xmm4, %xmm4
leaq 0x62dc(%rip), %r8       # 0x8160
leaq 0x62e5(%rip), %r9       # 0x8170
movsd 0x61cd(%rip), %xmm5     # 0x8060
movapd 0x6295(%rip), %xmm6     # 0x8130
movl $0x0, 0x8(%rsp)
movaps %xmm11, %xmm12
cmpl $0x2, %r14d
jl 0x1f94
movq 0x20(%rsp), %rax
movq (%rax,%rdi,8), %r11
movl $0x1, %ebx
cmpb $0x2, (%r11,%rbx)
jne 0x1f88
movq (%rcx,%rdi,8), %rax
movsd (%rax,%rbx,8), %xmm8
ucomisd %xmm2, %xmm8
jbe 0x1f88
movq %r14, %r10
movq %rbx, %r14
xorq $0x1, %r14
movslq %ebx, %r15
xorl %r12d, %r12d
movapd %xmm3, %xmm7
movq %r12, %rax
xorq $0x8, %rax
orq %r14, %rax
je 0x1f68
movslq (%r12,%r8), %r13
addq %rdi, %r13
movslq (%r12,%r9), %rax
addq %r15, %rax
movq (%rcx,%r13,8), %rsi
movsd (%rsi,%rax,8), %xmm9
subsd %xmm8, %xmm9
movapd %xmm9, %xmm10
mulsd %xmm0, %xmm10
ucomisd %xmm5, %xmm10
jbe 0x1f5e
movq (%rdx,%r13,8), %rsi
movsd (%rsi,%rax,8), %xmm10
movq (%rdx,%rdi,8), %rax
subsd (%rax,%rbx,8), %xmm10
ucomisd %xmm10, %xmm4
jbe 0x1f5e
xorpd %xmm6, %xmm10
divsd %xmm9, %xmm10
ucomisd %xmm7, %xmm10
jbe 0x1f5e
movapd %xmm10, %xmm7
addq $0x4, %r12
cmpq $0x10, %r12
jne 0x1ef3
ucomisd %xmm4, %xmm7
movq %r10, %r14
jb 0x1f88
ucomisd %xmm7, %xmm12
jbe 0x1f88
movapd %xmm7, %xmm12
movl %ebx, 0x8(%rsp)
movl %edi, %eax
movq %rax, 0x10(%rsp)
incq %rbx
cmpq %r14, %rbx
jne 0x1ebf
incq %rdi
cmpl %edi, 0x28(%rsp)
jne 0x1ea7
movl 0x8(%rsp), %eax
decl %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
movq 0x10(%rsp), %rax
decl %eax
xorps %xmm3, %xmm3
cvtsi2ss %eax, %xmm3
jmp 0x1fcd
movss 0x613e(%rip), %xmm2     # 0x8104
movaps %xmm11, %xmm12
movaps %xmm2, %xmm3
ucomisd %xmm12, %xmm1
movaps %xmm11, %xmm0
subsd %xmm1, %xmm0
jbe 0x204f
leaq 0x6546(%rip), %rdi      # 0x8529
movb $0x1, %al
movsd %xmm11, 0x8(%rsp)
movsd %xmm12, 0x10(%rsp)
movss %xmm2, 0x40(%rsp)
movss %xmm3, 0x20(%rsp)
callq 0x10f0
movss 0x4(%rsp), %xmm0
movss 0x40(%rsp), %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
movss 0x20(%rsp), %xmm2
mulss %xmm0, %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x6522(%rip), %rdi      # 0x854f
movsd 0x10(%rsp), %xmm0
movb $0x3, %al
callq 0x10f0
movsd 0x8(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x652c(%rip), %rdi      # 0x8579
jmp 0x2056
leaq 0x6555(%rip), %rdi      # 0x85ab
movb $0x1, %al
callq 0x10f0
xorps %xmm0, %xmm0
cvtss2sd 0x4f0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x458(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x464(%rsp), %xmm2
leaq 0x6792(%rip), %rdi      # 0x881a
movb $0x3, %al
callq 0x10f0
jmp 0x134c