// File: /workspace/github_c_makefile_star2_O0/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/smooth_seis_rates.c
// Function: calc_seis_rate
float calc_seis_rate(struct smoothp* smpp, struct eqcat* eqcatp, struct compl_levels* cat_compp, 
	struct catalog* cat_parp, int eqno)
/*--------------------------------------------------------------------------*/
{
  int cnt;
  float num_fac, denom_fac, rate_fac, ratev, fac_exp;
//  float bvalue, beta, n_eff, mag_eq, denom_mod;
  float bvalue, beta, n_eff, denom_mod;
//  float bvalue, beta, n_eff, denom_mod;

// 
  bvalue=cat_parp->bval;
  beta=2.303*bvalue;
//  mag_eq=eqcatp->mag[eqno];

// check if earthquake occurred in a region with catalog gaps
// this feature allows for removing potentially induced earthquakes from catalog but 
// correctly calculating the rates with reduced time windows
  if ( (cat_compp->catalogGaps) == 1 ) {
    denom_mod=check_earthquake_catalog_gaps(eqcatp,cat_compp,eqno);
  }
  else {
    denom_mod=0;
  }

// convert from numbers to rates here
  if ( smpp->adj_compl == 1 ) {
    num_fac=0.0;
    denom_fac=0.0;
    for(cnt=0; cnt<cat_compp->nlevels; cnt++) {
      fac_exp=exp(-beta*(cat_compp->mag_comp[cnt]));
      num_fac=num_fac+fac_exp;
      denom_fac=denom_fac+fac_exp*(cat_parp->end_yr-cat_compp->yr_comp[cnt]+1);
    }
  }
  else {
    num_fac=1.0;
    if ( cat_compp->variableCompleteness == 1 ) {
      denom_fac=(cat_parp->end_yr-eqcatp->year_compl[eqno]+1);
    }
    else {
      denom_fac=(cat_parp->end_yr-cat_compp->yr_comp[0]+1);
    }
    denom_fac=denom_fac-denom_mod;
  }
  if (denom_fac<0) { 
    fprintf(stderr,"Problem with rate calculation.\n");
    exit(1);
  }
  rate_fac=num_fac/denom_fac;

// apply effective-number-count here, if appropriate 
  if ( (smpp->use_neff) == 1 ) {
    n_eff=eqcatp->neff[eqno];
  }
  else {
    n_eff=1.00;
  }
// ratev corresponds to the annual rate of earthquake (array element, eqno) in the catalog 
  ratev=rate_fac*n_eff;
    
  return ratev;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x20(%rbp), %rax
movss 0xc(%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x40(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x4865(%rip), %xmm0     # 0x91c0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x4989
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x4700
movss %xmm0, -0x4c(%rbp)
jmp 0x4991
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x4a43
xorps %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x4a41
movss -0x44(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
mulss 0x3c(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1180
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x2c(%rbp), %xmm0
addss -0x3c(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x30(%rbp), %xmm1
movss -0x3c(%rbp), %xmm0
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
subl 0x14(%rcx,%rdx,4), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x30(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x49b6
jmp 0x4aa4
movss 0x38cd(%rip), %xmm0     # 0x8318
movss %xmm0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x4a7c
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
subl 0x2bf24(%rcx,%rdx,4), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
jmp 0x4a95
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x14(%rcx), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
subss -0x4c(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x30(%rbp), %xmm0
jbe 0x4acf
movq 0x7544(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x4757(%rip), %rsi      # 0x9215
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1160
movss -0x2c(%rbp), %xmm0
divss -0x30(%rbp), %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jne 0x4b00
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movss 0x927c4(%rax,%rcx,4), %xmm0
movss %xmm0, -0x48(%rbp)
jmp 0x4b0d
movss 0x3810(%rip), %xmm0     # 0x8318
movss %xmm0, -0x48(%rbp)
movss -0x34(%rbp), %xmm0
mulss -0x48(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x38(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)