// File: /workspace/github_cpp_makefile_star2_O1/bolongz[P]Systematic-Alias-Sampling/test.cpp
// Function: cramer_von_mises_sas(int, int)
double cramer_von_mises_sas(int bincount, int samplecount){
    
    std::vector<double> pmf;
    std::vector<double> values;
    
    double h = (20.0) / (bincount - 1); //[take value in [-4, 4]
    for(int i = 0; i < bincount; i++){
        double t = -10 + i * h;
        values.push_back(t);
        pmf.push_back(_normal_distribution(0.0, 1.0, t) +0.02);
    }
    
    SystematicAliasSampling _sample(pmf, values);
    
    std::vector<double> samples(samplecount); // store the results
    _sample.aliastable(); //generate table
    
    std::vector<double> cdf(bincount);
    _sample.cummulative_distribution(cdf);
    

    //_sample.systematicaliassampling(samplecount, samples);
    _sample.simple_sas(samplecount, samples);
    //_sample.goldratioaliassampling(samplecount, samples);

    std::vector<double> edf(bincount);
    _sample.empirical_distribution(samples, edf);
    
    double cvm = _sample.cramer_von_mises(cdf, edf);
    
    return cvm;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %esi, 0x1c(%rsp)
movl %edi, %r14d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x50(%rsp)
movq %rbx, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
testl %edi, %edi
jle 0x2a61
leal -0x1(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x3685(%rip), %xmm1     # 0x6020
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
leaq 0x20(%rsp), %r15
leaq 0xa0(%rsp), %r12
leaq 0x40(%rsp), %r13
leaq 0x58(%rsp), %rbp
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x10(%rsp), %xmm0
addsd 0x3657(%rip), %xmm0     # 0x6028
movsd %xmm0, 0xa0(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x29f5
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x2a00
movq %r15, %rdi
movq %r12, %rdx
callq 0x520a
movsd 0xa0(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x3603(%rip), %xmm0     # 0x6018
callq 0x2240
mulsd 0x360e(%rip), %xmm0     # 0x6030
addsd 0x360e(%rip), %xmm0     # 0x6038
movsd %xmm0, 0x58(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x2a4b
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x2a56
movq %r13, %rdi
movq %rbp, %rdx
callq 0x52e2
incl %ebx
cmpl %ebx, %r14d
jne 0x29bc
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x376c
movl 0x1c(%rsp), %ebx
movslq %ebx, %rsi
leaq 0x58(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x3d24
leaq 0xa0(%rsp), %rdi
callq 0x3820
movslq %r14d, %r14
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0x3d24
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0x2afc
movq 0x88(%rsp), %rcx
movq 0xa0(%rsp), %rdx
xorl %esi, %esi
testq %rsi, %rsi
je 0x2aec
movsd -0x8(%rcx,%rsi,8), %xmm0
addsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
jmp 0x2af4
movsd (%rdx), %xmm0
movsd %xmm0, (%rcx)
incq %rsi
cmpq %rsi, %rax
jne 0x2ad5
leaq 0xa0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x3f9c
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x3d24
leaq 0xa0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x3dae
movq 0x118(%rsp), %rax
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x2b79
movq 0x70(%rsp), %rcx
movq 0x88(%rsp), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm2
subsd (%rdx,%rsi,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x2b5f
movq %rax, %xmm2
punpckldq 0x34fa(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x3502(%rip), %xmm2     # 0x6090
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
divsd %xmm3, %xmm0
ucomisd %xmm1, %xmm0
jb 0x2baa
sqrtsd %xmm0, %xmm0
jmp 0x2baf
callq 0x20f0
movsd %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2bc4
callq 0x2140
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2bd6
callq 0x2140
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2be5
callq 0x2140
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x2bf7
callq 0x2140
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c09
callq 0x2140
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2c1b
callq 0x2140
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c2d
callq 0x2140
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x2c3f
callq 0x2140
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2c4e
callq 0x2140
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2c5d
callq 0x2140
movsd 0x10(%rsp), %xmm0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2c8e
callq 0x2140
jmp 0x2c8e
jmp 0x2c8b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2ca7
callq 0x2140
jmp 0x2ca7
jmp 0x2ca4
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2cbb
callq 0x2140
jmp 0x2cbb
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3f50
jmp 0x2cd1
jmp 0x2cce
jmp 0x2cce
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2ce0
callq 0x2140
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2cef
callq 0x2140
movq %rbx, %rdi
callq 0x2230