// File: /workspace/github_c_makefile_star2_O2/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 $0x41a8, %rsp           # imm = 0x41A8
movq %rsi, %r15
movl %edi, %ebp
cmpl $0x2, %edi
setl %al
movl %ebp, %ecx
orb %al, %cl
pushq $0x1
popq %r13
testb $0x1, %cl
jne 0x132a
movq 0x8(%r15), %rdi
leaq 0x98(%rsp), %rsi
callq 0x5b6c
testl %eax, %eax
je 0x1350
movq (%r15), %rsi
leaq 0x5e4c(%rip), %rdi      # 0x7180
xorl %eax, %eax
callq 0x10f0
movl %r13d, %eax
addq $0x41a8, %rsp           # imm = 0x41A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1518(%rsp), %rbx
movq 0x8(%r15), %rsi
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
callq 0x1040
cvtss2sd -0x142c(%rbx), %xmm0
movsd 0x5c8f(%rip), %xmm1     # 0x7008
ucomisd %xmm0, %xmm1
jbe 0x138a
movl $0x3f000000, 0xec(%rsp) # imm = 0x3F000000
leaq 0x4e4(%rsp), %rax
movss -0x3d8(%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
andl $0x0, (%rax)
decl %ebp
pushq $0x2
popq %r12
leaq 0x5efb(%rip), %r13      # 0x72aa
cmpl %ebp, %r12d
jge 0x158f
movslq %r12d, %r14
movq (%r15,%r14,8), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x11e0
testq %rax, %rax
je 0x13f0
incl %r12d
movq 0x8(%r15,%r14,8), %rdi
callq 0x1090
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movss %xmm0, 0x10c(%rsp)
jmp 0x141b
movq %rbx, %rdi
leaq 0x5eb3(%rip), %rsi      # 0x72ad
callq 0x11e0
testq %rax, %rax
jne 0x1418
movq %rbx, %rdi
leaq 0x5ea2(%rip), %rsi      # 0x72b0
callq 0x11e0
testq %rax, %rax
je 0x1420
incl %r12d
incl %r12d
jmp 0x13af
movq %rbx, %rdi
leaq 0x5e89(%rip), %rsi      # 0x72b3
callq 0x11e0
testq %rax, %rax
je 0x144a
incl %r12d
movq 0x8(%r15,%r14,8), %rdi
callq 0x11c0
movl %eax, 0x118(%rsp)
jmp 0x141b
movq %rbx, %rdi
leaq 0x5e62(%rip), %rsi      # 0x72b6
callq 0x11e0
testq %rax, %rax
je 0x14ed
movq 0x8(%r15,%r14,8), %rdi
leaq 0x5e49(%rip), %rsi      # 0x72b7
callq 0x11b0
movq 0x8(%r15,%r14,8), %rsi
testq %rax, %rax
je 0x188a
movq %rax, %rbx
movq %rsi, %rdi
leaq 0x5e63(%rip), %rsi      # 0x72f1
callq 0x11e0
testq %rax, %rax
je 0x14ae
leaq 0x4e4(%rsp), %rdi
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1080
incl %r12d
xorl %eax, %eax
cmpq $0x400, %rax            # imm = 0x400
je 0x14c8
andl $0x0, 0x4e4(%rsp,%rax,4)
incq %rax
jmp 0x14b3
movl $0x1000, %esi           # imm = 0x1000
leaq 0x4e4(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1080
movq %rbx, %rdi
callq 0x10c0
jmp 0x141b
movq %rbx, %rdi
leaq 0x5dff(%rip), %rsi      # 0x72f6
callq 0x11e0
testq %rax, %rax
je 0x154e
movq 0x8(%r15,%r14,8), %rdi
callq 0x11c0
cmpl $0xc6, %eax
jg 0x18d7
incl %r12d
movslq %eax, %rcx
movl $0xc8, %eax
subq %rcx, %rax
leaq 0x4e4(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x141b
movss (%rcx,%rdx,4), %xmm0
movss %xmm0, 0x4e4(%rsp,%rdx,4)
incq %rdx
jmp 0x1532
movq %rbx, %rdi
leaq 0x5ddd(%rip), %rsi      # 0x7335
callq 0x11e0
testq %rax, %rax
jne 0x141b
movq %rbx, %rdi
leaq 0x5dc8(%rip), %rsi      # 0x7338
callq 0x11e0
testq %rax, %rax
jne 0x141b
leaq 0x6459(%rip), %rdi      # 0x79de
callq 0x1070
jmp 0x18e7
movss 0xbc(%rsp), %xmm0
movss 0xcc(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x15c1
movss %xmm0, 0xcc(%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x5d81(%rip), %rdi      # 0x733b
movb $0x1, %al
callq 0x10f0
cmpl $0x2, 0x98(%rsp)
pushq $0x1
popq %r13
jl 0x1625
movss 0x4e4(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x15e2
jnp 0x1625
leaq 0x635a(%rip), %rdi      # 0x7943
callq 0x1070
xorl %ebx, %ebx
leaq 0x5d80(%rip), %r15      # 0x7377
movss 0x9c(%rsp), %xmm1
cvttss2si %xmm1, %eax
cltq
cmpq %rax, %rbx
jge 0x162e
cvtss2sd 0x4e4(%rsp,%rbx,4), %xmm0
movq %r15, %rdi
movl %ebx, %esi
movb $0x1, %al
callq 0x10f0
incq %rbx
jmp 0x15f7
movss 0x9c(%rsp), %xmm1
movss 0xa0(%rsp), %xmm0
movss 0xec(%rsp), %xmm2
movaps %xmm1, %xmm3
divss %xmm2, %xmm3
mulss %xmm0, %xmm3
divss %xmm2, %xmm3
ucomiss 0x5aba(%rip), %xmm3     # 0x7110
jbe 0x1664
leaq 0x6348(%rip), %rdi      # 0x79a7
jmp 0x1880
cmpl $0x2, 0x98(%rsp)
jl 0x1756
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
leaq 0x5d03(%rip), %rdi      # 0x7384
movb $0x2, %al
callq 0x10f0
movss 0xbc(%rsp), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x16ec
movss 0xcc(%rsp), %xmm3
ucomiss 0x5a73(%rip), %xmm3     # 0x711c
cvtss2sd 0xc0(%rsp), %xmm0
cvtss2sd %xmm1, %xmm1
jbe 0x16de
cvtss2sd 0xd4(%rsp), %xmm2
cvtss2sd %xmm3, %xmm3
cvtss2sd 0xc8(%rsp), %xmm4
leaq 0x5ce1(%rip), %rdi      # 0x73b6
movb $0x5, %al
callq 0x10f0
jmp 0x16ec
leaq 0x5d26(%rip), %rdi      # 0x740b
movb $0x2, %al
callq 0x10f0
cvtss2sd 0xa8(%rsp), %xmm0
cvtss2sd 0xa4(%rsp), %xmm1
leaq 0x5d36(%rip), %rdi      # 0x743b
movb $0x2, %al
callq 0x10f0
movss 0xb0(%rsp), %xmm1
ucomiss 0x5a00(%rip), %xmm1     # 0x711c
jbe 0x1742
cvtss2sd 0xac(%rsp), %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd 0xb4(%rsp), %xmm2
leaq 0x5d30(%rip), %rdi      # 0x746b
movb $0x3, %al
callq 0x10f0
cvtss2sd 0x20(%rsp), %xmm0
leaq 0x5d59(%rip), %rdi      # 0x74a8
movb $0x1, %al
callq 0x10f0
xorps %xmm1, %xmm1
ucomiss 0x20(%rsp), %xmm1
movss 0xf0(%rsp), %xmm0
jbe 0x176e
ucomiss %xmm0, %xmm1
ja 0x177d
movaps 0x20(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1789
ucomiss %xmm1, %xmm0
jbe 0x1789
leaq 0x61ee(%rip), %rdi      # 0x7972
jmp 0x1880
ucomiss %xmm1, %xmm0
jbe 0x17eb
movaps 0x599b(%rip), %xmm1     # 0x7130
movaps 0x20(%rsp), %xmm2
xorps %xmm1, %xmm2
movaps %xmm2, 0x20(%rsp)
movss 0xf4(%rsp), %xmm2
movss 0x100(%rsp), %xmm3
movss 0x10c(%rsp), %xmm4
xorps %xmm1, %xmm4
movss %xmm4, 0x10c(%rsp)
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movhps 0xf8(%rsp), %xmm0       # xmm0 = xmm0[0,1],mem[0,1]
xorps %xmm1, %xmm0
movups %xmm0, 0xf0(%rsp)
xorps %xmm1, %xmm3
movss %xmm3, 0x100(%rsp)
leaq 0x2bf8(%rsp), %rbx
leaq 0x98(%rsp), %r15
movl $0x15b0, %edx           # imm = 0x15B0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1160
leaq 0x1648(%rsp), %r12
movl $0x15b0, %edx           # imm = 0x15B0
movq %r12, %rdi
movq %r15, %rsi
callq 0x1160
movss 0x54(%rbx), %xmm0
mulss 0x58e4(%rip), %xmm0     # 0x7114
movss %xmm0, 0x54(%rbx)
movss 0x54(%r12), %xmm0
mulss 0x58d4(%rip), %xmm0     # 0x7118
movss %xmm0, 0x54(%r12)
movq %rbx, %rdi
callq 0x1f8f
testl %eax, %eax
jne 0x1879
leaq 0x1648(%rsp), %rdi
callq 0x1f8f
testl %eax, %eax
jne 0x1879
leaq 0x98(%rsp), %rdi
callq 0x1f8f
testl %eax, %eax
je 0x189a
leaq 0x60d0(%rip), %rdi      # 0x7950
callq 0x1070
jmp 0x133b
leaq 0x5a28(%rip), %rdi      # 0x72b9
xorl %eax, %eax
callq 0x10f0
jmp 0x18e7
cmpl $0x0, 0x114(%rsp)
pushq $0x1
popq %r15
je 0x1927
andl $0x0, 0x2c74(%rsp)
andl $0x0, 0x16c4(%rsp)
cvtss2sd 0xec(%rsp), %xmm0
ucomisd 0x5747(%rip), %xmm0     # 0x7010
jbe 0x18f0
leaq 0x1648(%rsp), %rdi
xorl %esi, %esi
jmp 0x190d
leaq 0x5a1b(%rip), %rdi      # 0x72f9
movl %eax, %esi
xorl %eax, %eax
callq 0x10f0
pushq $0x1
popq %r13
jmp 0x133b
leaq 0x2bf8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x301b
leaq 0x1648(%rsp), %rdi
movq %rbx, %rsi
callq 0x301b
leaq 0x98(%rsp), %rdi
leaq 0x1648(%rsp), %rsi
callq 0x301b
cmpl $0x0, 0x118(%rsp)
je 0x1997
andl $0x0, 0x2c78(%rsp)
andl $0x0, 0x16c8(%rsp)
cvtss2sd 0xec(%rsp), %xmm0
ucomisd 0x56be(%rip), %xmm0     # 0x7010
jbe 0x1960
leaq 0x1648(%rsp), %rdi
xorl %esi, %esi
jmp 0x197d
leaq 0x2bf8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3bbf
leaq 0x1648(%rsp), %rdi
movq %rbx, %rsi
callq 0x3bbf
leaq 0x98(%rsp), %rdi
leaq 0x1648(%rsp), %rsi
callq 0x3bbf
movss 0x9c(%rsp), %xmm0
movss 0xec(%rsp), %xmm1
movss %xmm1, 0x4(%rsp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %rbx
movss 0xa0(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r14
movss 0xa4(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, %r12
movss 0xa8(%rsp), %xmm0
divss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
cmpl $0x0, 0x118(%rsp)
je 0x1d65
leal 0x1(%rax), %ecx
leal 0x1(%r12), %esi
movq 0x480(%rsp), %rdx
movq 0x490(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x55ce(%rip), %xmm7     # 0x7018
mulsd %xmm0, %xmm7
movq 0x498(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq %rax, 0x40(%rsp)
leal 0x2(%rax), %edi
movq %r12, 0x48(%rsp)
leal 0x2(%r12), %r8d
movq 0x4c8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x50(%rsp)
leal 0x1(%r14), %eax
cltq
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movslq %ecx, %rax
movq %rax, 0x80(%rsp)
movq %rdi, 0x90(%rsp)
movslq %edi, %rax
movq %rax, 0x78(%rsp)
movq %rbx, 0x58(%rsp)
leal 0x1(%rbx), %eax
cltq
movq %rax, 0x68(%rsp)
movq %rsi, 0x88(%rsp)
movslq %esi, %rax
movq %rax, 0x70(%rsp)
movq %r8, %rbp
movslq %r8d, %r10
movl $0x0, 0x14(%rsp)
xorpd %xmm8, %xmm8
movsd 0x5574(%rip), %xmm1     # 0x7058
movsd 0x5574(%rip), %xmm2     # 0x7060
xorpd %xmm9, %xmm9
cmpq 0x68(%rsp), %r15
jge 0x1c35
leaq 0x1(%r15), %r13
pushq $0x2
popq %rsi
movq %rsi, %rcx
cmpq 0x18(%rsp), %rcx
jge 0x1c2d
cmpq %rbp, %r15
sete %bl
cmpq %r10, %r15
setle %al
cmpq 0x88(%rsp), %r15
sete %r14b
cmpq 0x70(%rsp), %r15
movq 0x38(%rsp), %rsi
movq (%rsi,%r15,8), %rsi
movsd (%rsi,%rcx,8), %xmm3
movq (%rdx,%r15,8), %rsi
movsd (%rsi,%rcx,8), %xmm4
movapd %xmm4, %xmm5
subsd 0x8(%rsi,%rcx,8), %xmm5
mulsd %xmm1, %xmm3
mulsd %xmm3, %xmm5
movq 0x30(%rsp), %rsi
movq (%rsi,%r15,8), %rsi
movsd (%rsi,%rcx,8), %xmm3
mulsd %xmm1, %xmm3
movq (%rdx,%r13,8), %rsi
subsd (%rsi,%rcx,8), %xmm4
mulsd %xmm3, %xmm4
leal -0x1(%rcx), %esi
cvtsi2sd %esi, %xmm3
movq %r15, %r11
setle %r15b
cmpq %rcx, 0x8(%rsp)
sete %r12b
cmpq 0x80(%rsp), %rcx
setle %r8b
cmpq %rcx, 0x90(%rsp)
sete %dil
cmpq 0x78(%rsp), %rcx
leaq 0x1(%rcx), %rsi
divsd %xmm7, %xmm5
cvtsd2ss %xmm5, %xmm5
divsd %xmm7, %xmm4
cvtsd2ss %xmm4, %xmm4
mulss %xmm4, %xmm4
mulss %xmm5, %xmm5
addss %xmm4, %xmm5
cvtss2sd %xmm5, %xmm4
movaps %xmm4, %xmm5
mulsd %xmm3, %xmm5
addsd %xmm5, %xmm9
setle %r9b
testb %r15b, %r12b
movq %r11, %r15
jne 0x1bfc
andb %r14b, %r8b
jne 0x1bfc
andb %al, %dil
jne 0x1bfc
movq %rsi, %rcx
andb %bl, %r9b
je 0x1b06
movq 0x60(%rsp), %rax
movq (%rax,%r13,8), %rax
cmpb $0x0, (%rax,%rsi)
movl 0x14(%rsp), %eax
pushq $0x1
popq %rcx
cmovel %ecx, %eax
movl %eax, 0x14(%rsp)
sqrtsd %xmm4, %xmm4
mulsd %xmm2, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm8
jmp 0x1b03
movq %r13, %r15
jmp 0x1af1
movsd %xmm8, 0x8(%rsp)
movsd 0x53dc(%rip), %xmm1     # 0x7020
movsd %xmm0, 0x38(%rsp)
movsd %xmm9, 0x18(%rsp)
callq 0x10b0
mulsd 0x53ca(%rip), %xmm0     # 0x7028
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvtss2sd 0x20(%rsp), %xmm0
leaq 0x584a(%rip), %rdi      # 0x74bf
movsd %xmm0, 0x30(%rsp)
movb $0x2, %al
callq 0x10f0
cmpl $0x0, 0x14(%rsp)
jne 0x1caf
movsd 0x38(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x5395(%rip), %xmm0     # 0x7030
mulsd 0x8(%rsp), %xmm0
leaq 0x5849(%rip), %rdi      # 0x74f1
movb $0x1, %al
callq 0x10f0
xorl %r13d, %r13d
cmpl $0x0, 0x118(%rsp)
movq 0x58(%rsp), %r11
movq 0x50(%rsp), %rbx
movq 0x48(%rsp), %rdx
je 0x133b
cmpl $0x0, 0x4d8(%rsp)
je 0x1f61
movq 0x480(%rsp), %rax
movq 0x4c0(%rsp), %rcx
movq 0x40(%rsp), %rsi
addl $0x3, %esi
movslq %esi, %rsi
addl $0x3, %edx
movslq %edx, %rdx
pushq $0x1
popq %rdi
xorps %xmm0, %xmm0
movsd 0x5344(%rip), %xmm2     # 0x7050
movq %rdi, %r8
movsd 0x30(%rsp), %xmm11
movapd %xmm11, %xmm1
movsd 0x38(%rsp), %xmm10
cmpq %rdx, %r8
jge 0x1d6d
movq %rdi, %r9
cmpq %rsi, %r9
jge 0x1d60
movq (%rcx,%r8,8), %r10
movsd (%r10,%r9,8), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1d5b
movq (%rax,%r8,8), %r10
movapd %xmm2, %xmm4
subsd (%r10,%r9,8), %xmm4
divsd %xmm4, %xmm3
ucomisd %xmm3, %xmm1
jbe 0x1d5b
movapd %xmm3, %xmm1
incq %r9
jmp 0x1d2a
incq %r8
jmp 0x1d22
xorl %r13d, %r13d
jmp 0x133b
movq 0x4c8(%rsp), %rsi
decl %ebx
movslq %ebx, %rdi
decl %r11d
movslq %r11d, %r8
movq %r8, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movsd 0x52a2(%rip), %xmm0     # 0x7038
movsd 0x52a2(%rip), %xmm2     # 0x7040
xorps %xmm3, %xmm3
leaq 0x53b8(%rip), %r10      # 0x7160
leaq 0x53c1(%rip), %r11      # 0x7170
movsd 0x5291(%rip), %xmm4     # 0x7048
movapd 0x5381(%rip), %xmm5     # 0x7140
movapd %xmm11, %xmm12
movl $0x0, 0x18(%rsp)
cmpq 0x8(%rsp), %rdx
jge 0x1eda
pushq $0x1
popq %r14
cmpq %rdi, %r14
jge 0x1ed2
movq (%rsi,%rdx,8), %r8
cmpb $0x2, (%r8,%r14)
jne 0x1eca
movq (%rax,%rdx,8), %r8
movsd (%r8,%r14,8), %xmm6
ucomisd %xmm0, %xmm6
jbe 0x1eca
movq %r14, %r15
xorq $0x1, %r15
movslq %r14d, %r12
xorl %r13d, %r13d
xorl %r9d, %r9d
movaps %xmm2, %xmm7
movq %r9, %r8
xorq $0x2, %r8
orq %r15, %r8
sete %r8b
cmpq $0x3, %r9
ja 0x1ea1
testb %r8b, %r8b
jne 0x1ea1
movslq (%r13,%r10), %r8
addq %rdx, %r8
movslq (%r13,%r11), %rbx
addq %r12, %rbx
movq (%rax,%r8,8), %rbp
movsd (%rbp,%rbx,8), %xmm8
subsd %xmm6, %xmm8
movapd %xmm8, %xmm9
mulsd %xmm10, %xmm9
ucomisd %xmm4, %xmm9
jbe 0x1e95
movq (%rcx,%r8,8), %r8
movsd (%r8,%rbx,8), %xmm9
movq (%rcx,%rdx,8), %r8
subsd (%r8,%r14,8), %xmm9
ucomisd %xmm9, %xmm3
jbe 0x1e95
xorpd %xmm5, %xmm9
divsd %xmm8, %xmm9
ucomisd %xmm7, %xmm9
jbe 0x1e95
movapd %xmm9, %xmm7
incq %r9
addq $0x4, %r13
jmp 0x1e1a
ucomisd %xmm3, %xmm7
jb 0x1ec7
ucomisd %xmm7, %xmm12
movl $0x0, %r13d
jbe 0x1eca
movapd %xmm7, %xmm12
movl %r14d, %r8d
movq %r8, 0x20(%rsp)
movl %edx, 0x18(%rsp)
jmp 0x1eca
xorl %r13d, %r13d
incq %r14
jmp 0x1ddb
incq %rdx
jmp 0x1dcc
ucomisd %xmm12, %xmm1
movapd %xmm11, %xmm0
subsd %xmm1, %xmm0
jbe 0x1f53
leaq 0x5638(%rip), %rdi      # 0x7529
movb $0x1, %al
movsd %xmm12, 0x8(%rsp)
callq 0x10f0
movq 0x20(%rsp), %rax
decl %eax
cvtsi2ss %eax, %xmm0
movl 0x18(%rsp), %eax
decl %eax
cvtsi2ss %eax, %xmm2
movss 0x4(%rsp), %xmm3
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm1
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x561e(%rip), %rdi      # 0x754f
movsd 0x8(%rsp), %xmm0
movb $0x3, %al
callq 0x10f0
movsd 0x30(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
leaq 0x5628(%rip), %rdi      # 0x7579
jmp 0x1f5a
leaq 0x5651(%rip), %rdi      # 0x75ab
movb $0x1, %al
callq 0x10f0
cvtss2sd 0x4e0(%rsp), %xmm0
cvtss2sd 0x448(%rsp), %xmm1
cvtss2sd 0x454(%rsp), %xmm2
leaq 0x5897(%rip), %rdi      # 0x781a
movb $0x3, %al
callq 0x10f0
jmp 0x133b