// File: /workspace/github_c_makefile_star2_O0/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/get_eq_neighbor_dists.c
// Function: get_eq_neighbor_dists
void get_eq_neighbor_dists(struct eqcat* catn)
/*--------------------------------------------------------------------------*/
{
//  int cnt, cnt1, cnt2, ncnt, narr;
  int cnt, cnt1, cnt2, ncnt;
//  int ord[NEQ];
  float lon1, lat1, lon2, lat2, dist, az, baz;
  float distarr[NEQ];

// sorting array has one less element than earthquake list array
//  narr=catn->nv-1;
  for(cnt=0; cnt<NEQ; cnt++) distarr[cnt]=0.0;

// loop over all pairs of stations, get distances and sort for the 10-nearest events
//  fprintf(stderr,"nv=%d\n", catn->nv);
  for(cnt1=0; cnt1<catn->nv; cnt1++) {
    lon1=catn->lon[cnt1];
    lat1=catn->lat[cnt1];
    ncnt=0;
    for(cnt2=0; cnt2<catn->nv; cnt2++) {
      lon2=catn->lon[cnt2];
      lat2=catn->lat[cnt2];
      if ( (cnt1>cnt2) || (cnt1<cnt2) ) {
        delaz_(&lat1,&lon1,&lat2,&lon2,&dist,&az,&baz);
        distarr[ncnt]=dist;
//        fprintf(stderr,"dist/coords: %f %.2f %.2f %.2f %.2f %d %d\n", dist, lon1, lat1, lon2, lat2, cnt1, cnt2);
        ncnt++;
      }
    }
//    for(cnt2=0; cnt2<ncnt; cnt2++) fprintf(stderr,"dist: %f\n", distarr[cnt2]);

// sort distances in distarr array
    qsort(distarr,ncnt,sizeof(float),compare_floats);
//    for(cnt2=0; cnt2<ncnt; cnt2++) fprintf(stderr,"dist_sort: %f\n", distarr[cnt2]);

    for(cnt=0;cnt<(int)NNUM; cnt++) {
      catn->dist_nbr[cnt1][cnt]=distarr[cnt];
//      fprintf(stderr,"dist_nbr: %f %f\n", distarr[cnt], catn->dist_nbr[cnt1][cnt]);
    }
//    fprintf(stderr,"REMOVE LATER\n"); exit(1);
    for(cnt=0; cnt<NEQ; cnt++) distarr[cnt]=0.0;
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xeab0, %rsp           # imm = 0xEAB0
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3a98, -0xc(%rbp)     # imm = 0x3A98
jge 0x359a
movslq -0xc(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, -0xeaa0(%rbp,%rax,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3576
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x371f
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movss 0x668a4(%rax,%rcx,4), %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movss 0x75304(%rax,%rcx,4), %xmm0
movss %xmm0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x3685
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x668a4(%rax,%rcx,4), %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x75304(%rax,%rcx,4), %xmm0
movss %xmm0, -0x28(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x3635
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3675
leaq -0x20(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x24(%rbp), %rcx
leaq -0x2c(%rbp), %r8
leaq -0x30(%rbp), %r9
leaq -0x34(%rbp), %rax
movq %rax, (%rsp)
callq 0x3728
movss -0x2c(%rbp), %xmm0
movslq -0x18(%rbp), %rax
movss %xmm0, -0xeaa0(%rbp,%rax,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3677
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x35ea
leaq -0xeaa0(%rbp), %rdi
movslq -0x18(%rbp), %rsi
movl $0x4, %edx
leaq -0x16c(%rip), %rcx      # 0x3530
callq 0x1050
movl $0x0, -0xc(%rbp)
cmpl $0xa, -0xc(%rbp)
jge 0x36e4
movslq -0xc(%rbp), %rax
movss -0xeaa0(%rbp,%rax,4), %xmm0
movq -0x8(%rbp), %rax
addq $0xbe6e4, %rax          # imm = 0xBE6E4
movslq -0x10(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36a8
movl $0x0, -0xc(%rbp)
cmpl $0x3a98, -0xc(%rbp)     # imm = 0x3A98
jge 0x370f
movslq -0xc(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, -0xeaa0(%rbp,%rax,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36eb
jmp 0x3711
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x35a1
addq $0xeab0, %rsp           # imm = 0xEAB0
popq %rbp
retq