// File: /workspace/github_c_makefile_star2_O1/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/convert_eq_nos_rates.c
// Function: convert_eq_nos_rates
void convert_eq_nos_rates(struct rates* seisr, struct compl_levels* compl, struct smoothp* smp, struct catalog* cat, struct boundaries* reg)
/*--------------------------------------------------------------------------*/
{
  int cnt;
  float isum=0.0;
  float fac, sum0=0.0, sum3=0.0, sum4=0.0, sum5=0.0, sum_noSm=0.0;
  float arg_pow;

// get factors for converting cumulative to incremental rates 
// Herrmann's formula for converting cumulative to incremental
// set factor to zero to retain cumulative rates
  if ( smp->cumul_rates == 1 ) {
    fac=0.0;
  }
  else {
// 0.5-factor gives dMag about a magnitude value
    arg_pow=(cat->bval*cat->dMag*0.5);
    fac=log10f( powf(10,arg_pow) - powf(10,-arg_pow) );
    fprintf(stdout,"bval/dMag/arg_pow/powf: %f %f %f %f \n", cat->bval, cat->dMag, arg_pow, powf(10,arg_pow));
  }
  fprintf(stdout,"Additive factor (log) converting cumulative to incremental (cumulative fac=0): %.4f\n", fac);

// loop through rates at all points to modify rates
// apply to smoothed and earthquake count results
  fprintf(stdout,"nsrc pts: %d\n", seisr->nv);
  for (cnt=0; cnt<seisr->nv; cnt++) {
    if ( seisr->asum[cnt] > 0 ) {
//if (cnt==29375) fprintf(stderr,"asum smoothed (M4+), %f \n", seisr->asum[cnt]);
// convert from (cumulative) counts per cell to rates
      isum=isum+seisr->asum[cnt];
// convert to log(rate)(M=0), cumulative
      seisr->asum[cnt]=log10f(seisr->asum[cnt]) + cat->bval*cat->minMag;
      seisr->asum_noSm[cnt]=log10f(seisr->asum_noSm[cnt]) + cat->bval*cat->minMag;
// convert cumulative to incremental rates, if specified
      seisr->asum[cnt]=seisr->asum[cnt]+fac;
      seisr->asum_noSm[cnt]=seisr->asum_noSm[cnt]+fac;
// convert back to rates, 10^a
      seisr->asum[cnt]=powf(10,seisr->asum[cnt]);
      seisr->asum_noSm[cnt]=powf(10,seisr->asum_noSm[cnt]);
      sum0=sum0+seisr->asum[cnt];
      sum3=sum3+seisr->asum[cnt]*powf(10,-(cat->bval)*3);
      sum4=sum4+seisr->asum[cnt]*powf(10,-(cat->bval)*4);
      sum5=sum5+seisr->asum[cnt]*powf(10,-(cat->bval)*5);
      sum_noSm=sum_noSm+seisr->asum_noSm[cnt];
    }
//if (cnt==29375) fprintf(stderr,"(rates, M0), final %f \n", seisr->asum[cnt]);
  }
/*  float maxr=0; int imaxr=0;
  for (cnt=0; cnt<seisr->nv; cnt++) {
    if (seisr->asum[cnt]>maxr) {
      maxr=seisr->asum[cnt];
      imaxr=cnt;
    }
  } 
 fprintf(stderr,"maxrate: %f %d\n", maxr, imaxr); */
  
// print summary rate info
//  fprintf(stdout,"%d eqs -> rates M0/3/4/5: %.4e %.4e %.4e %.4e\n", isum, sum0, sum3, sum4, sum5);
  fprintf(stdout,"%.3f eqs -> sum rates (no./yr), M0/3/4/5: %.1f %.1f %.1f %.1f\n", isum, sum0, sum3, sum4, sum5);

}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
cmpl $0x1, (%rdx)
je 0x3d76
movss 0xc(%rbx), %xmm1
mulss 0x8(%rbx), %xmm1
mulss 0x341d(%rip), %xmm1     # 0x70d8
movaps %xmm1, 0x30(%rsp)
movss 0x3414(%rip), %xmm0     # 0x70dc
callq 0x1150
movss %xmm0, 0x8(%rsp)
movaps 0x3416(%rip), %xmm1     # 0x70f0
xorps 0x30(%rsp), %xmm1
movss 0x33f5(%rip), %xmm0     # 0x70dc
callq 0x1150
movss 0x8(%rsp), %xmm1
subss %xmm0, %xmm1
movaps %xmm1, %xmm0
callq 0x1110
movss %xmm0, 0x14(%rsp)
movq 0x62cd(%rip), %rax      # 0x9fd8
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%rax), %r15
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rbx), %xmm0
movsd %xmm0, 0x18(%rsp)
movaps 0x30(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movss 0x3398(%rip), %xmm0     # 0x70dc
callq 0x1150
cvtss2sd %xmm0, %xmm3
leaq 0x33ac(%rip), %rsi      # 0x7100
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movb $0x4, %al
callq 0x1100
movss 0x14(%rsp), %xmm0
movq 0x625b(%rip), %r15      # 0x9fd8
movq (%r15), %rdi
movss %xmm0, 0x14(%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x3395(%rip), %rsi      # 0x7126
movb $0x1, %al
callq 0x1100
movq (%r15), %rdi
movl 0x298100(%r14), %edx
leaq 0x33d2(%rip), %rsi      # 0x717b
xorl %eax, %eax
callq 0x1100
cmpl $0x0, 0x298100(%r14)
jle 0x3fae
xorps %xmm1, %xmm1
xorl %r12d, %r12d
xorps %xmm4, %xmm4
xorps %xmm0, %xmm0
movss %xmm0, 0x30(%rsp)
movss %xmm0, 0x8(%rsp)
movss %xmm0, 0x18(%rsp)
xorps %xmm2, %xmm2
movss 0x14c080(%r14,%r12,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3f73
addss %xmm0, %xmm2
movss %xmm2, 0x2c(%rsp)
movss %xmm4, 0x20(%rsp)
callq 0x1110
movss 0xc(%rbx), %xmm1
mulss 0x4(%rbx), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x14c080(%r14,%r12,4)
movss 0x1f20c0(%r14,%r12,4), %xmm0
callq 0x1110
movss 0xc(%rbx), %xmm2
mulss 0x4(%rbx), %xmm2
addss %xmm0, %xmm2
movss 0x14c080(%r14,%r12,4), %xmm1
movss 0x14(%rsp), %xmm0
addss %xmm0, %xmm1
movss %xmm1, 0x14c080(%r14,%r12,4)
addss %xmm0, %xmm2
movss %xmm2, 0x1f20c0(%r14,%r12,4)
movss 0x326c(%rip), %xmm0     # 0x70dc
callq 0x1150
movss %xmm0, 0x14c080(%r14,%r12,4)
movss 0x1f20c0(%r14,%r12,4), %xmm1
movss 0x324b(%rip), %xmm0     # 0x70dc
callq 0x1150
movss %xmm0, 0x1f20c0(%r14,%r12,4)
movss 0x14c080(%r14,%r12,4), %xmm1
movss %xmm1, 0x4(%rsp)
movss 0x18(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x18(%rsp)
movss 0xc(%rbx), %xmm1
mulss 0x3213(%rip), %xmm1     # 0x70e0
movss 0x3207(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x4(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movss 0x14c080(%r14,%r12,4), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0xc(%rbx), %xmm1
mulss 0x31d7(%rip), %xmm1     # 0x70e4
movss 0x31c7(%rip), %xmm0     # 0x70dc
callq 0x1150
mulss 0x4(%rsp), %xmm0
movss 0x30(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x30(%rsp)
movss 0x14c080(%r14,%r12,4), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0xc(%rbx), %xmm1
mulss 0x319b(%rip), %xmm1     # 0x70e8
movss 0x3187(%rip), %xmm0     # 0x70dc
callq 0x1150
movss 0x2c(%rsp), %xmm2
movss 0x20(%rsp), %xmm4
xorps %xmm1, %xmm1
mulss 0x4(%rsp), %xmm0
addss %xmm0, %xmm4
incq %r12
movslq 0x298100(%r14), %rax
cmpq %rax, %r12
jl 0x3ddf
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x18(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rsp), %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0x30(%rsp), %xmm3
cvtss2sd %xmm4, %xmm4
jmp 0x3fbd
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
movq (%r15), %rdi
leaq 0x31c2(%rip), %rsi      # 0x7189
movb $0x5, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x1100
nopl (%rax)