// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x4165
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x4256
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x20(%rbp), %rax
mulss 0x8(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x4f65(%rip), %xmm1     # 0x90e8
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x4c(%rbp), %xmm1
movss 0x4f3b(%rip), %xmm0     # 0x90d8
callq 0x1120
movss %xmm0, -0x74(%rbp)
movss -0x4c(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
movss 0x4f17(%rip), %xmm0     # 0x90d8
callq 0x1120
movaps %xmm0, %xmm1
movss -0x74(%rbp), %xmm0
subss %xmm1, %xmm0
callq 0x10f0
movss %xmm0, -0x34(%rbp)
movq 0x7df5(%rip), %rax      # 0xbfd8
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x20(%rbp), %rax
movss 0x8(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movss -0x4c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movss -0x4c(%rbp), %xmm1
movss 0x4eaf(%rip), %xmm0     # 0x90d8
callq 0x1120
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x58(%rbp), %xmm0
cvtss2sd %xmm3, %xmm3
leaq 0x4ea1(%rip), %rsi      # 0x90f0
movb $0x4, %al
callq 0x10e0
movq 0x7d7b(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x4ea6(%rip), %rsi      # 0x9116
movb $0x1, %al
callq 0x10e0
movq 0x7d5a(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x298100(%rax), %edx
leaq 0x4ed9(%rip), %rsi      # 0x916b
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x298100(%rcx), %eax
jge 0x45b2
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x45a2
movss -0x30(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addss 0x14c080(%rax,%rcx,4), %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
callq 0x10f0
movaps %xmm0, %xmm1
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x14c080(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x1f20c0(%rax,%rcx,4), %xmm0
callq 0x10f0
movaps %xmm0, %xmm1
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x1f20c0(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
addss -0x34(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x14c080(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x1f20c0(%rax,%rcx,4), %xmm0
addss -0x34(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x1f20c0(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm1
movss 0x4cfe(%rip), %xmm0     # 0x90d8
callq 0x1120
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x14c080(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x1f20c0(%rax,%rcx,4), %xmm1
movss 0x4ccf(%rip), %xmm0     # 0x90d8
callq 0x1120
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, 0x1f20c0(%rax,%rcx,4)
movss -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addss 0x14c080(%rax,%rcx,4), %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x3c(%rbp), %xmm0
movss %xmm0, -0x8c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
movss %xmm0, -0x88(%rbp)
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
movss 0x4c66(%rip), %xmm0     # 0x90e4
mulss %xmm0, %xmm1
movss 0x4c4e(%rip), %xmm0     # 0x90d8
callq 0x1120
movss -0x8c(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0x88(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x40(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
movss %xmm0, -0x80(%rbp)
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
movss 0x4bf0(%rip), %xmm0     # 0x90e0
mulss %xmm0, %xmm1
movss 0x4bdc(%rip), %xmm0     # 0x90d8
callq 0x1120
movss -0x84(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0x80(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x44(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x14c080(%rax,%rcx,4), %xmm0
movss %xmm0, -0x78(%rbp)
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
movss 0x4b80(%rip), %xmm0     # 0x90dc
mulss %xmm0, %xmm1
movss 0x4b70(%rip), %xmm0     # 0x90d8
callq 0x1120
movss -0x7c(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0x78(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x48(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addss 0x1f20c0(%rax,%rcx,4), %xmm0
movss %xmm0, -0x48(%rbp)
jmp 0x45a4
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x42a0
movq 0x7a1f(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x38(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x3c(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x40(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movss -0x44(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
leaq 0x4b89(%rip), %rsi      # 0x9179
movb $0x5, %al
callq 0x10e0
addq $0x90, %rsp
popq %rbp
retq