// File: /workspace/github_cpp_makefile_star2_O3/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 0xea2af
jp 0xea2af
callq 0xe9fe2
xorpd %xmm4, %xmm4
movapd %xmm0, %xmm5
cmpeqsd %xmm5, %xmm4
movsd 0x21744(%rip), %xmm0    # 0x10ba00
andpd %xmm4, %xmm0
andnpd %xmm5, %xmm4
orpd %xmm0, %xmm4
leaq 0x1540c1(%rip), %r12    # 0x23e390
movq (%r12), %rdi
testq %rdi, %rdi
movapd %xmm4, -0x40(%rbp)
je 0xea309
movapd %xmm4, %xmm1
divsd 0x41e1f(%rip), %xmm1    # 0x12c108
leaq 0x4a996(%rip), %rsi     # 0x134c86
movapd %xmm4, %xmm0
movb $0x2, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movapd -0x40(%rbp), %xmm4
movl $0x1, %r14d
movsd -0x48(%rbp), %xmm1
movapd %xmm4, %xmm0
movl %r14d, %edi
callq 0xea1cc
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0xea348
incl %r14d
cmpl $0x3e9, %r14d           # imm = 0x3E9
movsd -0x48(%rbp), %xmm1
movapd -0x40(%rbp), %xmm4
jne 0xea314
movl $0x3e9, %r14d           # imm = 0x3E9
jmp 0xea34c
movaps -0x40(%rbp), %xmm4
movq (%r12), %rdi
testq %rdi, %rdi
je 0xea392
cmpl $0x2, %r14d
leaq 0x2d23b(%rip), %rax     # 0x11759b
leaq 0x4772f(%rip), %rcx     # 0x131a96
cmovaeq %rax, %rcx
divsd 0x2159d(%rip), %xmm0    # 0x10b910
leaq 0x4a936(%rip), %rsi     # 0x134cb0
movl %r14d, %edx
movb $0x1, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movapd -0x40(%rbp), %xmm4
movsd %xmm4, (%r15)
leaq 0x222c32(%rip), %r15    # 0x30cfd0
movsd (%r15), %xmm0
leaq 0x222c36(%rip), %r13    # 0x30cfe0
movsd (%r13), %xmm1
callq 0xe80f9
leal (%r14,%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
movapd -0x40(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd (%r15), %xmm0
movsd (%r13), %xmm1
callq 0xe80f9
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 0x1ec57(%rip), %xmm0    # 0x109068
callq 0x91b0
addsd -0x50(%rbp), %xmm0
callq 0x92d0
movsd 0x41c38(%rip), %xmm1    # 0x12c060
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x9080
movapd -0x40(%rbp), %xmm1
mulsd 0x33df6(%rip), %xmm0    # 0x11e238
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movq (%r12), %rdi
testq %rdi, %rdi
je 0xea485
leaq 0x4bed9(%rip), %rsi     # 0x136333
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