// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]Dsuite/KolmogorovSmirnovDist.cpp
// Function: KSPlusbarUpper(int, double)
static double KSPlusbarUpper (int n, double x)
{
   /* Compute the probability of the KS+ distribution in the upper tail
      using Smirnov's stable formula */
   const double EPSILON = 1.0E-12;
   double q;
   double Sum = 0.0;
   double term;
   double t;
   double LogCom;
   double LOGJMAX;
   int j;
   int jdiv;
   int jmax = (int) (n * (1.0 - x));

   if (n > 200000)
      return KSPlusbarAsymp (n, x);

   /* Avoid log(0) for j = jmax and q ~ 1.0 */
   if ((1.0 - x - (double) jmax / n) <= 0.0)
      jmax--;

   if (n > 3000)
      jdiv = 2;
   else
      jdiv = 3;

   j = jmax / jdiv + 1;
   LogCom = getLogFactorial (n) - getLogFactorial (j) -
            getLogFactorial (n - j);
   LOGJMAX = LogCom;

   while (j <= jmax) {
      q = (double) j / n + x;
      term = LogCom + (j - 1) * log (q) + (n - j) * log1p (-q);
      t = exp (term);
      Sum += t;
      LogCom += log ((double) (n - j) / (j + 1));
      if (t <= Sum * EPSILON)
         break;
      j++;
   }

   j = jmax / jdiv;
   LogCom = LOGJMAX + log ((double) (j + 1) / (n - j));

   while (j > 0) {
      q = (double) j / n + x;
      term = LogCom + (j - 1) * log (q) + (n - j) * log1p (-q);
      t = exp (term);
      Sum += t;
      LogCom += log ((double) j / (n - j + 1));
      if (t <= Sum * EPSILON)
         break;
      j--;
   }

   Sum *= x;
   /* add the term j = 0 */
   Sum += exp (n * log1p (-x));
   return Sum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movapd %xmm0, %xmm1
cvtsi2sd %edi, %xmm3
cmpl $0x30d41, %edi          # imm = 0x30D41
jl 0x40498
movsd 0x60a0(%rip), %xmm0     # 0x464a8
mulsd %xmm3, %xmm0
mulsd %xmm1, %xmm0
movsd 0x1058(%rip), %xmm4     # 0x41470
addsd %xmm4, %xmm0
mulsd 0x6064(%rip), %xmm3     # 0x46488
mulsd %xmm0, %xmm0
divsd %xmm3, %xmm0
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd 0x6144(%rip), %xmm2     # 0x46580
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
addsd 0x1040(%rip), %xmm1     # 0x41490
divsd %xmm3, %xmm1
movapd %xmm4, %xmm2
subsd %xmm1, %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
jae 0x407a9
xorpd 0x103e(%rip), %xmm0     # 0x414b0
movsd %xmm2, 0x8(%rsp)
callq 0x7750
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0xfe1(%rip), %xmm1      # 0x41470
minsd %xmm2, %xmm1
jmp 0x407a9
movl %edi, %ebx
movsd 0xfce(%rip), %xmm0      # 0x41470
movapd %xmm1, 0x40(%rsp)
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
mulsd %xmm3, %xmm1
cvttsd2si %xmm1, %ebp
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
divsd %xmm3, %xmm1
subsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
ucomisd %xmm0, %xmm2
adcl $-0x1, %ebp
xorl %ecx, %ecx
cmpl $0xbb9, %edi            # imm = 0xBB9
setge %cl
xorl $0x3, %ecx
movl %ebp, %eax
cltd
idivl %ecx
movl %eax, %r14d
leal 0x1(%r14), %r15d
movsd %xmm3, 0x20(%rsp)
callq 0x407bc
movsd %xmm0, 0x18(%rsp)
movl %r15d, %edi
callq 0x407bc
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movl %ebx, %edi
movl %r15d, 0x3c(%rsp)
subl %r15d, %edi
callq 0x407bc
movsd 0x20(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
subsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
cmpl %ebp, %r14d
jge 0x40652
movl %r14d, %r12d
notl %r12d
addl %ebx, %r12d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, %r13d
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
leal -0x1(%r13), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x10(%rsp)
callq 0x7360
mulsd 0x10(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x10(%rsp)
movapd 0x50(%rsp), %xmm0
xorpd 0xee0(%rip), %xmm0      # 0x414b0
callq 0x7810
mulsd 0x10(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
callq 0x7750
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leal 0x1(%r13), %r15d
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x7360
movsd 0x8(%rsp), %xmm1
mulsd 0x5f53(%rip), %xmm1     # 0x46578
ucomisd 0x28(%rsp), %xmm1
jae 0x40652
decl %r12d
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
cmpl %ebp, %r13d
movl %r15d, %r13d
movsd 0x20(%rsp), %xmm1
jl 0x40574
xorps %xmm0, %xmm0
cvtsi2sdl 0x3c(%rsp), %xmm0
subl %r14d, %ebx
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
callq 0x7360
testl %r14d, %r14d
jle 0x40771
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
movsd %xmm0, 0x18(%rsp)
xorps %xmm2, %xmm2
cvtsi2sd %r14d, %xmm2
movsd %xmm2, 0x30(%rsp)
divsd %xmm1, %xmm2
addsd 0x40(%rsp), %xmm2
movapd %xmm2, 0x50(%rsp)
leal -0x1(%r14), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd %xmm2, %xmm0
callq 0x7360
mulsd 0x10(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x28(%rsp)
movapd 0x50(%rsp), %xmm0
xorpd 0xdba(%rip), %xmm0      # 0x414b0
callq 0x7810
mulsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
callq 0x7750
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incl %ebx
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x7360
movsd 0x8(%rsp), %xmm1
mulsd 0x5e30(%rip), %xmm1     # 0x46578
ucomisd 0x10(%rsp), %xmm1
jae 0x40771
movsd 0x18(%rsp), %xmm2
addsd %xmm0, %xmm2
cmpl $0x1, %r14d
movl %ebp, %r14d
movsd 0x20(%rsp), %xmm1
movapd %xmm2, %xmm0
ja 0x4068b
movapd 0x40(%rsp), %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
xorpd 0xd21(%rip), %xmm0      # 0x414b0
callq 0x7810
mulsd 0x20(%rsp), %xmm0
callq 0x7750
movapd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq