// File: /workspace/github_cpp_makefile_star2_O3/bolongz[P]Systematic-Alias-Sampling/./sas.h
// Function: SystematicAliasSampling::systematicaliassampling(int, std::vector<double, std::allocator<double>>&, int)
void systematicaliassampling(int samplecount, Table &samples, int from = 0){
            int splitindex;  
            if(samplecount > minbatchsize && isdivisible(bincount, samplecount)){
                if(samplecount <= minrecursize){
                    splitindex = minbatchsize;
                }else{
                    splitindex = samplecount * batchsplitnumerator / batchsplitdenominator;
                }
                systematicaliassampling(samplecount - splitindex, samples, from);
                systematicaliassampling(splitindex, samples, from + samplecount - splitindex);
            }else{
                 
                double steps = double(bincount) / samplecount;
                double r = steps * (1.0 - __random(gen));
                //double x =  r;
                double x =  bincount - r;
                int i = from;

                int to = from + samplecount;
                while(i < to){
                    int ri = int(x);
                    double rf  = x  -ri;
                    samples[i] = aliassample(ri, rf);
                    //x += steps;
                    x -= steps;
                    i++;
                }
            }
        
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %rbx
cmpl %esi, 0x88(%rdi)
jge 0x4139
movq 0x78(%rbx), %rsi
movslq %r12d, %rdx
movq %rbx, %rdi
callq 0x4d56
testb %al, %al
je 0x4139
cmpl %r12d, 0x8c(%rbx)
jge 0x410b
movl 0x90(%rbx), %eax
imull %r12d, %eax
cltd
idivl 0x94(%rbx)
movl %eax, %r15d
jmp 0x4112
movl 0x88(%rbx), %r15d
movl %r12d, %esi
subl %r15d, %esi
movq %rbx, %rdi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x40ba
addl %r12d, %ebp
subl %r15d, %ebp
movl %r15d, %r12d
cmpl %r15d, 0x88(%rbx)
jl 0x40d9
jmp 0x413c
movl %r12d, %r15d
movsd 0x78(%rbx), %xmm0
movapd %xmm0, (%rsp)
leaq 0x63a3(%rip), %rdi      # 0xa4f0
callq 0x4eae
testl %r15d, %r15d
jle 0x4232
movapd (%rsp), %xmm2
unpcklps 0x1f19(%rip), %xmm2     # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1f21(%rip), %xmm2     # 0x6090
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r15d, %xmm2
divsd %xmm2, %xmm1
addl %ebp, %r15d
movsd 0x78(%rbx), %xmm3
unpcklps 0x1eea(%rip), %xmm3     # xmm3 = xmm3[0],mem[0],xmm3[1],mem[1]
subpd 0x1ef2(%rip), %xmm3     # 0x6090
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
movsd 0x76d6(%rip), %xmm3     # 0xb888
movsd 0x76c6(%rip), %xmm4     # 0xb880
subsd %xmm4, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm4, %xmm0
movsd 0x1e42(%rip), %xmm3     # 0x6010
subsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
subsd %xmm3, %xmm2
movq 0x60(%rbx), %rax
movq (%r14), %rcx
movslq %ebp, %rdx
movslq %r15d, %rsi
leaq 0x30(%rbx), %rdi
addq $0x18, %rbx
cvttsd2si %xmm2, %r8d
cvttpd2dq %xmm2, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
movslq %r8d, %r8
movsd (%rax,%r8,8), %xmm0
ucomisd %xmm3, %xmm0
movq %rdi, %r9
cmovbq %rbx, %r9
movq (%r9), %r9
movsd (%r9,%r8,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
subsd %xmm1, %xmm2
incq %rdx
cmpq %rsi, %rdx
jl 0x41ef
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop