// File: /workspace/github_cpp_makefile_star2_O1/millanek[P]Dsuite/kstest.cpp
// Function: ks_test_of_uniformity(std::vector<double, std::allocator<double>>, std::ostream&, bool)
double ks_test_of_uniformity(std::vector<double> sampleVect0to1, std::ostream& outfile, bool printDebug) {

    unsigned int N = sampleVect0to1.size();
    
    double d, Dplusmax, Dminusmax;
    std::vector<double> DplusVals(N,0.0);
    std::vector<double> DminusVals(N,0.0);
    
    for (int i = 0; i < N; i++) {
        int j = i+1;
        double ratio = (double)j/N;
        double ratiominus = (double)i/N;
        DplusVals[i] = ratio - sampleVect0to1[i];
        DminusVals[i] = sampleVect0to1[i] - ratiominus;
    }
    
    Dplusmax = *max_element(DplusVals.begin(), DplusVals.end());
    Dminusmax = *max_element(DminusVals.begin(), DminusVals.end());
    
    
  //  std::cerr << "Dplusmax: " << Dplusmax << std::endl;
  //  std::cerr << "Dminusmax: " << Dminusmax << std::endl;
    
  //  print_vector(DplusVals, std::cerr, ',');
  //  print_vector(DminusVals, std::cerr, ',');
    
    
    if (Dplusmax > Dminusmax) {
        d = Dplusmax;
    } else {
        d = Dminusmax;
    }
    
   // std::cerr << "d: " << d << std::endl;
    
    // Return p-value
    return 1 - KScdf(N,d);

}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %r14
movq 0x8(%rdi), %rbx
subq (%rdi), %rbx
sarq $0x3, %rbx
movl %ebx, %r15d
xorl %r13d, %r13d
leaq 0x10(%rsp), %rdx
movq %r13, (%rdx)
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %r12
movq %r15, %rsi
movq %r12, %rcx
callq 0xebec
movq %r13, (%r12)
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
leaq 0xf(%rsp), %rcx
movq %r15, %rsi
callq 0xebec
testl %ebx, %ebx
je 0x3da6b
cvtsi2sd %r15, %xmm0
movq (%r14), %rax
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %rdx
movl %ebx, %esi
xorl %edi, %edi
leaq 0x1(%rdi), %r8
xorps %xmm1, %xmm1
cvtsi2sd %r8d, %xmm1
divsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
divsd %xmm0, %xmm2
subsd (%rax,%rdi,8), %xmm1
movsd %xmm1, (%rcx,%rdi,8)
movsd (%rax,%rdi,8), %xmm1
subsd %xmm2, %xmm1
movsd %xmm1, (%rdx,%rdi,8)
movq %r8, %rdi
cmpq %r8, %rsi
jne 0x3da30
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
cmpq %rax, %rdx
sete %sil
movq %rdx, %rcx
addq $0x8, %rcx
cmpq %rax, %rcx
sete %dil
orb %sil, %dil
je 0x3da94
movq %rdx, %rsi
jmp 0x3dab0
movsd (%rcx), %xmm0
ucomisd (%rdx), %xmm0
movq %rcx, %rsi
ja 0x3daa4
movq %rdx, %rsi
addq $0x8, %rcx
movq %rsi, %rdx
cmpq %rax, %rcx
jne 0x3da94
movsd (%rsi), %xmm0
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
cmpq %rax, %rdx
sete %sil
movq %rdx, %rcx
addq $0x8, %rcx
cmpq %rax, %rcx
sete %dil
orb %sil, %dil
je 0x3dadd
movq %rdx, %rsi
jmp 0x3daf9
movsd (%rcx), %xmm1
ucomisd (%rdx), %xmm1
movq %rcx, %rsi
ja 0x3daed
movq %rdx, %rsi
addq $0x8, %rcx
movq %rsi, %rdx
cmpq %rax, %rcx
jne 0x3dadd
maxsd (%rsi), %xmm0
movl %ebx, %edi
callq 0x3dec0
movsd %xmm0, 0x40(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3db21
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3db38
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movsd 0x2930(%rip), %xmm0     # 0x40470
subsd 0x40(%rsp), %xmm0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3db73
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0x3db73
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3db8a
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x7740