// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movsd %xmm4, -0x48(%rbp)
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm5
jne 0xd5cb9
jp 0xd5cb9
callq 0xd59ef
xorpd %xmm4, %xmm4
movapd %xmm0, %xmm5
cmpeqsd %xmm5, %xmm4
movsd 0x1fdb2(%rip), %xmm0    # 0xf5a78
andpd %xmm4, %xmm0
andnpd %xmm5, %xmm4
orpd %xmm0, %xmm4
leaq 0x1526b7(%rip), %r12    # 0x228390
movq (%r12), %rdi
testq %rdi, %rdi
movapd %xmm4, -0x40(%rbp)
je 0xd5d13
movapd %xmm4, %xmm1
divsd 0x40345(%rip), %xmm1    # 0x116038
leaq 0x48eac(%rip), %rsi     # 0x11eba6
movapd %xmm4, %xmm0
movb $0x2, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movapd -0x40(%rbp), %xmm4
pushq $0x1
popq %r14
movsd -0x48(%rbp), %xmm1
movapd %xmm4, %xmm0
movl %r14d, %edi
callq 0xd5bd9
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0xd5d50
incl %r14d
cmpl $0x3e9, %r14d           # imm = 0x3E9
movsd -0x48(%rbp), %xmm1
movapd -0x40(%rbp), %xmm4
jne 0xd5d1c
movl $0x3e9, %r14d           # imm = 0x3E9
jmp 0xd5d54
movaps -0x40(%rbp), %xmm4
movq (%r12), %rdi
testq %rdi, %rdi
je 0xd5d9a
cmpl $0x2, %r14d
leaq 0x2b8b3(%rip), %rax     # 0x10161b
leaq 0x45c47(%rip), %rcx     # 0x11b9b6
cmovaeq %rax, %rcx
divsd 0x1fc0d(%rip), %xmm0    # 0xf5988
leaq 0x48e4e(%rip), %rsi     # 0x11ebd0
movl %r14d, %edx
movb $0x1, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movapd -0x40(%rbp), %xmm4
movsd %xmm4, (%r15)
leaq 0x22122a(%rip), %r15    # 0x2f6fd0
movsd (%r15), %xmm0
leaq 0x22122e(%rip), %r13    # 0x2f6fe0
movsd (%r13), %xmm1
callq 0xd3c65
leal (%r14,%r14), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
movapd -0x40(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd (%r15), %xmm0
movsd (%r13), %xmm1
callq 0xd3c65
movsd %xmm0, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
callq 0x9080
mulsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
mulsd 0x1d252(%rip), %xmm0    # 0xf3068
callq 0x91a0
addsd -0x50(%rbp), %xmm0
callq 0x92c0
movsd 0x40163(%rip), %xmm1    # 0x115f90
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x9080
movapd -0x40(%rbp), %xmm1
mulsd 0x32469(%rip), %xmm0    # 0x1082b0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movq (%r12), %rdi
testq %rdi, %rdi
je 0xd5e8a
leaq 0x4a3e0(%rip), %rsi     # 0x12023f
movapd %xmm1, %xmm0
movsd -0x48(%rbp), %xmm1
movl %r14d, %edx
movsd %xmm2, -0x40(%rbp)
movsd -0x40(%rbp), %xmm2
movb $0x3, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movsd -0x40(%rbp), %xmm2
movsd %xmm2, (%rbx)
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq