// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %rbx
movq %rdi, 0xa0(%rsp)
movl $0x0, 0x4c(%rsp)
movss 0x58(%rsi), %xmm4
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm4
jne 0x2bde
jnp 0x2bf5
ucomiss %xmm3, %xmm2
jbe 0x2beb
movb $0x1, %r13b
ucomiss %xmm4, %xmm3
ja 0x2c5f
ucomiss %xmm2, %xmm3
jbe 0x2c5c
ucomiss %xmm3, %xmm4
jmp 0x2c56
ucomiss %xmm3, %xmm2
jbe 0x2c26
movq 0x1470(%rbx), %rax
movss 0xc(%rbx), %xmm3
divss 0x54(%rbx), %xmm3
cvttss2si %xmm3, %ecx
movq (%rax), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x1, %r13b
xorps %xmm3, %xmm3
ucomiss 0x20(%rax,%rcx,4), %xmm3
ja 0x2c5f
xorps %xmm4, %xmm4
ucomiss %xmm2, %xmm4
jbe 0x2c5c
movq 0x1470(%rbx), %rax
movss 0xc(%rbx), %xmm3
divss 0x54(%rbx), %xmm3
cvttss2si %xmm3, %ecx
movq (%rax), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movss 0x20(%rax,%rcx,4), %xmm3
ucomiss %xmm4, %xmm3
seta %r13b
jmp 0x2c5f
xorl %r13d, %r13d
movl 0x390(%rbx), %r14d
leaq 0x30(%rsp), %rdi
movss %xmm1, 0x18(%rsp)
movq %rbx, %rsi
movss %xmm2, 0x14(%rsp)
movaps %xmm0, 0x50(%rsp)
callq 0x5872
testl %eax, %eax
js 0x33c5
xorps %xmm0, %xmm0
xorl %eax, %eax
movss 0x14(%rsp), %xmm1
ucomiss %xmm0, %xmm1
seta %al
movq %r14, 0x90(%rsp)
movq %r14, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x1580(,%rax,8), %rax
movq %rax, 0xa8(%rsp)
xorl %r15d, %r15d
movss 0x5332(%rip), %xmm0     # 0x8004
movss %xmm0, 0x40(%rsp)
movl $0x8, %r12d
xorl %r14d, %r14d
movss 0x18(%rsp), %xmm3
movapd 0x50(%rsp), %xmm5
xorpd %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0xa8(%rsp), %rax
movq (%rbx,%rax), %rax
movlpd %xmm5, -0x8(%rax,%r12)
movss %xmm3, (%rax,%r12)
testb %r13b, %r13b
movss %xmm3, 0xc(%rsp)
movapd %xmm5, 0x20(%rsp)
je 0x2e97
testq %r15, %r15
je 0x2ea2
cmpl $0x0, 0x3a0(%rbx)
je 0x2e97
movsd 0x30(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
callq 0x5e59
movaps %xmm0, %xmm4
divss 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd 0x15a8(%rbx), %xmm1
movsd %xmm1, 0x15a8(%rbx)
xorps %xmm0, %xmm0
cvtss2sd 0x159c(%rbx), %xmm0
mulsd 0x98(%rsp), %xmm0
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd 0x529f(%rip), %xmm3     # 0x8040
movapd %xmm3, %xmm5
minsd %xmm0, %xmm5
cvtss2sd 0x15a0(%rbx), %xmm6
mulsd 0x528f(%rip), %xmm6     # 0x8048
movapd %xmm6, %xmm0
divsd %xmm1, %xmm0
addsd %xmm5, %xmm0
ucomisd %xmm3, %xmm0
ja 0x2de8
xorps %xmm3, %xmm3
cvtss2sd 0x394(%rbx), %xmm3
mulsd %xmm0, %xmm3
ucomisd 0x526e(%rip), %xmm3     # 0x8050
jbe 0x2fd9
cmpl $0x2, (%rbx)
movss %xmm4, 0x10(%rsp)
jl 0x2e36
leaq 0x5499(%rip), %rdi      # 0x8293
movb $0x2, %al
movsd %xmm5, 0x80(%rsp)
callq 0x25b2
movsd 0x80(%rsp), %xmm5
xorps %xmm6, %xmm6
cvtss2sd 0x15a0(%rbx), %xmm6
movsd 0x15a8(%rbx), %xmm1
mulsd 0x521a(%rip), %xmm6     # 0x8048
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm6, %xmm6
xorps %xmm0, %xmm0
cvtss2sd 0x394(%rbx), %xmm0
mulsd %xmm0, %xmm6
movsd %xmm6, 0x80(%rsp)
mulsd 0x51fe(%rip), %xmm5     # 0x8058
mulsd %xmm0, %xmm5
addsd %xmm1, %xmm5
mulsd %xmm2, %xmm5
movapd %xmm5, %xmm0
movsd 0x51ee(%rip), %xmm1     # 0x8060
callq 0x2280
addsd 0x80(%rsp), %xmm0
ucomisd 0x5240(%rip), %xmm0     # 0x80c8
jb 0x2f98
sqrtsd %xmm0, %xmm0
jmp 0x2f9d
movss 0x10(%rsp), %xmm4
jmp 0x2ff1
movsd 0x30(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
callq 0x5e59
movaps %xmm0, %xmm4
movss %xmm0, 0x1594(%rbx)
movss %xmm0, 0x1598(%rbx)
xorps %xmm0, %xmm0
cvtss2sd 0x39c(%rbx), %xmm0
movsd %xmm0, 0x15a8(%rbx)
cmpl $0x0, 0x3a0(%rbx)
je 0x2f53
movsd 0x517e(%rip), %xmm1     # 0x8068
ucomisd %xmm0, %xmm1
jbe 0x2f01
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, 0x15a8(%rbx)
xorps %xmm0, %xmm0
cvtss2sd 0x3a4(%rbx), %xmm0
ucomisd 0x513c(%rip), %xmm0     # 0x8050
jbe 0x2f53
movsd 0x512a(%rip), %xmm1     # 0x8048
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd 0x513e(%rip), %xmm0     # 0x8070
divsd 0x513e(%rip), %xmm0     # 0x8078
mulsd 0x513e(%rip), %xmm0     # 0x8080
mulsd 0x513e(%rip), %xmm0     # 0x8088
movsd %xmm0, 0x98(%rsp)
cmpl $0x2, (%rbx)
jl 0x2f90
xorps %xmm0, %xmm0
cvtss2sd %xmm4, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x30(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x34(%rsp), %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0x38(%rsp), %xmm3
leaq 0x52f8(%rip), %rdi      # 0x8279
movb $0x4, %al
movss %xmm4, 0x10(%rsp)
callq 0x25b2
jmp 0x2fbe
movss %xmm4, 0x10(%rsp)
jmp 0x2fcc
callq 0x2290
movss 0x10(%rsp), %xmm1
movsd %xmm0, 0x15a8(%rbx)
cmpl $0x2, (%rbx)
jl 0x2fc6
leaq 0x52f6(%rip), %rdi      # 0x82ad
movb $0x1, %al
callq 0x25b2
movss 0x10(%rsp), %xmm4
jmp 0x2fe5
movss %xmm1, 0x10(%rsp)
movss 0xc(%rsp), %xmm3
movaps 0x20(%rsp), %xmm5
jmp 0x3051
addsd %xmm1, %xmm3
movsd %xmm3, 0x15a8(%rbx)
movss 0xc(%rsp), %xmm3
movapd 0x20(%rsp), %xmm5
cmpl $0x2, (%rbx)
jl 0x304b
xorps %xmm0, %xmm0
cvtss2sd %xmm5, %xmm0
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
xorps %xmm1, %xmm1
cvtss2sd %xmm5, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0x30(%rsp), %xmm3
movss %xmm4, 0x10(%rsp)
xorps %xmm4, %xmm4
cvtss2sd 0x34(%rsp), %xmm4
xorps %xmm5, %xmm5
cvtss2sd 0x38(%rsp), %xmm5
leaq 0x5280(%rip), %rdi      # 0x82b7
movb $0x6, %al
callq 0x25b2
movaps 0x20(%rsp), %xmm5
movss 0xc(%rsp), %xmm3
jmp 0x3051
movss %xmm4, 0x10(%rsp)
movaps %xmm5, %xmm0
movaps %xmm3, %xmm1
leaq 0x1c(%rsp), %rdi
movq %rbx, %rsi
callq 0x53ba
testl %eax, %eax
jne 0x33fc
movss 0x1c(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x3085
movl $0x0, 0x1c(%rsp)
xorps %xmm0, %xmm0
cmpl $0x2, (%rbx)
jl 0x309c
cvtss2sd %xmm0, %xmm0
leaq 0x5271(%rip), %rdi      # 0x8306
movb $0x1, %al
callq 0x25b2
movss 0x1c(%rsp), %xmm4
xorps %xmm0, %xmm0
cvtss2sd %xmm4, %xmm0
testb %r13b, %r13b
movss 0x14(%rsp), %xmm2
je 0x30d5
movsd 0x4fdc(%rip), %xmm1     # 0x8098
subsd %xmm0, %xmm1
movsd 0x4fc8(%rip), %xmm3     # 0x8090
ucomisd %xmm1, %xmm3
jbe 0x30f0
movl $0x3, %ebp
jmp 0x30f2
movsd 0x4fb3(%rip), %xmm1     # 0x8090
ucomisd %xmm0, %xmm1
movss 0x40(%rsp), %xmm3
jbe 0x30fa
movl $0x2, %ebp
jmp 0x30fc
xorl %ebp, %ebp
movss 0x40(%rsp), %xmm3
jmp 0x30fc
xorl %ebp, %ebp
movslq 0x390(%rbx), %rax
addq $-0x2, %rax
cmpq %rax, %r15
movl $0x1, %eax
cmovgel %eax, %ebp
testq %r15, %r15
je 0x3136
movaps %xmm4, %xmm1
subss %xmm3, %xmm1
mulss %xmm2, %xmm1
movq 0xa0(%rsp), %rax
addss (%rax,%r15,4), %xmm1
movss %xmm1, (%rax,%r15,4)
ucomisd 0x4f62(%rip), %xmm0     # 0x80a0
jb 0x315d
movaps %xmm4, %xmm0
subss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x4f55(%rip), %xmm1     # 0x80a8
ucomisd %xmm0, %xmm1
ja 0x343d
movss %xmm4, 0x40(%rsp)
movss 0x394(%rbx), %xmm2
movsd 0x30(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
callq 0x5f13
movaps %xmm0, %xmm3
movaps %xmm1, %xmm4
testl %r14d, %r14d
je 0x31ae
xorps %xmm0, %xmm0
ucomiss %xmm4, %xmm0
movss 0xc(%rsp), %xmm1
movaps 0x20(%rsp), %xmm0
jbe 0x31b9
movss 0x1590(%rbx), %xmm2
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
mulps %xmm2, %xmm3
xorps %xmm4, %xmm4
jmp 0x31b9
movss 0xc(%rsp), %xmm1
movaps 0x20(%rsp), %xmm0
movaps %xmm3, 0x80(%rsp)
movaps %xmm3, %xmm2
movss %xmm4, 0x7c(%rsp)
movaps %xmm4, %xmm3
callq 0x5ea4
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
movaps %xmm0, 0x20(%rsp)
jbe 0x3264
movss 0x10(%rbx), %xmm2
movss 0x14(%rbx), %xmm5
ucomiss %xmm5, %xmm2
movss 0x14(%rsp), %xmm2
jae 0x3216
movaps %xmm0, %xmm4
mulps %xmm0, %xmm4
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
movaps %xmm0, %xmm3
mulss %xmm0, %xmm3
addss %xmm4, %xmm3
mulss %xmm5, %xmm5
ucomiss %xmm3, %xmm5
jbe 0x326a
xorps %xmm1, %xmm1
movl $0x1, %r14d
cmpl $0x2, (%rbx)
jl 0x326a
movaps %xmm0, %xmm2
mulps %xmm0, %xmm2
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm0, %xmm1
mulss %xmm0, %xmm1
addss %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
leaq 0x50c7(%rip), %rdi      # 0x8315
movsd 0x68(%rsp), %xmm0
movb $0x2, %al
callq 0x25b2
movaps 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
movss 0x14(%rsp), %xmm2
movss %xmm1, 0xc(%rsp)
incq %r15
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x5872
movaps 0x20(%rsp), %xmm5
movss 0xc(%rsp), %xmm3
testl %eax, %eax
movss 0x18(%rsp), %xmm1
movapd 0x50(%rsp), %xmm0
js 0x32a7
addq $0xc, %r12
testl %ebp, %ebp
je 0x2d04
cmpl $0x1, (%rbx)
jle 0x32f2
leaq 0xb0(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movaps %xmm5, %xmm0
movaps %xmm3, %xmm1
callq 0x5ff7
leaq 0x50ea(%rip), %rdi      # 0x83b5
movq %rax, %rsi
movsd 0x68(%rsp), %xmm0
movb $0x1, %al
callq 0x25b2
movaps 0x20(%rsp), %xmm5
movss 0xc(%rsp), %xmm3
movapd 0x50(%rsp), %xmm0
movss 0x18(%rsp), %xmm1
cmpl $0x1, %ebp
movss 0x14(%rsp), %xmm2
ja 0x36ad
xorl %r14d, %r14d
movq 0x90(%rsp), %rcx
cmpl %r15d, %ecx
jle 0x3481
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomiss %xmm0, %xmm2
seta %al
subq %r15, %rcx
movq %rcx, 0x40(%rsp)
leaq 0x1580(,%rax,8), %r13
movl %r15d, %eax
leaq (%rax,%rax,2), %rax
leaq 0x8(,%rax,4), %rbp
movq 0x70(%rsp), %r12
subl %r15d, %r12d
xorl %r14d, %r14d
movss %xmm3, 0xc(%rsp)
movaps %xmm5, 0x20(%rsp)
movaps %xmm5, %xmm0
movaps %xmm3, %xmm1
movq %rbx, %rdi
callq 0x3a34
testl %eax, %eax
jne 0x3471
movaps 0x20(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
movaps 0x80(%rsp), %xmm2
movss 0x7c(%rsp), %xmm3
callq 0x5ea4
movaps %xmm0, %xmm5
movaps %xmm1, %xmm3
movq (%rbx,%r13), %rax
movlps %xmm0, -0x8(%rax,%rbp)
movss %xmm1, (%rax,%rbp)
incq %r14
addq $0xc, %rbp
cmpq %r14, %r12
jne 0x334b
movss %xmm3, 0xc(%rsp)
movq 0x40(%rsp), %r14
movss 0x14(%rsp), %xmm2
movaps 0x50(%rsp), %xmm0
jmp 0x3481
movl (%rbx), %eax
movss 0x18(%rsp), %xmm1
movapd 0x50(%rsp), %xmm0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jl 0x3705
leaq 0xb0(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x5ff7
leaq 0x4f47(%rip), %rdi      # 0x8341
jmp 0x342e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x0, (%rbx)
jle 0x3705
leaq 0xb0(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movaps 0x20(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
callq 0x5ff7
leaq 0x4ead(%rip), %rdi      # 0x82db
movq %rax, %rsi
xorl %eax, %eax
callq 0x25b2
jmp 0x3705
movl (%rbx), %eax
testq %r15, %r15
je 0x33c7
cmpl $0x2, %eax
jl 0x36e1
leaq 0x4f20(%rip), %rdi      # 0x8374
xorl %eax, %eax
callq 0x25b2
movaps 0x50(%rsp), %xmm0
movss 0x14(%rsp), %xmm2
movss 0x18(%rsp), %xmm1
jmp 0x36ad
movss 0x14(%rsp), %xmm2
movaps 0x50(%rsp), %xmm0
movaps 0x20(%rsp), %xmm5
cmpl $0x1, %r14d
movl %r14d, %ebp
adcl $0x0, %ebp
cmpl $0x0, (%rbx)
jle 0x34ef
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0x18(%rsp), %xmm3
xorps %xmm4, %xmm4
cvtss2sd %xmm5, %xmm4
movaps %xmm5, %xmm0
shufps $0x55, %xmm5, %xmm0     # xmm0 = xmm0[1,1],xmm5[1,1]
movaps %xmm5, 0x20(%rsp)
xorps %xmm5, %xmm5
cvtss2sd %xmm0, %xmm5
cvtss2sd 0xc(%rsp), %xmm6
leaq 0x4f1b(%rip), %rdi      # 0x83ed
movsd 0x68(%rsp), %xmm0
movl %r15d, %esi
movl %ebp, %edx
movb $0x7, %al
callq 0x25b2
movaps 0x20(%rsp), %xmm5
movss 0x14(%rsp), %xmm2
movl %r14d, %eax
cmpq $0x1, %rax
adcq $0x0, %rax
addl %r15d, %eax
cmpl 0x70(%rsp), %eax
jge 0x3546
movss 0x1c(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
ucomisd 0x4ba8(%rip), %xmm0     # 0x80c0
jbe 0x35f7
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd 0x4b6b(%rip), %xmm2     # 0x8098
subsd %xmm0, %xmm2
divsd %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movaps %xmm0, 0x20(%rsp)
jmp 0x363e
movq 0x90(%rsp), %r14
subq %r15, %r14
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
ja 0x3570
xorps %xmm0, %xmm0
cvtss2sd 0x1c(%rsp), %xmm0
ucomisd 0x4b46(%rip), %xmm0     # 0x80b0
jbe 0x3610
cmpl $0x2, (%rbx)
jl 0x3592
leaq 0x4eab(%rip), %rdi      # 0x8427
movq 0x70(%rsp), %rsi
xorl %eax, %eax
movaps %xmm5, 0x20(%rsp)
callq 0x25b2
movaps 0x20(%rsp), %xmm5
movss 0x1c(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0x4b11(%rip), %xmm2     # 0x80b8
ucomisd %xmm1, %xmm2
ja 0x35bb
xorpd %xmm2, %xmm2
ucomisd 0x4a87(%rip), %xmm1     # 0x8040
jbe 0x3626
leaq 0x4c(%rsp), %rdi
movapd %xmm5, %xmm0
movss 0xc(%rsp), %xmm1
movq %rbx, %rsi
callq 0x53ba
testl %eax, %eax
je 0x361a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, (%rbx)
jl 0x3705
leaq 0x4e68(%rip), %rdi      # 0x8453
xorl %eax, %eax
callq 0x25b2
jmp 0x3705
xorps 0x4ad2(%rip), %xmm1     # 0x80d0
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
divss %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
jmp 0x363e
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
jmp 0x363b
movss 0x4c(%rsp), %xmm2
movss 0x1c(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r14d, %xmm1
subss %xmm0, %xmm2
divss %xmm1, %xmm2
movaps %xmm2, 0x20(%rsp)
movl %r14d, %ebp
movss 0x394(%rbx), %xmm2
movsd 0x30(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
callq 0x5f13
xorps %xmm0, %xmm0
movss 0xc(%rsp), %xmm1
ucomiss %xmm0, %xmm1
movss 0x18(%rsp), %xmm1
movss 0x14(%rsp), %xmm2
movapd 0x50(%rsp), %xmm0
movaps 0x20(%rsp), %xmm4
jbe 0x36ad
testl %ebp, %ebp
jle 0x36ad
movl %ebp, %eax
movl %r15d, %ecx
movq 0xa0(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
mulss %xmm2, %xmm4
movss (%rcx,%rdx,4), %xmm3
addss %xmm4, %xmm3
movss %xmm3, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x3697
cmpl $0x2, (%rbx)
jl 0x36e1
leaq 0xb0(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x5ff7
leaq 0x4dc0(%rip), %rdi      # 0x848b
movsd 0x68(%rsp), %xmm0
movq %rax, %rsi
movb $0x1, %al
callq 0x25b2
movss 0x14(%rsp), %xmm2
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jbe 0x3705
movsd 0x30(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
callq 0x5e59
movss %xmm0, 0x1598(%rbx)
movl %ebp, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq