// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: find_delay(double, double, double, double, double, double, double*, double*)
int find_delay(double lat1,double long1,double lat2,double long2,double h,  double u_dist, double *dist,double *delay)
{
double dg;      /* great circle distance */
double delta;   /* wave angle */
int n;          /* number of hops */

   if(u_dist) dg = u_dist;
   else       dg = greatcircle(lat1, long1, lat2, long2);
   if(dg == 0.0) dg = 0.000001;
   if(debug_file) {
       fprintf(debug_file, "great circle distance %.9f km %.9f miles\n", dg, dg/KM_PER_MILE);
       fflush(debug_file);
   }
   
   n = 1;
   while((delta = waveangle(dg, h, n)) < 0.0) {
      if(0 && debug_file) {
          fprintf(debug_file, "tried %d hop%s, no good\n", n, n>1?"s":"");
          fflush(debug_file);
      }

      n++;
      if(n > 1000) break;  // should never happen
   }
   if(debug_file) {
       fprintf(debug_file, "%d hop%s okay, wave angle is %g\n", n, n>1?"s":"",
              delta / RADPERDEG);
       fflush(debug_file);
   }

   *dist = dg;
   *delay = propdelay(dg, h, n);
   return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movsd %xmm2, -0x18(%rbp)
movsd %xmm3, -0x20(%rbp)
movsd %xmm4, -0x28(%rbp)
movsd %xmm5, -0x30(%rbp)
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13fbf0
jp 0x13fbf0
jmp 0x13fbfc
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x13fc1a
movsd -0x8(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movsd -0x18(%rbp), %xmm2
movsd -0x20(%rbp), %xmm3
callq 0x13f830
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13fc37
jp 0x13fc37
movsd 0x31b06(%rip), %xmm0    # 0x171738
movsd %xmm0, -0x48(%rbp)
leaq 0x15d932(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13fc81
leaq 0x15d925(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movsd -0x48(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd 0x4ef38(%rip), %xmm2    # 0x18eb98
divsd %xmm2, %xmm1
leaq 0x57bad(%rip), %rsi     # 0x197818
movb $0x2, %al
callq 0x9550
leaq 0x15d8f7(%rip), %rax    # 0x29d570
movq (%rax), %rdi
callq 0x9430
movl $0x1, -0x54(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl -0x54(%rbp), %edi
callq 0x13fac0
movaps %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13fcc1
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x3e8, -0x54(%rbp)     # imm = 0x3E8
jle 0x13fcbf
jmp 0x13fcc1
jmp 0x13fc88
leaq 0x15d8a8(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13fd21
leaq 0x15d89b(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0x54(%rbp), %edx
movl -0x54(%rbp), %esi
leaq 0x548ad(%rip), %rcx     # 0x194592
leaq 0x3c2ad(%rip), %rax     # 0x17bf99
cmpl $0x1, %esi
cmovgq %rax, %rcx
movsd -0x50(%rbp), %xmm0
movsd 0x31990(%rip), %xmm1    # 0x171690
divsd %xmm1, %xmm0
leaq 0x57b37(%rip), %rsi     # 0x197842
movb $0x1, %al
callq 0x9550
leaq 0x15d857(%rip), %rax    # 0x29d570
movq (%rax), %rdi
callq 0x9430
movsd -0x48(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x48(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl -0x54(%rbp), %edi
callq 0x13fd60
movq -0x40(%rbp), %rax
movsd %xmm0, (%rax)
movl -0x54(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)