// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
cvtsi2sd %edi, %xmm2
mulsd %xmm2, %xmm3
ucomisd 0x80d0(%rip), %xmm3     # 0x45390
jbe 0x3d2dc
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jb 0x3d5c7
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
jmp 0x3d5e8
movl %edi, %ebp
ucomisd 0x80b2(%rip), %xmm3     # 0x45398
seta %al
cmpl $0x64, %edi
setge %cl
cmpl $0x3a98, %edi           # imm = 0x3A98
jg 0x3d2c2
andb %al, %cl
jne 0x3d2c2
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm0, 0x28(%rsp)
cvttsd2si %xmm0, %r15d
leal 0x1(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
leal 0x1(,%r15,2), %r12d
movl %r12d, %r14d
imull %r14d, %r14d
shlq $0x3, %r14
movq %r14, %rdi
callq 0x7570
movq %rax, %rbx
movq %r14, %rdi
callq 0x7570
testl %r15d, %r15d
js 0x3d3a6
cmpl $0x2, %r12d
movl $0x1, %r9d
cmovgel %r12d, %r9d
leal (%r15,%r15), %ecx
movslq %ecx, %rcx
leaq 0x8(,%rcx,8), %rcx
xorl %edx, %edx
movsd 0x30fd(%rip), %xmm0     # 0x40470
movq %rbx, %rsi
movq %rdx, %rdi
xorl %r8d, %r8d
xorpd %xmm1, %xmm1
cmpq $-0x1, %rdi
jl 0x3d38a
movapd %xmm0, %xmm1
movsd %xmm1, (%rsi,%r8,8)
incq %r8
decq %rdi
cmpq %r8, %r9
jne 0x3d37c
incq %rdx
addq %rcx, %rsi
cmpq %r9, %rdx
jne 0x3d376
movl %r12d, 0x14(%rsp)
movq %rax, 0x48(%rsp)
movq %rbx, 0x38(%rsp)
leal 0x2(,%r15,2), %eax
movq %rax, 0x18(%rsp)
movsd 0x8(%rsp), %xmm2
subsd 0x28(%rsp), %xmm2
movq %r15, 0x40(%rsp)
testl %r15d, %r15d
js 0x3d482
movq 0x18(%rsp), %rcx
leal -0x2(%rcx), %eax
movl 0x14(%rsp), %r15d
imull %r15d, %eax
cltq
cmpl $0x2, %r15d
movl $0x1, %edx
cmovgel %r15d, %edx
movq %rdx, 0x28(%rsp)
movq 0x38(%rsp), %rbx
leaq (%rbx,%rax,8), %r13
movslq %ecx, %rax
leaq -0x8(,%rax,8), %rax
movq %rax, 0x50(%rsp)
xorl %r12d, %r12d
movsd %xmm2, 0x8(%rsp)
leaq 0x1(%r12), %r14
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movapd %xmm2, %xmm0
callq 0x7730
movsd (%rbx), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rbx)
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x7730
movsd 0x8(%rsp), %xmm2
movsd (%r13,%r12,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r13,%r12,8)
decl %r15d
addq 0x50(%rsp), %rbx
movq %r14, %r12
cmpq %r14, 0x28(%rsp)
jne 0x3d423
addsd %xmm2, %xmm2
addsd 0x3002(%rip), %xmm2     # 0x40490
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
movl 0x14(%rsp), %r13d
jbe 0x3d4ae
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movapd %xmm2, %xmm0
callq 0x7730
movq 0x18(%rsp), %rax
addl $-0x2, %eax
imull %r13d, %eax
cltq
movq 0x38(%rsp), %rbx
addsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
movq 0x40(%rsp), %r15
testl %r15d, %r15d
movq 0x48(%rsp), %r14
js 0x3d53a
cmpl $0x2, %r13d
movl $0x1, %eax
cmovgel %r13d, %eax
movslq %r13d, %rcx
xorl %edx, %edx
movsd 0x2f7c(%rip), %xmm0     # 0x40470
movq %rdx, %rsi
imulq %rcx, %rsi
leaq (%rbx,%rsi,8), %rsi
xorl %edi, %edi
movq %rdx, %r8
subq %rdi, %r8
js 0x3d52a
movsd (%rsi,%rdi,8), %xmm1
xorl %r9d, %r9d
movapd %xmm0, %xmm2
divsd %xmm2, %xmm1
addsd %xmm0, %xmm2
incq %r9
cmpq %r9, %r8
jge 0x3d515
movsd %xmm1, (%rsi,%rdi,8)
incq %rdi
cmpq %rax, %rdi
jne 0x3d501
incq %rdx
cmpq %rax, %rdx
jne 0x3d4f4
leaq 0x34(%rsp), %r12
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
movl %r13d, %r8d
movl %ebp, %r9d
callq 0x3d085
movq 0x18(%rsp), %rax
imull %r15d, %eax
cltq
movsd (%r14,%rax,8), %xmm2
movl (%r12), %eax
testl %ebp, %ebp
jle 0x3d63a
movsd 0x2ef6(%rip), %xmm0     # 0x40470
movsd 0x7e06(%rip), %xmm1     # 0x45388
movsd 0x7df6(%rip), %xmm3     # 0x45380
movapd %xmm0, %xmm4
movsd 0x20(%rsp), %xmm5
movl %eax, %ecx
mulsd %xmm4, %xmm2
divsd %xmm5, %xmm2
leal -0x8c(%rcx), %eax
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm6
mulsd %xmm3, %xmm6
cmovbel %ecx, %eax
ja 0x3d5b9
movapd %xmm2, %xmm6
addsd %xmm0, %xmm4
movapd %xmm6, %xmm2
decl %ebp
jne 0x3d594
jmp 0x3d63e
movapd %xmm2, %xmm0
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0x7350
movsd 0x8(%rsp), %xmm3
movsd 0x20(%rsp), %xmm2
movsd 0x7db0(%rip), %xmm1     # 0x453a0
divsd %xmm0, %xmm1
addsd 0x7dac(%rip), %xmm1     # 0x453a8
movsd 0x7dac(%rip), %xmm0     # 0x453b0
divsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorpd 0x2e9c(%rip), %xmm0     # 0x404b0
mulsd %xmm0, %xmm3
movapd %xmm3, %xmm0
callq 0x7750
addsd %xmm0, %xmm0
movsd 0x2e43(%rip), %xmm1     # 0x40470
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x3d6d1
movapd %xmm2, %xmm6
movsd %xmm6, 0x8(%rsp)
movl %eax, 0x34(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x2e31(%rip), %xmm0     # 0x40488
callq 0x7730
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x19979(%rip), %r15     # 0x56fe8
leaq 0x7d42(%rip), %rsi      # 0x453b8
movl $0x3, %edx
movq %r15, %rdi
callq 0x74b0
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x7680
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x73f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x72e0
movq %rbx, %rdi
callq 0x7500
movq %r14, %rdi
callq 0x7500
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq