// File: /workspace/github_cpp_makefile_star2_O3/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, %xmm2
mulsd %xmm0, %xmm2
cvtsi2sd %edi, %xmm1
mulsd %xmm1, %xmm2
ucomisd 0x8795(%rip), %xmm2     # 0x46420
jbe 0x3dca7
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x3e00d
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x3e02c
ucomisd 0x8779(%rip), %xmm2     # 0x46428
seta %al
cmpl $0x64, %edi
setge %cl
cmpl $0x3a98, %edi           # imm = 0x3A98
jg 0x3dc8d
andb %al, %cl
jne 0x3dc8d
movl %edi, 0x24(%rsp)
movapd %xmm1, 0x30(%rsp)
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebx
leal 0x1(%rbx), %eax
leal 0x2(%rbx,%rbx), %ecx
movq %rcx, 0x10(%rsp)
leal 0x1(%rbx,%rbx), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movl %ebp, %r14d
imull %r14d, %r14d
shlq $0x3, %r14
movq %r14, %rdi
callq 0x7570
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x7570
movsd (%rsp), %xmm10
movq %rax, 0x40(%rsp)
movl %ebp, 0xc(%rsp)
movl %ebp, %r12d
movq %rbx, 0x28(%rsp)
testl %ebx, %ebx
js 0x3decd
movl 0x10(%rsp), %eax
leaq -0x1(%r12), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq 0x18(%rsp), %rcx
addq $0x8, %rcx
movq 0x28(%rsp), %r11
leal (%r11,%r11), %edx
movslq %edx, %rdx
leaq 0x8(,%rdx,8), %rdx
movq $-0x1, %rsi
xorl %edi, %edi
movdqa 0x377a(%rip), %xmm1     # 0x414f0
movdqa 0x3782(%rip), %xmm2     # 0x41500
pxor %xmm2, %xmm0
movq 0x36e6(%rip), %xmm3     # 0x41470
pcmpeqd %xmm4, %xmm4
movdqa 0x86aa(%rip), %xmm5     # 0x46440
movq %rsi, %r8
xorl %r9d, %r9d
movdqa %xmm1, %xmm6
movdqa %xmm6, %xmm7
pxor %xmm2, %xmm7
movdqa %xmm7, %xmm8
pcmpgtd %xmm0, %xmm8
pcmpeqd %xmm0, %xmm7
pshufd $0xf5, %xmm7, %xmm9     # xmm9 = xmm7[1,1,3,3]
pand %xmm8, %xmm9
pshufd $0xf5, %xmm8, %xmm7     # xmm7 = xmm8[1,1,3,3]
por %xmm9, %xmm7
movd %xmm7, %r10d
notl %r10d
testb $0x1, %r10b
je 0x3ddf5
leaq 0x1(%r8), %r10
pxor %xmm8, %xmm8
cmpq $-0x1, %r10
jl 0x3ddee
movdqa %xmm3, %xmm8
movq %xmm8, -0x8(%rcx,%r9,8)
pxor %xmm4, %xmm7
pextrw $0x4, %xmm7, %r10d
testb $0x1, %r10b
je 0x3de19
pxor %xmm7, %xmm7
cmpq $-0x1, %r8
jl 0x3de13
movdqa %xmm3, %xmm7
movq %xmm7, (%rcx,%r9,8)
addq $0x2, %r9
paddq %xmm5, %xmm6
addq $-0x2, %r8
cmpq %r9, %rax
jne 0x3dda0
incq %rdi
incq %rsi
addq %rdx, %rcx
cmpq %r12, %rdi
jne 0x3dd96
testl %r11d, %r11d
js 0x3decd
movq 0x10(%rsp), %rcx
leal -0x2(%rcx), %eax
imull 0xc(%rsp), %eax
cltq
movq 0x18(%rsp), %rbx
leaq (%rbx,%rax,8), %r14
movslq %ecx, %rax
leaq -0x8(,%rax,8), %rax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq %r12, %r13
leaq 0x1(%r15), %rbp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movapd %xmm10, %xmm0
callq 0x7730
movsd (%rbx), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rbx)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd (%rsp), %xmm0
callq 0x7730
movsd (%rsp), %xmm10
movsd (%r14,%r15,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r15,8)
addq 0x48(%rsp), %rbx
movq %rbp, %r15
decq %r13
jne 0x3de77
addsd %xmm10, %xmm10
addsd 0x35b5(%rip), %xmm10    # 0x41490
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm10
movl 0xc(%rsp), %r13d
jbe 0x3defd
movapd %xmm10, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
callq 0x7730
movq 0x10(%rsp), %rax
addl $-0x2, %eax
imull %r13d, %eax
cltq
movq 0x18(%rsp), %rbx
addsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
movq 0x28(%rsp), %r15
testl %r15d, %r15d
movq 0x40(%rsp), %r14
movl 0x24(%rsp), %ebp
js 0x3df80
movslq %r13d, %rax
xorl %ecx, %ecx
movsd 0x3536(%rip), %xmm0     # 0x41470
movq %rcx, %rdx
imulq %rax, %rdx
leaq (%rbx,%rdx,8), %rdx
xorl %esi, %esi
movq %rcx, %rdi
subq %rsi, %rdi
js 0x3df70
movsd (%rdx,%rsi,8), %xmm1
xorl %r8d, %r8d
movapd %xmm0, %xmm2
divsd %xmm2, %xmm1
addsd %xmm0, %xmm2
incq %r8
cmpq %r8, %rdi
jae 0x3df5b
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %r12, %rsi
jne 0x3df47
incq %rcx
cmpq %r12, %rcx
jne 0x3df3a
leaq 0x54(%rsp), %r12
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
movl %r13d, %r8d
movl %ebp, %r9d
callq 0x3da41
movq 0x10(%rsp), %rax
imull %r15d, %eax
cltq
movsd (%r14,%rax,8), %xmm2
movl (%r12), %eax
testl %ebp, %ebp
jle 0x3e07e
movsd 0x34b0(%rip), %xmm0     # 0x41470
movsd 0x8450(%rip), %xmm1     # 0x46418
movsd 0x8440(%rip), %xmm3     # 0x46410
movapd %xmm0, %xmm4
movapd 0x30(%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 0x3dfff
movapd %xmm2, %xmm6
addsd %xmm0, %xmm4
movapd %xmm6, %xmm2
decl %ebp
jne 0x3dfda
jmp 0x3e082
movapd %xmm1, %xmm0
movapd %xmm1, 0x30(%rsp)
movsd %xmm2, (%rsp)
callq 0x7350
movsd (%rsp), %xmm2
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x8418(%rip), %xmm0     # 0x46450
divpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd 0x83e4(%rip), %xmm1     # 0x46430
addsd %xmm0, %xmm1
xorpd 0x3458(%rip), %xmm1     # 0x414b0
mulsd %xmm1, %xmm2
movapd %xmm2, %xmm0
callq 0x7750
addsd %xmm0, %xmm0
movsd 0x33ff(%rip), %xmm1     # 0x41470
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x3e10c
movapd %xmm2, %xmm6
movq %xmm6, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x33f2(%rip), %xmm0     # 0x41488
callq 0x7730
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x19f3c(%rip), %r15     # 0x57fe8
leaq 0x83ad(%rip), %rsi      # 0x46460
movl $0x3, %edx
movq %r15, %rdi
callq 0x74b0
movq %r15, %rdi
movsd (%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 (%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq