// File: /workspace/github_cpp_makefile_star2_O1/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 0xe983c
jp 0xe983c
callq 0xe956f
xorpd %xmm4, %xmm4
movapd %xmm0, %xmm5
cmpeqsd %xmm5, %xmm4
movsd 0x221b7(%rip), %xmm0    # 0x10ba00
andpd %xmm4, %xmm0
andnpd %xmm5, %xmm4
orpd %xmm0, %xmm4
leaq 0x154b34(%rip), %r12    # 0x23e390
movq (%r12), %rdi
testq %rdi, %rdi
movapd %xmm4, -0x40(%rbp)
je 0xe9896
movapd %xmm4, %xmm1
divsd 0x427b2(%rip), %xmm1    # 0x12c028
leaq 0x4b319(%rip), %rsi     # 0x134b96
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 0xe9759
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0xe98d5
incl %r14d
cmpl $0x3e9, %r14d           # imm = 0x3E9
movsd -0x48(%rbp), %xmm1
movapd -0x40(%rbp), %xmm4
jne 0xe98a1
movl $0x3e9, %r14d           # imm = 0x3E9
jmp 0xe98d9
movaps -0x40(%rbp), %xmm4
movq (%r12), %rdi
testq %rdi, %rdi
je 0xe991f
cmpl $0x2, %r14d
leaq 0x2dc1a(%rip), %rax     # 0x117507
leaq 0x480b2(%rip), %rcx     # 0x1319a6
cmovaeq %rax, %rcx
divsd 0x22008(%rip), %xmm0    # 0x10b908
leaq 0x4b2b9(%rip), %rsi     # 0x134bc0
movl %r14d, %edx
movb $0x1, %al
callq 0x9560
movq (%r12), %rdi
callq 0x9420
movapd -0x40(%rbp), %xmm4
movsd %xmm4, (%r15)
leaq 0x2236a5(%rip), %r15    # 0x30cfd0
movsd (%r15), %xmm0
leaq 0x2236a9(%rip), %r13    # 0x30cfe0
movsd (%r13), %xmm1
callq 0xe765f
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 0xe765f
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 0x1f6ca(%rip), %xmm0    # 0x109068
callq 0x91b0
addsd -0x50(%rbp), %xmm0
callq 0x92d0
movsd 0x425cb(%rip), %xmm1    # 0x12bf80
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x9080
movapd -0x40(%rbp), %xmm1
mulsd 0x347c1(%rip), %xmm0    # 0x11e190
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movq (%r12), %rdi
testq %rdi, %rdi
je 0xe9a12
leaq 0x4c853(%rip), %rsi     # 0x13623a
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