// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]Dsuite/kstest.cpp
// Function: K(int, double)
double K(int n,double d)
{
   int k,m,i,j,g,eH,eQ;
   double h,s,*H,*Q;
    /* OMIT NEXT TWO LINES IF YOU REQUIRE >7 DIGIT ACCURACY IN THE RIGHT TAIL*/
s=d*d*n;
if(s>7.24||(s>3.76&&n>99) || n > 15000) return 1-2*exp(-(2.000071+.331/sqrt(n)+1.409/n)*s);
   k=(int)(n*d)+1;
   m=2*k-1;
   h=k-n*d;
   H=(double*)malloc((m*m)*sizeof(double));
   Q=(double*)malloc((m*m)*sizeof(double));
       for(i=0;i<m;i++)
         for(j=0;j<m;j++)
           if(i-j+1<0) H[i*m+j]=0;
          else     H[i*m+j]=1;
    for(i=0;i<m;i++)
    {
    H[i*m]-=pow(h,i+1);
    H[(m-1)*m+i]-=pow(h,(m-i));
    }
    H[(m-1)*m]+=(2*h-1>0?pow(2*h-1,m):0);
    for(i=0;i<m;i++)
    for(j=0;j<m;j++)
    if(i-j+1>0)
        for(g=1;g<=i-j+1;g++) H[i*m+j]/=g;
    eH=0;
    mPower(H,eH,Q,&eQ,m,n);
    s=Q[(k-1)*m+k-1];
    for(i=1;i<=n;i++)
    {
    s=s*i/n;
    if(s<1e-140){s*=1e140; eQ-=140;}
    }
    s*=pow(10.,eQ);
    std::cerr << "s: " << s << std::endl;
    
    free(H);
    free(Q);
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
cvtsi2sd %edi, %xmm1
mulsd %xmm1, %xmm2
ucomisd 0x7ec3(%rip), %xmm2     # 0x3b3b0
jbe 0x33506
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x335e9
sqrtsd %xmm1, %xmm0
jmp 0x33608
ucomisd 0x7eaa(%rip), %xmm2     # 0x3b3b8
seta %al
cmpl $0x64, %edi
setge %cl
cmpl $0x3a98, %edi           # imm = 0x3A98
jg 0x334ef
andb %al, %cl
jne 0x334ef
movl %edi, 0x2c(%rsp)
movapd %xmm1, %xmm2
movsd %xmm0, 0x20(%rsp)
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %r12d
leal 0x1(%r12), %eax
movl %eax, 0x18(%rsp)
leal 0x2(%r12,%r12), %r13d
leal 0x1(%r12,%r12), %r15d
movapd 0x2f5b(%rip), %xmm0     # 0x364b0
movapd %xmm1, 0x30(%rsp)
xorpd %xmm1, %xmm0
movapd %xmm0, (%rsp)
movl %r15d, %r14d
imull %r14d, %r14d
shlq $0x3, %r14
movq %r14, %rdi
callq 0x7560
movq %rax, %rbx
movq %r14, %rdi
callq 0x7560
movslq %r15d, %r9
xorl %r8d, %r8d
testl %r9d, %r9d
movl $0x0, %ebp
cmovgl %r15d, %ebp
movq %r12, 0x58(%rsp)
leal (%r12,%r12), %ecx
movslq %ecx, %rcx
leaq 0x8(,%rcx,8), %rcx
movsd 0x2ec0(%rip), %xmm0     # 0x36470
movq %rbx, %rdx
cmpq %rbp, %r8
je 0x3365a
movq %r8, %rsi
xorl %edi, %edi
cmpq %rdi, %r15
je 0x335e1
xorpd %xmm1, %xmm1
cmpq $-0x1, %rsi
jl 0x335d4
movapd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rdi,8)
incq %rdi
decq %rsi
jmp 0x335c1
incq %r8
addq %rcx, %rdx
jmp 0x335b3
movapd %xmm1, %xmm0
movapd %xmm1, 0x30(%rsp)
movsd %xmm2, (%rsp)
callq 0x7360
movsd (%rsp), %xmm2
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x7dbc(%rip), %xmm0     # 0x3b3d0
divpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd 0x7d98(%rip), %xmm1     # 0x3b3c0
addsd %xmm0, %xmm1
xorpd 0x2e7c(%rip), %xmm1     # 0x364b0
mulsd %xmm1, %xmm2
movapd %xmm2, %xmm0
callq 0x7760
addsd %xmm0, %xmm0
movsd 0x2e23(%rip), %xmm1     # 0x36470
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x338b1
movq %r9, 0x48(%rsp)
movq %rax, 0x60(%rsp)
cvtsi2sdl 0x18(%rsp), %xmm0
movapd (%rsp), %xmm1
mulsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
movq %r13, 0x50(%rsp)
leal -0x2(%r13), %eax
movslq %eax, %rcx
imull %r15d, %eax
cltq
movq %rax, 0x40(%rsp)
leaq (%rbx,%rax,8), %rax
movq %rax, 0x20(%rsp)
leaq 0x8(,%rcx,8), %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movq %rbx, 0x68(%rsp)
movl %r15d, %r12d
cmpq %r14, %rbp
je 0x33710
movq %rbp, %r13
leaq 0x1(%r14), %rbp
cvtsi2sd %ebp, %xmm1
movapd (%rsp), %xmm0
callq 0x7720
movsd (%rbx), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rbx)
cvtsi2sd %r12d, %xmm1
movapd (%rsp), %xmm0
callq 0x7720
movq 0x20(%rsp), %rax
movsd (%rax,%r14,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r14,8)
decl %r12d
addq 0x18(%rsp), %rbx
movq %rbp, %r14
movq %r13, %rbp
jmp 0x336b6
movapd (%rsp), %xmm1
addsd %xmm1, %xmm1
addsd 0x2d6f(%rip), %xmm1     # 0x36490
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x33739
movapd %xmm1, %xmm0
cvtsi2sd %r15d, %xmm1
callq 0x7720
movq 0x68(%rsp), %rbx
movq 0x40(%rsp), %rax
addsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
movl %r15d, %eax
pushq $0x1
popq %rcx
xorl %edx, %edx
movsd 0x2d13(%rip), %xmm0     # 0x36470
movq 0x60(%rsp), %r13
movq 0x48(%rsp), %r10
cmpq %rbp, %rdx
je 0x337c0
movq %rdx, %rsi
imulq %r10, %rsi
leaq (%rbx,%rsi,8), %rsi
xorl %edi, %edi
movl %ecx, %r8d
testl %r8d, %r8d
movl $0x0, %r9d
cmovgl %r8d, %r9d
cmpq %rax, %rdi
je 0x337b9
cmpq %rdi, %rdx
jae 0x3379b
incq %rdi
decl %r8d
jmp 0x3377c
movapd %xmm0, %xmm1
subl $0x1, %r9d
jb 0x33793
movsd (%rsi,%rdi,8), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, (%rsi,%rdi,8)
addsd %xmm0, %xmm1
jmp 0x3379f
incq %rdx
incl %ecx
jmp 0x33767
xorl %r14d, %r14d
leaq 0x74(%rsp), %r12
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movl %r15d, %r8d
movl 0x2c(%rsp), %ebp
movl %ebp, %r9d
callq 0x3337b
movq 0x50(%rsp), %rax
imull 0x58(%rsp), %eax
cltq
movsd (%r13,%rax,8), %xmm6
movl (%r12), %eax
testl %ebp, %ebp
cmovgl %ebp, %r14d
movsd 0x2c69(%rip), %xmm0     # 0x36470
movsd 0x7b99(%rip), %xmm1     # 0x3b3a8
movsd 0x7b89(%rip), %xmm2     # 0x3b3a0
movapd %xmm0, %xmm3
movapd 0x30(%rsp), %xmm5
subl $0x1, %r14d
jb 0x33854
mulsd %xmm3, %xmm6
divsd %xmm5, %xmm6
leal -0x8c(%rax), %ecx
ucomisd %xmm6, %xmm1
movapd %xmm6, %xmm4
mulsd %xmm2, %xmm4
cmoval %ecx, %eax
ja 0x3384a
movapd %xmm6, %xmm4
addsd %xmm0, %xmm3
movapd %xmm4, %xmm6
jmp 0x33821
cvtsi2sd %eax, %xmm1
movsd 0x2c28(%rip), %xmm0     # 0x36488
movsd %xmm6, (%rsp)
callq 0x7720
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x1d76d(%rip), %rdi     # 0x50fe8
leaq 0x7b5e(%rip), %rsi      # 0x3b3e0
callq 0x7400
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x7680
movq %rax, %rdi
callq 0x71e0
movq %rbx, %rdi
callq 0x74e0
movq %r13, %rdi
callq 0x74e0
movsd (%rsp), %xmm0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq