// File: /workspace/github_c_makefile_star2_O0/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/get_eqs_fm_catalog.c
// Function: assign_variable_completeness_eqs
void assign_variable_completeness_eqs(struct eqcat* cat, struct compl_levels* compl_vals)
/*--------------------------------------------------------------------------*/
{
  int cnt, cnt1;
  int year_mindist;
  float loneq, lateq, lonpt, latpt;
  float dist, az, baz, mindist;
 
// loop over all earthquakes and assign the completeness year from closest grid point  
// default to 
  for(cnt=0; cnt<cat->nv; cnt++) {
    cat->year_compl[cnt]=compl_vals->yr_comp[0];
    loneq=cat->lon[cnt];
    lateq=cat->lat[cnt];
    mindist=9999.0;
    for(cnt1=0; cnt1<compl_vals->nVarComp; cnt1++) {
      lonpt=compl_vals->lon_arr[cnt1];
      latpt=compl_vals->lat_arr[cnt1];
      delaz_(&lateq,&loneq,&latpt,&lonpt,&dist,&az,&baz);
      if ( dist<mindist ) {
        mindist=dist;
        year_mindist=compl_vals->yrCompl_arr[cnt1];
      }
    }
    if (mindist<200) cat->year_compl[cnt]=year_mindist;
//    fprintf(stdout,"compl-yr %.2f %.2f %d\n", loneq, lateq, cat->year_compl[cnt]);
  }
  fprintf(stdout,"Assigned variable completeness to earthquakes in catalog.\n");

// remove events that occur before variable completeness year
  cnt1=0;
  for(cnt=0; cnt<cat->nv; cnt++) {
    if ( (cat->year[cnt]) >= (cat->year_compl[cnt]) ) {
      cat->year[cnt1]=cat->year[cnt];
      cat->month[cnt1]=cat->month[cnt];
      cat->day[cnt1]=cat->day[cnt];
      cat->lineno[cnt1]=cat->lineno[cnt];
      cat->mag[cnt1]=cat->mag[cnt];
      cat->lon[cnt1]=cat->lon[cnt];
      cat->lat[cnt1]=cat->lat[cnt];
      cat->depth[cnt1]=cat->depth[cnt];
      cat->neff[cnt1]=cat->neff[cnt];
      cat->mag_sigma[cnt1]=cat->mag_sigma[cnt];
      cat->year_compl[cnt1]=cat->year_compl[cnt];
      fprintf(stderr,"%4d %4d %4d %8.4f\n", cat->year[cnt1], cat->month[cnt1], cat->day[cnt1], cat->mag[cnt1]);
      cnt1++;
    }
/*    else {
     fprintf(stderr,"Year discrepancy: %d %d, complete\n",cat->year[cnt], cat->year_compl[cnt]);
    } */
  }
  fprintf(stderr,"Reduced catalog by %d events (%d orig; %d variable-completeness).\n", cat->nv-cnt1, cat->nv, cnt1);
  cat->nv=cnt1;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2e6b
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, 0x2bf24(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x668a4(%rax,%rcx,4), %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x75304(%rax,%rcx,4), %xmm0
movss %xmm0, -0x24(%rbp)
movss 0x5f78(%rip), %xmm0     # 0x8d08
movss %xmm0, -0x3c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x2c0(%rcx), %eax
jge 0x2e3b
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss 0x14c344(%rax,%rcx,4), %xmm0
movss %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss 0x1f2384(%rax,%rcx,4), %xmm0
movss %xmm0, -0x2c(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0x30(%rbp), %r8
leaq -0x34(%rbp), %r9
leaq -0x38(%rbp), %rax
movq %rax, (%rsp)
callq 0x3728
movss -0x30(%rbp), %xmm1
movss -0x3c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2e2b
movss -0x30(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0x2c4(%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
jmp 0x2e2d
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2d9c
movss 0x5ec9(%rip), %xmm0     # 0x8d0c
ucomiss -0x3c(%rbp), %xmm0
jbe 0x2e5b
movl -0x1c(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, 0x2bf24(%rax,%rcx,4)
jmp 0x2e5d
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2d37
movq 0x9166(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
leaq 0x5e98(%rip), %rsi      # 0x8d14
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x308e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
cmpl 0x2bf24(%rcx,%rdx,4), %eax
jl 0x307e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0xea64(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0xea64(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x1d4c4(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0x1d4c4(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x3a984(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0x3a984(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x57e44(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0x57e44(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x668a4(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0x668a4(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x75304(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0x75304(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x83d64(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0x83d64(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x927c4(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0x927c4(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0xa1224(%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, 0xa1224(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x2bf24(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0x2bf24(%rax,%rcx,4)
movq 0x8fd4(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0xea64(%rax,%rcx,4), %ecx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rsi
movl 0x1d4c4(%rax,%rsi,4), %r8d
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rsi
movss 0x57e44(%rax,%rsi,4), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x5ce1(%rip), %rsi      # 0x8d4f
movb $0x1, %al
callq 0x10e0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3080
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2e91
movq 0x8f63(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %edx
subl -0x18(%rbp), %edx
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movl -0x18(%rbp), %r8d
leaq 0x5cb0(%rip), %rsi      # 0x8d62
movb $0x0, %al
callq 0x10e0
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)