// File: /workspace/github_c_makefile_star2_O3/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/smooth_seis_rates.c
// Function: smooth_seis_rates
void smooth_seis_rates(struct rates* seisr, struct smoothp* smp, struct eqcat* catn, struct boundaries* reg, struct compl_levels* cat_comp, struct catalog* cat_par)
/*--------------------------------------------------------------------------*/
{
  int cnt, ix, iy, ix1, iy1, n;
  int log_shift_eq, log_shift_pt, log_actual_eq_loc;
  int imaxv=0, tot_asum_int;
//  float maxv=0.0, tot_asum, n_eff, eq_rate, beta, area_scaling;
  float maxv=0.0, tot_asum, n_eff, eq_rate, area_scaling;
//  float lonEq, latEq, lonPt, latPt, sigma, avg_lat;
  float lonEq, latEq, lonPt, latPt, sigma;
//  float lonEq1, latEq1;
  float dist, az, baz, fac_exp, sig2, dist2;
  float norm_term, kernel_sum, sum_eqs=0.0;

// logicals for adjusting earthquake points to grid cell locations and shifting grid cell 
  log_actual_eq_loc=0;
  log_shift_eq=1;
  log_shift_pt=0;

// 
//  beta=2.303*cat_par->bval;

// check if smoothing is to be applied
/* -------------------------------------------------------- */
// NO SMOOTHING
// time duration normalization - adjust completeness levels by Wiechert
// adjusts sum for different completeness times, assuming magnitude thresholds differ by 1 m.u.
/* -------------------------------------------------------- */
  if ( smp->apply_sm == 0 ) { 
    for(cnt=0; cnt<catn->nv; cnt++) {
//      iy=(int)nearbyintf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
//      ix=(int)nearbyintf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
      iy=(int)roundf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
      ix=(int)roundf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
      n=iy*reg->nsx+ix;
      catn->agrid_id[cnt]=n;
// convert from numbers to rates here
      eq_rate=calc_seis_rate(smp, catn, cat_comp, cat_par, cnt);
      n_eff=eq_rate;

//  Sum earthquake integers, effective-numbers-earthquakes in asum_cnt and asum
      seisr->asum_cnt_int[n]++;
      seisr->asum_cnt[n]=seisr->asum_cnt[n]+n_eff;
      seisr->asum[n]=seisr->asum[n]+n_eff;
    }
    fprintf(stderr,"Earthquakes assigned to grid cells (no smoothing) - %d earthquakes. ", catn->nv);
    maxv=0.0; imaxv=0; tot_asum=0.0; tot_asum_int=0;
    for(cnt=0; cnt<seisr->nv; cnt++) {
      if (seisr->asum[cnt]>maxv) {
        maxv=seisr->asum[cnt];
        imaxv=cnt;
      } 
      tot_asum_int=tot_asum_int+seisr->asum_cnt_int[cnt];
      tot_asum=tot_asum+seisr->asum[cnt];
    }
    fprintf(stdout,"Earthquakes recovered from grid cells: total-rates,eff=%.2f, total-numbers=%d\n", tot_asum, tot_asum_int);
    fprintf(stdout,"Max number earthquakes in a cell: %.2f\n", maxv);
  }
/* -------------------------------------------------------- */
// SMOOTHING
/* -------------------------------------------------------- */
  else {

// assign eqs to grid cells for un-smoothed results and maximum, un-smoothed rate
//    avg_lat=0.5*(reg->minlon+reg->maxlon);
    for(cnt=0; cnt<catn->nv; cnt++) {
//      iy=(int)nearbyintf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
//      ix=(int)nearbyintf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
      iy=(int)roundf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
      ix=(int)roundf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
      n=iy*reg->nsx+ix;
      catn->agrid_id[cnt]=n;
// convert from numbers to rates here
      eq_rate=calc_seis_rate(smp, catn, cat_comp, cat_par, cnt);
      n_eff=eq_rate;
// summing over asum
// get un-smoothed results for comparison
      seisr->asum_cnt_int[n]++;
      seisr->asum_cnt[n]=seisr->asum_cnt[n]+n_eff;
    }
    for(cnt=0; cnt<seisr->nv; cnt++) seisr->asum_noSm[cnt]=(float)seisr->asum_cnt[cnt];
// get maximum, un-smoothed rate
    maxv=0.0; imaxv=0; tot_asum=0.0; tot_asum_int=0;
    for(cnt=0; cnt<seisr->nv; cnt++) {
      if (seisr->asum_noSm[cnt]>maxv) {
        maxv=seisr->asum_noSm[cnt];
        imaxv=cnt;
      } 
      tot_asum_int=tot_asum_int+seisr->asum_cnt_int[cnt];
      tot_asum=tot_asum+seisr->asum_cnt[cnt];
    }
    fprintf(stdout,"Maximum, un-smoothed rate (eq nos/cell/yr), cell-number: %.2f %d\n", maxv, imaxv);
    fprintf(stdout,"Earthquakes recovered from grid cells: effective-rate=%.2f, #eqs=%d\n", tot_asum, tot_asum_int);
//    fprintf(stdout,"Max number earthquakes in a cell: %.2f\n", maxv);
//    fprintf(stderr,"unsmoothed nv: %d\n", seisr->nv);
//    fprintf(stderr,"maxv: %f \n", seisr->asum_noSm[35185]);

// SMOOTH GRID CELL NUMBERS
// loop over all earthquake sources to get smoothed rates
// assign eq location to center of cell
    fprintf(stderr,"Smoothing rates...\n");
    for(cnt=0; cnt<catn->nv; cnt++) {
      iy1=(int)roundf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
      ix1=(int)roundf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
//      iy1=(int)nearbyintf(((reg->maxlat-catn->lat[cnt])/reg->dlat));
//      ix1=(int)nearbyintf(((catn->lon[cnt]-reg->minlon)/reg->dlon));
//      iy1=(int)((reg->maxlat-catn->lat[cnt])/reg->dlat);
//      ix1=(int)((catn->lon[cnt]-reg->minlon)/reg->dlon);
// convert from numbers to rates here
      eq_rate=calc_seis_rate(smp, catn, cat_comp, cat_par, cnt);
      n_eff=eq_rate;
// check location parameters
      if ( (ix1<0) || (ix1>=reg->nsx) || (iy1<0) || (iy1>=reg->nsy) ) {
        fprintf(stderr,"Error with earthquake location parameters, lon/lat/ix/iy/nsx/nsy: %.3f %.3f %d %d (%d %d)\n", catn->lon[cnt], catn->lat[cnt], ix1, iy1, reg->nsx, reg->nsy);
        exit(1);
      }

// determine location of earthquake epicenter
// original point location
//      lonEq1=catn->lon[cnt];
//      latEq1=catn->lat[cnt];
      if ( log_actual_eq_loc==1 ) {
        lonEq=catn->lon[cnt];
        latEq=catn->lat[cnt];
      }
      else {
// epicenters determined from cell origin
        if ( log_shift_eq==1 ) {
          lonEq=reg->minlon+(ix1+0.5)*reg->dlon;
          latEq=reg->maxlat-(iy1+0.5)*reg->dlat;
        }
// epicenter at center of cell - shifted 0.5 increment
        else {
          lonEq=reg->minlon+(ix1)*reg->dlon;
          latEq=reg->maxlat-(iy1)*reg->dlat;
        }
      }

// optional test of earthquake locations
/*      delaz_(&latEq,&lonEq,&latEq1,&lonEq1,&dist,&az,&baz);
      fprintf(stderr,"EqDist %.2f %.2f %.2f %.2f %.2f %d %d\n", dist, lonEq1, latEq1, lonEq, latEq, ix1, iy1);
      exit(1); 	*/	


// loop over grid points and assign numbers
// get normalization term, first
      norm_term=0.0;
      kernel_sum=0.0;
      sigma=get_sigma_value(smp, catn, cnt);
      sig2=2*sigma*sigma;
      for(ix=0; ix<reg->nsx; ix++) {
        for(iy=0; iy<reg->nsy; iy++) {
          n=iy*reg->nsx+ix;
// shift cell origin to center cell
          if ( log_shift_pt==1 ) {
            lonPt=reg->minlon+(ix+0.5)*reg->dlon;
            latPt=reg->maxlat-(iy+0.5)*reg->dlat;
          }
// original location
          else {
            lonPt=reg->minlon+(ix)*reg->dlon;
            latPt=reg->maxlat-(iy)*reg->dlat;
          }
// distances from earthquakes to cells
          delaz_(&latEq,&lonEq,&latPt,&lonPt,&dist,&az,&baz);
          dist2=dist*dist;
          area_scaling=cos(latPt*DEG2RAD)/cos(latEq*DEG2RAD);
          if ( (smp->gauss_kern) == 1 ) {
            fac_exp=expf(-1*dist2/sig2);
          }
          else {
            fac_exp=powf((dist2+sigma*sigma),-1.5);
          }
          kernel_sum=kernel_sum+fac_exp*area_scaling;
//          if ( fac_exp > VTHR ) {
//            norm_term=norm_term+fac_exp;
//          }
//  if (n==29375) fprintf(stderr,"wt_norm: %.2f %.2f %.4e %d %d %.2f %.2f\n", dist, sigma, fac_exp, ix, iy, lonPt, latPt);
//          fprintf(stderr,"area-scaling/latPt/latEq: %.2f %.2f %.2f\n", area_scaling, latPt, latEq);
        }
      }
      norm_term=1/kernel_sum;
//fprintf(stderr,"wt_norm: %.4f %.2f %d\n", norm_term, sigma, cnt);
//      fprintf(stderr,"norm term: %.2f %.2f %d %.4f %.2f\n", catn->lon[cnt], catn->lat[cnt], cnt, norm_term, sigma);
/*
if (norm_term>1) {
  fprintf(stderr,"error norm term: %f\n", norm_term); exit(1);
}
else {
  fprintf(stderr,"norm term: %.2f %.2f %d %.2f %.2f\n", catn->lon[cnt], catn->lat[cnt], cnt, norm_term, sigma);
}
*/
// assign normalized weights 
      float eq_sum=0.0;
      for(ix=0; ix<reg->nsx; ix++) {
        for(iy=0; iy<reg->nsy; iy++) {
          n=iy*reg->nsx+ix;
// original location
          if ( log_shift_pt==0 ) {
            lonPt=reg->minlon+(ix)*reg->dlon;
            latPt=reg->maxlat-(iy)*reg->dlat;
          }
          else {
// shift cell origin to center cell
            lonPt=reg->minlon+(ix+0.5)*reg->dlon;
            latPt=reg->maxlat-(iy+0.5)*reg->dlat;
          }
// earthquake location - calculate distances
          delaz_(&latEq,&lonEq,&latPt,&lonPt,&dist,&az,&baz);
          dist2=dist*dist;
          area_scaling=cos(latPt*DEG2RAD)/cos(latEq*DEG2RAD);
          if ( (smp->gauss_kern) == 1 ) {
            fac_exp=n_eff*norm_term*expf(-1*dist2/sig2);
          }
          else {
            fac_exp=n_eff*norm_term*powf((dist2+sigma*sigma),-1.5);
          }
// scaling for variable-cell-area-with-latitude
          if ( cat_comp->correctAreaForLat ) {
//            fprintf(stderr,"correcting for grid cell area\n");
            eq_sum=eq_sum+fac_exp*area_scaling;
            seisr->asum[n]=seisr->asum[n]+fac_exp*area_scaling;
          }
          else {
            eq_sum=eq_sum+fac_exp;
            seisr->asum[n]=seisr->asum[n]+fac_exp;
          }
//          if ( fac_exp > norm_term*VTHR ) {
//fprintf(stderr,"sum_iter(sum/cnt/dist/sig/fac_exp): %.4f %d %.2f %.2f %.4e\n", eq_sum, cnt, dist, sigma, fac_exp);
          
//  if (n==29375) fprintf(stderr,"wt: %.2f %.2f %.4e %.4f %f %d %d n=%d\n", dist, sigma, fac_exp, norm_term, seisr->asum[n], ix, iy, cnt);
        }
      }				// end loops over gridpoints ix/iy
//fprintf(stderr,"sum eq: %.4f %d\n", eq_sum, cnt);
    }				// end loop earthquakes
// get maximum, smoothed rate
    maxv=0.0; imaxv=0;
    for(cnt=0; cnt<seisr->nv; cnt++) {
      if (seisr->asum[cnt]>maxv) {
        maxv=seisr->asum[cnt];
        imaxv=cnt;
      } 
    }
    fprintf(stdout,"Maximum, smoothed rate (eq nos/cell); grid-cell number: %.2f %d\n", maxv, imaxv);
// sum earthquake numbers to ensure that smoothing preserves numbers
    sum_eqs=0.0;
    for(cnt=0; cnt<seisr->nv; cnt++) {
      sum_eqs=sum_eqs+seisr->asum[cnt];
    }
    fprintf(stderr,"Over %d cells, %.2f earthquakes recovered, of %.2f effective events smoothed (%d actual).\n", seisr->nv, sum_eqs, tot_asum, catn->nv);
  } 				// end smoothing option


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r15
cmpl $0x0, 0x8(%rsi)
movl (%rdx), %edx
jne 0x445c
testl %edx, %edx
jle 0x43f4
movq %r9, 0x50(%rsp)
movq %r8, 0x30(%rsp)
xorl %ebx, %ebx
movss 0x18(%r12), %xmm0
subss 0x75304(%r13,%rbx,4), %xmm0
divss 0x20(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %r14d
movss 0x668a4(%r13,%rbx,4), %xmm0
subss 0xc(%r12), %xmm0
divss 0x1c(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %eax
imull (%r12), %r14d
addl %eax, %r14d
movl %r14d, 0x493e4(%r13,%rbx,4)
movq %rbp, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rcx
movl %ebx, %r8d
callq 0x41a8
movslq %r14d, %rax
incl (%r15,%rax,4)
movss 0xa6040(%r15,%rax,4), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0xa6040(%r15,%rax,4)
addss 0x14c080(%r15,%rax,4), %xmm0
movss %xmm0, 0x14c080(%r15,%rax,4)
incq %rbx
movslq (%r13), %rdx
cmpq %rdx, %rbx
jl 0x4346
movq 0x5bfd(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2e58(%rip), %rsi      # 0x725d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1100
movslq 0x298100(%r15), %rax
testq %rax, %rax
jle 0x4a8e
xorl %ecx, %ecx
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movaps %xmm1, %xmm2
movss 0x14c080(%r15,%rcx,4), %xmm1
addl (%r15,%rcx,4), %ebx
addss %xmm1, %xmm0
maxss %xmm2, %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x4428
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x20(%rsp)
jmp 0x4a97
testl %edx, %edx
movq %r9, 0x50(%rsp)
movq %r8, 0x30(%rsp)
jle 0x4506
xorl %ebx, %ebx
movss 0x18(%r12), %xmm0
subss 0x75304(%r13,%rbx,4), %xmm0
divss 0x20(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %r14d
movss 0x668a4(%r13,%rbx,4), %xmm0
subss 0xc(%r12), %xmm0
divss 0x1c(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %eax
imull (%r12), %r14d
addl %eax, %r14d
movl %r14d, 0x493e4(%r13,%rbx,4)
movq %rbp, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rcx
movl %ebx, %r8d
callq 0x41a8
movslq %r14d, %rax
incl (%r15,%rax,4)
addss 0xa6040(%r15,%rax,4), %xmm0
movss %xmm0, 0xa6040(%r15,%rax,4)
incq %rbx
movslq (%r13), %rax
cmpq %rax, %rbx
jl 0x4470
movslq 0x298100(%r15), %rax
xorps %xmm0, %xmm0
testq %rax, %rax
movq %r15, 0x78(%rsp)
jle 0x457f
xorl %ecx, %ecx
movss 0xa6040(%r15,%rcx,4), %xmm1
movss %xmm1, 0x1f20c0(%r15,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x451c
testl %eax, %eax
jle 0x457f
xorl %ecx, %ecx
xorps %xmm1, %xmm1
xorps %xmm0, %xmm0
xorl %ebx, %ebx
xorl %edx, %edx
movaps %xmm0, %xmm2
movss 0x1f20c0(%r15,%rcx,4), %xmm0
ucomiss %xmm2, %xmm0
cmoval %ecx, %edx
maxss %xmm2, %xmm0
addl (%r15,%rcx,4), %ebx
addss 0xa6040(%r15,%rcx,4), %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x4548
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
jmp 0x4586
xorl %edx, %edx
xorl %ebx, %ebx
xorps %xmm1, %xmm1
movsd %xmm1, 0x48(%rsp)
movq 0x5a45(%rip), %r14      # 0x9fd8
movq (%r14), %rdi
leaq 0x2d7c(%rip), %rsi      # 0x7319
movb $0x1, %al
callq 0x1100
movq (%r14), %rdi
leaq 0x2dad(%rip), %rsi      # 0x735b
movsd 0x48(%rsp), %xmm0
movl %ebx, %edx
movb $0x1, %al
callq 0x1100
movq 0x5a34(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x2dd2(%rip), %rdi      # 0x73a0
movl $0x13, %esi
movl $0x1, %edx
callq 0x11a0
cmpl $0x0, (%r13)
jle 0x4a62
xorl %ebx, %ebx
leaq 0xa4(%rsp), %r15
movq %r13, 0x58(%rsp)
movss 0x18(%r12), %xmm0
subss 0x75304(%r13,%rbx,4), %xmm0
divss 0x20(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %eax
movl %eax, 0x20(%rsp)
movss 0x668a4(%r13,%rbx,4), %xmm0
subss 0xc(%r12), %xmm0
divss 0x1c(%r12), %xmm0
callq 0x1070
cvttss2si %xmm0, %r14d
movq %rbp, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rcx
movl %ebx, %r8d
callq 0x41a8
movl %r14d, %edx
movss %xmm0, 0x14(%rsp)
movl (%r12), %r14d
testl %edx, %edx
js 0x4ad9
movl 0x4(%r12), %r13d
cmpl %edx, %r14d
jle 0x4ade
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
js 0x4aeb
cmpl %ecx, %r13d
jle 0x4aeb
xorps %xmm0, %xmm0
cvtss2sd 0xc(%r12), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x2b41(%rip), %xmm3     # 0x71e8
addsd %xmm3, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x1c(%r12), %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movss %xmm0, 0x44(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x18(%r12), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
addsd %xmm3, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x20(%r12), %xmm2
mulsd %xmm1, %xmm2
subsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
movq %rbp, %rdi
movq 0x58(%rsp), %rsi
movq %rbx, 0x98(%rsp)
movl %ebx, %edx
callq 0x3fd4
movaps %xmm0, %xmm1
addss %xmm0, %xmm1
movss %xmm0, 0x40(%rsp)
mulss %xmm0, %xmm1
movss %xmm1, 0x3c(%rsp)
xorl %ebx, %ebx
xorps %xmm1, %xmm1
testl %r13d, %r13d
jle 0x488b
xorps %xmm0, %xmm0
cvtsi2ss %ebx, %xmm0
movss %xmm0, 0x70(%rsp)
xorl %r14d, %r14d
movss %xmm1, 0x20(%rsp)
movss 0x1c(%r12), %xmm0
mulss 0x70(%rsp), %xmm0
addss 0xc(%r12), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x18(%r12), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r14d, %xmm1
mulss 0x20(%r12), %xmm1
subss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x74(%rsp), %rax
movq %rax, (%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x44(%rsp), %rsi
leaq 0xc(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %r15, %r9
callq 0x3574
movss 0x18(%rsp), %xmm0
mulss %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
movsd 0x2a1c(%rip), %xmm1     # 0x71f0
mulsd %xmm1, %xmm0
movsd 0x2a18(%rip), %xmm1     # 0x71f8
divsd %xmm1, %xmm0
callq 0x10c0
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
mulsd 0x29f0(%rip), %xmm0     # 0x71f0
divsd 0x29f0(%rip), %xmm0     # 0x71f8
callq 0x10c0
movsd %xmm0, 0x60(%rsp)
cmpl $0x1, 0x20(%rbp)
jne 0x4835
movaps 0x80(%rsp), %xmm0
xorps 0x28d8(%rip), %xmm0     # 0x7100
divss 0x3c(%rsp), %xmm0
callq 0x1060
jmp 0x4855
movss 0x40(%rsp), %xmm0
mulss %xmm0, %xmm0
addss 0x80(%rsp), %xmm0
movss 0x298c(%rip), %xmm1     # 0x71dc
callq 0x1150
movsd 0x68(%rsp), %xmm1
divsd 0x60(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm0, %xmm1
movss 0x20(%rsp), %xmm0
addss %xmm1, %xmm0
movaps %xmm0, %xmm1
incl %r14d
movl 0x4(%r12), %r13d
cmpl %r13d, %r14d
jl 0x4747
movl (%r12), %r14d
incl %ebx
cmpl %r14d, %ebx
jl 0x472e
testl %r14d, %r14d
jle 0x4a45
movss 0x2931(%rip), %xmm0     # 0x71d8
divss %xmm1, %xmm0
movss 0x14(%rsp), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x14(%rsp)
xorl %ebx, %ebx
testl %r13d, %r13d
jle 0x4a3a
xorps %xmm0, %xmm0
cvtsi2ss %ebx, %xmm0
movss %xmm0, 0x60(%rsp)
xorl %r14d, %r14d
movl (%r12), %r13d
imull %r14d, %r13d
movss 0x1c(%r12), %xmm0
mulss 0x60(%rsp), %xmm0
addss 0xc(%r12), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x18(%r12), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r14d, %xmm1
mulss 0x20(%r12), %xmm1
subss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x74(%rsp), %rax
movq %rax, (%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x44(%rsp), %rsi
leaq 0xc(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %r15, %r9
callq 0x3574
movss 0x18(%rsp), %xmm0
mulss %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
movsd 0x288e(%rip), %xmm1     # 0x71f0
mulsd %xmm1, %xmm0
movsd 0x288a(%rip), %xmm1     # 0x71f8
divsd %xmm1, %xmm0
callq 0x10c0
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
mulsd 0x2862(%rip), %xmm0     # 0x71f0
divsd 0x2862(%rip), %xmm0     # 0x71f8
callq 0x10c0
movsd %xmm0, 0x80(%rsp)
cmpl $0x1, 0x20(%rbp)
jne 0x49c3
movaps 0x20(%rsp), %xmm0
xorps 0x274a(%rip), %xmm0     # 0x7100
divss 0x3c(%rsp), %xmm0
callq 0x1060
jmp 0x49e0
movss 0x40(%rsp), %xmm0
mulss %xmm0, %xmm0
addss 0x20(%rsp), %xmm0
movss 0x2801(%rip), %xmm1     # 0x71dc
callq 0x1150
mulss 0x14(%rsp), %xmm0
movq 0x30(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0x4a08
movsd 0x68(%rsp), %xmm1
divsd 0x80(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm0
addl %ebx, %r13d
movslq %r13d, %rax
movq 0x78(%rsp), %rcx
addss 0x14c080(%rcx,%rax,4), %xmm0
movss %xmm0, 0x14c080(%rcx,%rax,4)
incl %r14d
movl 0x4(%r12), %r13d
cmpl %r13d, %r14d
jl 0x48d6
movl (%r12), %r14d
incl %ebx
cmpl %r14d, %ebx
jl 0x48bd
movq 0x98(%rsp), %rbx
incq %rbx
movq 0x58(%rsp), %r13
movslq (%r13), %rax
cmpq %rax, %rbx
jl 0x45f7
movq 0x78(%rsp), %rsi
leaq 0x298100(%rsi), %rdi
movq %r13, %rdx
movsd 0x48(%rsp), %xmm0
callq 0x19ef
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x553a(%rip), %r14      # 0x9fd8
movq (%r14), %rdi
leaq 0x27fa(%rip), %rsi      # 0x72a2
movl %ebx, %edx
movb $0x1, %al
callq 0x1100
movq (%r14), %rdi
leaq 0x2836(%rip), %rsi      # 0x72f1
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100
movl 0x4(%r12), %r13d
movq 0x5513(%rip), %rax      # 0x9ff8
movl 0x20(%rsp), %ecx
jmp 0x4af2
movq 0x5506(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq 0x58(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd 0x668a4(%rax,%rbx,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x75304(%rax,%rbx,4), %xmm1
leaq 0x289b(%rip), %rsi      # 0x73b4
movl %r14d, %r8d
movl %r13d, %r9d
movb $0x2, %al
callq 0x1100
movl $0x1, %edi
callq 0x1190