// File: /workspace/github_c_makefile_star2_O0/radforddc[P]icpc_siggen/calc_signal.c
// Function: make_signal
int make_signal(point pt, float *signal, float q, MJD_Siggen_Setup *setup) {
  float  wpot, wpot2=0, dwpot=0;
  char   tmpstr[MAX_LINE];
  point  new_pt;
  vector v, dx;
  float  vel0, vel1 = 0, wpot_old=-1;
  // double diffusion_coeff;
  double repulsion_fact = 0.0, ds2, ds3, dv, ds_dt;
  int    ntsteps, i, t, n, collect2pc, low_field=0, surface_drift=0, stop_drifting = 0;

  new_pt = pt;
  if (setup->impurity_z0 != 0.0) {
    collect2pc = ((q > 0 && setup->impurity_z0 < 0) ||  // holes for p-type 
                  (q < 0 && setup->impurity_z0 > 0));   // electrons for n-type
  } else {                                                // sometimes the impurity_z0 values can be commented out
    collect2pc = ((q > 0 && setup->efld[0][2 + (int)(setup->pc_length/setup->xtal_grid)].z < 0) ||  // holes for p-type 
                  (q < 0 && setup->efld[0][2 + (int)(setup->pc_length/setup->xtal_grid)].z > 0));   // electrons for n-type
  }
  /*
  if (q > 0) {
    diffusion_coeff = TWO_TIMES_DIFFUSION_COEF_H;
  } else {
    diffusion_coeff = TWO_TIMES_DIFFUSION_COEF_E;
  }
  */
  ntsteps = setup->time_steps_calc;
  for (t = 0; drift_velocity(new_pt, q, &v, setup) >= 0 && !stop_drifting; t++) { 
    if (q > 0) {
      setup->dpath_h[t] = new_pt;
    } else {
      setup->dpath_e[t] = new_pt;
    }
    if (collect2pc) {
      if (t == 0) {
	vel1 = setup->final_vel = setup->initial_vel = vector_length(v);
	setup->final_charge_size = setup->charge_cloud_size;
	if (setup->use_diffusion) {
	  if (setup->final_charge_size < 0.01) setup->final_charge_size = 0.01;
	  /* for a spherically symmetric charge cloud, the equivalent
	     delta-E at a distance of 1 sigma from the cloud center is
	     dE = Q/(4*pi*epsilon*sigma^2)  (Q is charge inside the 3D 1-sigma envelope)
	     dE (V/cm) = Q (C) * 1/(4*pi*epsilon) (N m2 / C2) / sigma2 (mm2)
	     1 V/m = 1 N/C
	     dE (V/cm) = Q (C) * 1/(4*pi*epsilon) (V m / C) / sigma2 (mm2)
	     dE (V/cm) = repulsion_fact * FWHM/sigma / (FWHM^2) (mm2), so
	     repulsion_fact = (FWHM/sigma)^3 * Q (C) * 1/(4*pi*epsilon) (V m / C) * mm/m * mm/cm
	  */
	  if (setup->energy > 0.1) {  // set up charge cloud self-repulsion
	    repulsion_fact = setup->energy * 0.67*0.67*0.67 / 0.003; // charge in 1 sigma (3D)
	    repulsion_fact /= 6.241e18;        // convert to Coulombs
	    repulsion_fact *= 9.0e13/16.0;     // 1/(4*pi*epsilon)  (N m2 / C2) * 1e4
	    repulsion_fact *= 2.355*2.355*2.355;      // convert FWHM to sigma
	  }
	}
	TELL_CHATTY("initial v: %f (%e %e %e)\n",
		    setup->initial_vel, v.x, v.y, v.z);
      } else if (setup->use_diffusion) {
	vel0 = vel1;
	vel1 = vector_length(v);
	setup->final_charge_size *= vel1/vel0;  // effect of acceleration
	// include effects of acceleration and diffusion on cloud size
	dv = repulsion_fact * setup->dv_dE /        // effect of repulsion
	        (setup->final_charge_size*setup->final_charge_size);
	// FIXME? this next line could more more fine-grained
	if (dv > 0.05) dv = 0.05;  // on account of drift velocity saturation
	ds_dt = dv + DIFFUSION_COEF/setup->final_charge_size;  // effect of diffusion
	if (ds_dt > 0.05 || ds_dt * setup->step_time_calc > 0.1) {
	  // nonlinear growth due to small size; need more careful calculation
	  TELL_CHATTY("ds_dt = %.2f; size = %.2f", ds_dt, setup->final_charge_size);
	  // ds_dt = 0.05;  // artificially limit nonlinear growth
	  ds2 = 2.0 * DIFFUSION_COEF * setup->step_time_calc; // increase^2 from diff.
	  ds3 = (setup->final_charge_size*setup->final_charge_size *
		 (setup->final_charge_size +
		  3.0 * dv * setup->step_time_calc));         // FWHM^3 after repulsion
	  setup->final_charge_size = sqrt(ds2 + pow(ds3, 0.6667)); 
	  TELL_CHATTY(" -> %.2f\n", setup->final_charge_size);
	} else {
	  setup->final_charge_size +=  ds_dt * setup->step_time_calc;  // effect of diff. + rep.
	}
      }
    }

    TELL_CHATTY("pt: (%.2f %.2f %.2f), v: (%e %e %e)",
		new_pt.x, new_pt.y, new_pt.z, v.x, v.y, v.z);
    if (0 && t >= ntsteps - 2) {   // DRC removed (if(0)) Oct 2019; t>ntsteps now dealt with below
      if (collect2pc || wpot > WP_THRESH_ELECTRONS) {
	/* for p-type, this is hole or electron+high wp */
	TELL_CHATTY("\nExceeded maximum number of time steps (%d)\n", ntsteps);
	low_field = 1;
	// return -1;
      }
      break;
    }
    if (wpotential(new_pt, &wpot, setup) != 0) {
      TELL_NORMAL("\nCan calculate velocity but not WP at %s!\n",
		  pt_to_str(tmpstr, MAX_LINE, new_pt));
      return -1;
    }
    if (wpot < 0.0) wpot = 0.0;
    TELL_CHATTY(" -> wp: %.10f\n", wpot);

    /* ------------- DCR added Oct 2019: if WP is very small or large, then stop drifting */
    if (!collect2pc &&    wpot < 5.0e-5) stop_drifting = 2;    // drifting to outside
    if (collect2pc && 1.0-wpot < 5.0e-5) stop_drifting = 3;    // drifting to point contact
    if (t >= setup->time_steps_calc - 2) stop_drifting = 1;    // have run out of time...

    if (t > 0) signal[t] += q*(wpot - wpot_old);
    // FIXME! Hack added by DCR to deal with undepleted point contact
    if (wpot >= 0.999 && (wpot - wpot_old) < 0.0002) {
      low_field = 1;
      break;
    }
    wpot_old = wpot;

    dx = vector_scale(v, setup->step_time_calc);
    if (surface_drift && dx.z < 0) {
      dx.x *= setup->surface_drift_vel_factor;  // Hmmm... should the default be zero or one?
      dx.y *= setup->surface_drift_vel_factor;
      dx.z = 0;
    }
    new_pt = vector_add(new_pt, dx);
    // q = charge_trapping(dx, q); //FIXME

    // look for charges on passivated surface of a PPC detector
    if (new_pt.z < 0 &&                                    // at or below surface, and
        (setup->wrap_around_radius <= setup->pc_radius ||  // this is a PPC detector
         new_pt.x*new_pt.x + new_pt.y*new_pt.y <           // or point is inside wrap-around
         setup->wrap_around_radius*setup->wrap_around_radius)) {
      TELL_CHATTY(" -> Passivated surface! q = %.2f  r = %.2f\n",
                  q, sqrt(new_pt.x*new_pt.x + new_pt.y*new_pt.y));
      //break;
      surface_drift = 1;
      new_pt.z = 0;
    }

  }
  if (t == 0) {
    TELL_CHATTY("The starting point %s is outside the WP or field.\n",
		pt_to_str(tmpstr, MAX_LINE, pt));
    return -1;
  }

  if (low_field) {
    TELL_CHATTY("Low field near point contact; this may or may not be a problem.\n");
  } else {
    TELL_CHATTY("Drifted to edge of WP or field grid, point: %s q: %.2f\n", 
		pt_to_str(tmpstr, MAX_LINE, new_pt), q);
  }
  if (!low_field && stop_drifting<2) {
    /* figure out how much we must drift to get to the crystal boundary */
    for (n = 0; n+t < ntsteps && !outside_detector(new_pt, setup); n++){
      new_pt = vector_add(new_pt, dx);
      if (q > 0) setup->dpath_h[t+n] = new_pt;
      else setup->dpath_e[t+n] = new_pt;
    }
    if (n == 0) n = 1; /* always drift at least one more step */
    // TELL_CHATTY(
    TELL_NORMAL("q: %.1f t: %d n: %d ((%.2f %.2f %.2f)=>(%.2f %.2f %.2f))\n", 
		q, t, n, pt.x, pt.y, pt.z, new_pt.x, new_pt.y, new_pt.z);

    if (n + t >= ntsteps){
      n = ntsteps - t;
      if (q > 0 || wpot > WP_THRESH_ELECTRONS) { /* hole or electron+high wp */
	TELL_CHATTY("Exceeded maximum number of time steps (%d)\n", ntsteps);
        /* check WP to see if we have produced most of the signal */
        if ((wpot < 0.95 || wpot > 0.05) &&
            wpotential(new_pt, &wpot2, setup) != 0) {
          TELL_CHATTY("Cannot finish drifting to make at least 95\% of signal.\n");
          return -1;  /* FIXME: could this be improved? */
        }
        /* drift to new_pt and wpot2 */
        dwpot = (wpot2 - wpot)/n;
      }
    } else {
      /* make WP go gradually to 1 or 0 */
      if (wpot > 0.3) {
        dwpot = (1.0 - wpot)/n;
      } else {
        dwpot = - wpot/n;
      }
    }

    /* now drift the final n steps */
    dx = vector_scale(v, setup->step_time_calc);
    if (new_pt.z > 0) {               // charges NOT on passivated surface
      for (i = 0; i < n; i++){
        signal[i+t] += q*dwpot;
        // q = charge_trapping(dx, q); //FIXME
      }
    }
  }
  TELL_CHATTY("q:%.2f pt: %s\n", q, pt_to_str(tmpstr, MAX_LINE, pt));
  if (q > 0) setup->final_vel = vector_length(v);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movlpd %xmm0, -0x20(%rbp)
movss %xmm1, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x8(%rbp)
movq %rdi, -0x28(%rbp)
movss %xmm2, -0x2c(%rbp)
movq %rsi, -0x38(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x27c(%rbp)
movss 0xa025(%rip), %xmm0     # 0xd008
movss %xmm0, -0x280(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x288(%rbp)
movl $0x0, -0x2c0(%rbp)
movl $0x0, -0x2c4(%rbp)
movl $0x0, -0x2c8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x25c(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x254(%rbp)
movq -0x38(%rbp), %rax
movss 0x58(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3042
jp 0x3042
jmp 0x30af
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3064
movq -0x38(%rbp), %rcx
movb $0x1, %al
xorps %xmm0, %xmm0
ucomiss 0x58(%rcx), %xmm0
movb %al, -0x459(%rbp)
ja 0x3099
xorl %eax, %eax
xorps %xmm0, %xmm0
ucomiss -0x2c(%rbp), %xmm0
movb %al, -0x45a(%rbp)
jbe 0x308d
movq -0x38(%rbp), %rax
movss 0x58(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %al
movb %al, -0x45a(%rbp)
movb -0x45a(%rbp), %al
movb %al, -0x459(%rbp)
movb -0x459(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2bc(%rbp)
jmp 0x3170
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x30fd
movq -0x38(%rbp), %rax
movq 0x1470(%rax), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x38(%rbp), %rax
divss 0x54(%rax), %xmm0
cvttss2si %xmm0, %eax
addl $0x2, %eax
cltq
imulq $0xc, %rax, %rax
addq %rax, %rcx
movb $0x1, %al
xorps %xmm0, %xmm0
ucomiss 0x8(%rcx), %xmm0
movb %al, -0x45b(%rbp)
ja 0x315f
xorl %eax, %eax
xorps %xmm0, %xmm0
ucomiss -0x2c(%rbp), %xmm0
movb %al, -0x45c(%rbp)
jbe 0x3153
movq -0x38(%rbp), %rax
movq 0x1470(%rax), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movss 0xc(%rcx), %xmm0
movq -0x38(%rbp), %rcx
divss 0x54(%rcx), %xmm0
cvttss2si %xmm0, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %al
movb %al, -0x45c(%rbp)
movb -0x45c(%rbp), %al
movb %al, -0x45b(%rbp)
movb -0x45b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2bc(%rbp)
movq -0x38(%rbp), %rax
movl 0x390(%rax), %eax
movl %eax, -0x2ac(%rbp)
movl $0x0, -0x2b4(%rbp)
movss -0x2c(%rbp), %xmm2
movq -0x38(%rbp), %rsi
movl -0x254(%rbp), %eax
movl %eax, -0x2d0(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movsd -0x2d8(%rbp), %xmm0
movss -0x2d0(%rbp), %xmm1
leaq -0x268(%rbp), %rdi
callq 0x7cd0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x45d(%rbp)
jl 0x31ea
cmpl $0x0, -0x2c8(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x45d(%rbp)
movb -0x45d(%rbp), %al
testb $0x1, %al
jne 0x31f9
jmp 0x3ba3
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3234
movq -0x38(%rbp), %rax
movq 0x1588(%rax), %rax
movslq -0x2b4(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x25c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x254(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3260
movq -0x38(%rbp), %rax
movq 0x1580(%rax), %rax
movslq -0x2b4(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x25c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x254(%rbp), %ecx
movl %ecx, 0x8(%rax)
cmpl $0x0, -0x2bc(%rbp)
je 0x36f9
cmpl $0x0, -0x2b4(%rbp)
jne 0x3428
movl -0x260(%rbp), %eax
movl %eax, -0x2e0(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movsd -0x2e8(%rbp), %xmm0
movss -0x2e0(%rbp), %xmm1
callq 0x8c40
movq -0x38(%rbp), %rax
movss %xmm0, 0x1594(%rax)
movq -0x38(%rbp), %rax
movss %xmm0, 0x1598(%rax)
movss %xmm0, -0x27c(%rbp)
movq -0x38(%rbp), %rax
movss 0x39c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, 0x15a8(%rax)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x3a0(%rax)
je 0x33d8
movq -0x38(%rbp), %rax
movsd 0x9d5e(%rip), %xmm0     # 0xd060
ucomisd 0x15a8(%rax), %xmm0
jbe 0x3320
movq -0x38(%rbp), %rax
movsd 0x9d48(%rip), %xmm0     # 0xd060
movsd %xmm0, 0x15a8(%rax)
movq -0x38(%rbp), %rax
movss 0x3a4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x9d10(%rip), %xmm1     # 0xd048
ucomisd %xmm1, %xmm0
jbe 0x33d6
movq -0x38(%rbp), %rax
movss 0x3a4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x9ce6(%rip), %xmm1     # 0xd040
mulsd %xmm1, %xmm0
movsd 0x9cda(%rip), %xmm1     # 0xd040
mulsd %xmm1, %xmm0
movsd 0x9cce(%rip), %xmm1     # 0xd040
mulsd %xmm1, %xmm0
movsd 0x9d02(%rip), %xmm1     # 0xd080
divsd %xmm1, %xmm0
movsd %xmm0, -0x288(%rbp)
movsd -0x288(%rbp), %xmm0
movsd 0x9cde(%rip), %xmm1     # 0xd078
divsd %xmm1, %xmm0
movsd %xmm0, -0x288(%rbp)
movsd 0x9cc2(%rip), %xmm0     # 0xd070
mulsd -0x288(%rbp), %xmm0
movsd %xmm0, -0x288(%rbp)
movsd 0x9ca2(%rip), %xmm0     # 0xd068
mulsd -0x288(%rbp), %xmm0
movsd %xmm0, -0x288(%rbp)
jmp 0x33d8
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3423
movq -0x38(%rbp), %rax
movss 0x1594(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x268(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x264(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x260(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x9e3d(%rip), %rdi      # 0xd259
movb $0x4, %al
callq 0x2530
jmp 0x36f7
movq -0x38(%rbp), %rax
cmpl $0x0, 0x3a0(%rax)
je 0x36f5
movss -0x27c(%rbp), %xmm0
movss %xmm0, -0x278(%rbp)
movl -0x260(%rbp), %eax
movl %eax, -0x2f0(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movsd -0x2f8(%rbp), %xmm0
movss -0x2f0(%rbp), %xmm1
callq 0x8c40
movss %xmm0, -0x27c(%rbp)
movss -0x27c(%rbp), %xmm0
divss -0x278(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
mulsd 0x15a8(%rax), %xmm0
movsd %xmm0, 0x15a8(%rax)
movsd -0x288(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss 0x159c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm1
movq -0x38(%rbp), %rax
mulsd 0x15a8(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x2a0(%rbp)
movsd -0x2a0(%rbp), %xmm0
movsd 0x9b40(%rip), %xmm1     # 0xd038
ucomisd %xmm1, %xmm0
jbe 0x350e
movsd 0x9b32(%rip), %xmm0     # 0xd038
movsd %xmm0, -0x2a0(%rbp)
movsd -0x2a0(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss 0x15a0(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x9b12(%rip), %xmm2     # 0xd040
mulsd %xmm2, %xmm1
movq -0x38(%rbp), %rax
divsd 0x15a8(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x2a8(%rbp)
movsd -0x2a8(%rbp), %xmm0
movsd 0x9ade(%rip), %xmm1     # 0xd038
ucomisd %xmm1, %xmm0
ja 0x358e
movsd -0x2a8(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
movsd 0x9ac4(%rip), %xmm1     # 0xd048
ucomisd %xmm1, %xmm0
jbe 0x36bf
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x35b9
movsd -0x2a8(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm1
leaq 0x9cc1(%rip), %rdi      # 0xd273
movb $0x2, %al
callq 0x2530
movq -0x38(%rbp), %rax
movss 0x15a0(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x9a6f(%rip), %xmm0     # 0xd040
mulsd %xmm0, %xmm1
movsd 0x9a53(%rip), %xmm0     # 0xd030
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x290(%rbp)
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm0
movq -0x38(%rbp), %rax
mulsd 0x15a8(%rax), %xmm0
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm2
movsd 0x9a2f(%rip), %xmm1     # 0xd058
mulsd -0x2a0(%rbp), %xmm1
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x298(%rbp)
movsd -0x290(%rbp), %xmm0
movsd %xmm0, -0x468(%rbp)
movsd -0x298(%rbp), %xmm0
movsd 0x99db(%rip), %xmm1     # 0xd050
callq 0x2240
movaps %xmm0, %xmm1
movsd -0x468(%rbp), %xmm0
addsd %xmm1, %xmm0
callq 0x2250
movq -0x38(%rbp), %rax
movsd %xmm0, 0x15a8(%rax)
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x36bd
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm0
leaq 0x9bd7(%rip), %rdi      # 0xd28d
movb $0x1, %al
callq 0x2530
jmp 0x36f3
movsd -0x2a8(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movq -0x38(%rbp), %rax
movsd 0x15a8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x15a8(%rax)
jmp 0x36f5
jmp 0x36f7
jmp 0x36f9
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3758
movss -0x25c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x258(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x254(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x268(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movss -0x264(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movss -0x260(%rbp), %xmm5
cvtss2sd %xmm5, %xmm5
leaq 0x9b46(%rip), %rdi      # 0xd297
movb $0x6, %al
callq 0x2530
movq -0x38(%rbp), %rsi
movl -0x254(%rbp), %eax
movl %eax, -0x300(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x308(%rbp)
movsd -0x308(%rbp), %xmm0
movss -0x300(%rbp), %xmm1
leaq -0x3c(%rbp), %rdi
callq 0x77b0
cmpl $0x0, %eax
je 0x37f5
movq -0x38(%rbp), %rax
cmpl $0x1, (%rax)
jl 0x37e9
leaq -0x250(%rbp), %rdi
movl -0x254(%rbp), %eax
movl %eax, -0x310(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x318(%rbp)
movsd -0x318(%rbp), %xmm0
movss -0x310(%rbp), %xmm1
movl $0x200, %esi            # imm = 0x200
callq 0x9160
movq %rax, %rsi
leaq 0x9ad9(%rip), %rdi      # 0xd2bb
movb $0x0, %al
callq 0x2530
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41e4
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x380f
xorps %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x382f
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x9abe(%rip), %rdi      # 0xd2e6
movb $0x1, %al
callq 0x2530
cmpl $0x0, -0x2bc(%rbp)
jne 0x3859
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x983f(%rip), %xmm0     # 0xd088
ucomisd %xmm1, %xmm0
jbe 0x3859
movl $0x2, -0x2c8(%rbp)
cmpl $0x0, -0x2bc(%rbp)
je 0x388f
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x981d(%rip), %xmm1     # 0xd090
subsd %xmm0, %xmm1
movsd 0x9809(%rip), %xmm0     # 0xd088
ucomisd %xmm1, %xmm0
jbe 0x388f
movl $0x3, -0x2c8(%rbp)
movl -0x2b4(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0x390(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jl 0x38b0
movl $0x1, -0x2c8(%rbp)
cmpl $0x0, -0x2b4(%rbp)
jle 0x38e8
movss -0x2c(%rbp), %xmm0
movss -0x3c(%rbp), %xmm2
subss -0x280(%rbp), %xmm2
movq -0x28(%rbp), %rax
movslq -0x2b4(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x979f(%rip), %xmm1     # 0xd098
ucomisd %xmm1, %xmm0
jb 0x392d
movss -0x3c(%rbp), %xmm0
subss -0x280(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x9788(%rip), %xmm0     # 0xd0a0
ucomisd %xmm1, %xmm0
jbe 0x392d
movl $0x1, -0x2c0(%rbp)
jmp 0x3ba3
movss -0x3c(%rbp), %xmm0
movss %xmm0, -0x280(%rbp)
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm2
movl -0x260(%rbp), %eax
movl %eax, -0x330(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x338(%rbp)
movsd -0x338(%rbp), %xmm0
movss -0x330(%rbp), %xmm1
callq 0x8fb0
movss %xmm1, -0x340(%rbp)
movlpd %xmm0, -0x348(%rbp)
movq -0x348(%rbp), %rax
movq %rax, -0x324(%rbp)
movl -0x340(%rbp), %eax
movl %eax, -0x31c(%rbp)
movq -0x324(%rbp), %rax
movq %rax, -0x274(%rbp)
movl -0x31c(%rbp), %eax
movl %eax, -0x26c(%rbp)
cmpl $0x0, -0x2c4(%rbp)
je 0x3a11
xorps %xmm0, %xmm0
ucomiss -0x26c(%rbp), %xmm0
jbe 0x3a11
movq -0x38(%rbp), %rax
movss 0x1590(%rax), %xmm0
mulss -0x274(%rbp), %xmm0
movss %xmm0, -0x274(%rbp)
movq -0x38(%rbp), %rax
movss 0x1590(%rax), %xmm0
mulss -0x270(%rbp), %xmm0
movss %xmm0, -0x270(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x26c(%rbp)
movl -0x254(%rbp), %eax
movl %eax, -0x360(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x368(%rbp)
movsd -0x368(%rbp), %xmm0
movss -0x360(%rbp), %xmm1
movl -0x26c(%rbp), %eax
movl %eax, -0x370(%rbp)
movq -0x274(%rbp), %rax
movq %rax, -0x378(%rbp)
movsd -0x378(%rbp), %xmm2
movss -0x370(%rbp), %xmm3
callq 0x8d60
movss %xmm1, -0x380(%rbp)
movlpd %xmm0, -0x388(%rbp)
movq -0x388(%rbp), %rax
movq %rax, -0x354(%rbp)
movl -0x380(%rbp), %eax
movl %eax, -0x34c(%rbp)
movq -0x354(%rbp), %rax
movq %rax, -0x25c(%rbp)
movl -0x34c(%rbp), %eax
movl %eax, -0x254(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x254(%rbp), %xmm0
jbe 0x3b8d
movq -0x38(%rbp), %rax
movss 0x14(%rax), %xmm1
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
ucomiss %xmm1, %xmm0
jae 0x3b14
movss -0x25c(%rbp), %xmm1
movss -0x25c(%rbp), %xmm2
movss -0x258(%rbp), %xmm0
mulss -0x258(%rbp), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq -0x38(%rbp), %rax
movss 0x14(%rax), %xmm0
movq -0x38(%rbp), %rax
mulss 0x14(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3b8d
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3b78
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x470(%rbp)
movss -0x25c(%rbp), %xmm0
movss -0x25c(%rbp), %xmm2
movss -0x258(%rbp), %xmm1
mulss -0x258(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0x470(%rbp), %xmm0
leaq 0x9784(%rip), %rdi      # 0xd2f5
movb $0x2, %al
callq 0x2530
movl $0x1, -0x2c4(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x254(%rbp)
jmp 0x3b8f
movl -0x2b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b4(%rbp)
jmp 0x318a
cmpl $0x0, -0x2b4(%rbp)
jne 0x3c07
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3bfb
leaq -0x250(%rbp), %rdi
movl -0x8(%rbp), %eax
movl %eax, -0x390(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x398(%rbp)
movsd -0x398(%rbp), %xmm0
movss -0x390(%rbp), %xmm1
movl $0x200, %esi            # imm = 0x200
callq 0x9160
movq %rax, %rsi
leaq 0x972d(%rip), %rdi      # 0xd321
movb $0x0, %al
callq 0x2530
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41e4
cmpl $0x0, -0x2c0(%rbp)
je 0x3c29
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3c27
leaq 0x9734(%rip), %rdi      # 0xd354
movb $0x0, %al
callq 0x2530
jmp 0x3c89
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3c87
leaq -0x250(%rbp), %rdi
movl -0x254(%rbp), %eax
movl %eax, -0x3a0(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movsd -0x3a8(%rbp), %xmm0
movss -0x3a0(%rbp), %xmm1
movl $0x200, %esi            # imm = 0x200
callq 0x9160
movq %rax, %rsi
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x9715(%rip), %rdi      # 0xd395
movb $0x1, %al
callq 0x2530
jmp 0x3c89
cmpl $0x0, -0x2c0(%rbp)
jne 0x412d
cmpl $0x2, -0x2c8(%rbp)
jge 0x412d
movl $0x0, -0x2b8(%rbp)
movl -0x2b8(%rbp), %ecx
addl -0x2b4(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2ac(%rbp), %ecx
movb %al, -0x471(%rbp)
jge 0x3d0a
movq -0x38(%rbp), %rdi
movl -0x254(%rbp), %eax
movl %eax, -0x3b0(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x3b8(%rbp)
movsd -0x3b8(%rbp), %xmm0
movss -0x3b0(%rbp), %xmm1
callq 0x4820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x471(%rbp)
movb -0x471(%rbp), %al
testb $0x1, %al
jne 0x3d19
jmp 0x3e43
movl -0x254(%rbp), %eax
movl %eax, -0x3d0(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x3d8(%rbp)
movsd -0x3d8(%rbp), %xmm0
movss -0x3d0(%rbp), %xmm1
movl -0x26c(%rbp), %eax
movl %eax, -0x3e0(%rbp)
movq -0x274(%rbp), %rax
movq %rax, -0x3e8(%rbp)
movsd -0x3e8(%rbp), %xmm2
movss -0x3e0(%rbp), %xmm3
callq 0x8d60
movss %xmm1, -0x3f0(%rbp)
movlpd %xmm0, -0x3f8(%rbp)
movq -0x3f8(%rbp), %rax
movq %rax, -0x3c4(%rbp)
movl -0x3f0(%rbp), %eax
movl %eax, -0x3bc(%rbp)
movq -0x3c4(%rbp), %rax
movq %rax, -0x25c(%rbp)
movl -0x3bc(%rbp), %eax
movl %eax, -0x254(%rbp)
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3df9
movq -0x38(%rbp), %rax
movq 0x1588(%rax), %rax
movl -0x2b4(%rbp), %ecx
addl -0x2b8(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x25c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x254(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3e2d
movq -0x38(%rbp), %rax
movq 0x1580(%rax), %rax
movl -0x2b4(%rbp), %ecx
addl -0x2b8(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x25c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x254(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3e2f
movl -0x2b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b8(%rbp)
jmp 0x3cad
cmpl $0x0, -0x2b8(%rbp)
jne 0x3e56
movl $0x1, -0x2b8(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x1, (%rax)
jl 0x3ec1
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movl -0x2b4(%rbp), %esi
movl -0x2b8(%rbp), %edx
movss -0x10(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0xc(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x8(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movss -0x25c(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movss -0x258(%rbp), %xmm5
cvtss2sd %xmm5, %xmm5
movss -0x254(%rbp), %xmm6
cvtss2sd %xmm6, %xmm6
leaq 0x9513(%rip), %rdi      # 0xd3cd
movb $0x7, %al
callq 0x2530
movl -0x2b8(%rbp), %eax
addl -0x2b4(%rbp), %eax
cmpl -0x2ac(%rbp), %eax
jl 0x3fda
movl -0x2ac(%rbp), %eax
subl -0x2b4(%rbp), %eax
movl %eax, -0x2b8(%rbp)
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
ja 0x3f13
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x91a7(%rip), %xmm1     # 0xd0b0
ucomisd %xmm1, %xmm0
jbe 0x3fd8
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3f30
movl -0x2ac(%rbp), %esi
leaq 0x94de(%rip), %rdi      # 0xd407
movb $0x0, %al
callq 0x2530
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x9177(%rip), %xmm0     # 0xd0b8
ucomisd %xmm1, %xmm0
ja 0x3f5e
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x90e0(%rip), %xmm1     # 0xd038
ucomisd %xmm1, %xmm0
jbe 0x3fbd
movq -0x38(%rbp), %rsi
movl -0x254(%rbp), %eax
movl %eax, -0x400(%rbp)
movq -0x25c(%rbp), %rax
movq %rax, -0x408(%rbp)
movsd -0x408(%rbp), %xmm0
movss -0x400(%rbp), %xmm1
leaq -0x40(%rbp), %rdi
callq 0x77b0
cmpl $0x0, %eax
je 0x3fbd
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x3fb1
leaq 0x9489(%rip), %rdi      # 0xd433
movb $0x0, %al
callq 0x2530
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41e4
movss -0x40(%rbp), %xmm0
subss -0x3c(%rbp), %xmm0
cvtsi2ssl -0x2b8(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x4042
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x90bd(%rip), %xmm1     # 0xd0a8
ucomisd %xmm1, %xmm0
jbe 0x401d
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x908e(%rip), %xmm0     # 0xd090
subsd %xmm1, %xmm0
cvtsi2sdl -0x2b8(%rbp), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x4040
movss -0x3c(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtsi2ssl -0x2b8(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x4042
movq -0x38(%rbp), %rax
movss 0x394(%rax), %xmm2
movl -0x260(%rbp), %eax
movl %eax, -0x420(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x428(%rbp)
movsd -0x428(%rbp), %xmm0
movss -0x420(%rbp), %xmm1
callq 0x8fb0
movss %xmm1, -0x430(%rbp)
movlpd %xmm0, -0x438(%rbp)
movq -0x438(%rbp), %rax
movq %rax, -0x414(%rbp)
movl -0x430(%rbp), %eax
movl %eax, -0x40c(%rbp)
movq -0x414(%rbp), %rax
movq %rax, -0x274(%rbp)
movl -0x40c(%rbp), %eax
movl %eax, -0x26c(%rbp)
movss -0x254(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x412b
movl $0x0, -0x2b0(%rbp)
movl -0x2b0(%rbp), %eax
cmpl -0x2b8(%rbp), %eax
jge 0x4129
movss -0x2c(%rbp), %xmm0
movss -0x44(%rbp), %xmm2
movq -0x28(%rbp), %rax
movl -0x2b0(%rbp), %ecx
addl -0x2b4(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x2b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b0(%rbp)
jmp 0x40db
jmp 0x412b
jmp 0x412d
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x4195
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x480(%rbp)
leaq -0x250(%rbp), %rdi
movl -0x8(%rbp), %eax
movl %eax, -0x440(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x448(%rbp)
movsd -0x448(%rbp), %xmm0
movss -0x440(%rbp), %xmm1
movl $0x200, %esi            # imm = 0x200
callq 0x9160
movsd -0x480(%rbp), %xmm0
movq %rax, %rsi
leaq 0x92dd(%rip), %rdi      # 0xd46b
movb $0x1, %al
callq 0x2530
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x41dd
movl -0x260(%rbp), %eax
movl %eax, -0x450(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x458(%rbp)
movsd -0x458(%rbp), %xmm0
movss -0x450(%rbp), %xmm1
callq 0x8c40
movq -0x38(%rbp), %rax
movss %xmm0, 0x1598(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq