// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a51
leal -0x1(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x3695(%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 0x3667(%rip), %xmm0     # 0x6028
movsd %xmm0, 0xa0(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x29e5
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x29f0
movq %r15, %rdi
movq %r12, %rdx
callq 0x5238
movsd 0xa0(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x3613(%rip), %xmm0     # 0x6018
callq 0x2240
mulsd 0x361e(%rip), %xmm0     # 0x6030
addsd 0x361e(%rip), %xmm0     # 0x6038
movsd %xmm0, 0x58(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x2a3b
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x2a46
movq %r13, %rdi
movq %rbp, %rdx
callq 0x5310
incl %ebx
cmpl %ebx, %r14d
jne 0x29ac
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3770
movl 0x1c(%rsp), %ebx
movslq %ebx, %rsi
leaq 0x58(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x3d22
leaq 0xa0(%rsp), %rdi
callq 0x3824
movslq %r14d, %r14
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0x3d22
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0x2aec
movq 0x88(%rsp), %rcx
movq 0xa0(%rsp), %rdx
xorl %esi, %esi
testq %rsi, %rsi
je 0x2adc
movsd -0x8(%rcx,%rsi,8), %xmm0
addsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
jmp 0x2ae4
movsd (%rdx), %xmm0
movsd %xmm0, (%rcx)
incq %rsi
cmpq %rsi, %rax
jne 0x2ac5
leaq 0xa0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x3fa4
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x3d22
leaq 0xa0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x3db0
movq 0x118(%rsp), %rax
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x2b69
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 0x2b4f
movq %rax, %xmm2
punpckldq 0x350a(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x3512(%rip), %xmm2     # 0x6090
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
divsd %xmm3, %xmm0
ucomisd %xmm1, %xmm0
jb 0x2b9a
sqrtsd %xmm0, %xmm0
jmp 0x2b9f
callq 0x20f0
movsd %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2bb4
callq 0x2140
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2bc6
callq 0x2140
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2bd5
callq 0x2140
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x2be7
callq 0x2140
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x2bf9
callq 0x2140
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2c0b
callq 0x2140
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c1d
callq 0x2140
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x2c2f
callq 0x2140
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2c3e
callq 0x2140
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2c4d
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 0x2c7e
callq 0x2140
jmp 0x2c7e
jmp 0x2c7b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2c97
callq 0x2140
jmp 0x2c97
jmp 0x2c94
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2cab
callq 0x2140
jmp 0x2cab
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3f58
jmp 0x2cc1
jmp 0x2cbe
jmp 0x2cbe
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2cd0
callq 0x2140
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2cdf
callq 0x2140
movq %rbx, %rdi
callq 0x2230