// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x88(%rcx), %eax
jle 0x4e11
movq -0x58(%rbp), %rdi
movq 0x78(%rdi), %rsi
movslq -0xc(%rbp), %rdx
callq 0x8ef0
testb $0x1, %al
jne 0x4da7
jmp 0x4e11
movq -0x58(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0x8c(%rcx), %eax
jg 0x4dc5
movq -0x58(%rbp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x4ddd
movq -0x58(%rbp), %rcx
movl -0xc(%rbp), %eax
imull 0x90(%rcx), %eax
cltd
idivl 0x94(%rcx)
movl %eax, -0x20(%rbp)
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %esi
subl -0x20(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x4d60
movq -0x58(%rbp), %rdi
movl -0x20(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
addl -0xc(%rbp), %ecx
subl -0x20(%rbp), %ecx
callq 0x4d60
jmp 0x4f3e
movq -0x58(%rbp), %rax
movq 0x78(%rax), %xmm0
movaps 0x626f(%rip), %xmm1     # 0xb090
movaps %xmm1, -0x80(%rbp)
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x626f(%rip), %xmm1     # 0xb0a0
movaps %xmm1, -0x70(%rbp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0xd9f5(%rip), %rdi      # 0x12858
leaq 0xc666(%rip), %rsi      # 0x114d0
callq 0x4560
movq -0x58(%rbp), %rax
movaps -0x80(%rbp), %xmm2
movaps -0x70(%rbp), %xmm1
movaps %xmm0, %xmm4
movsd -0x60(%rbp), %xmm0
movsd 0x617d(%rip), %xmm3     # 0xb008
subsd %xmm4, %xmm3
mulsd %xmm3, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x78(%rax), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
subsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x4f3c
movq -0x58(%rbp), %rdi
cvttsd2si -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
movsd -0x38(%rbp), %xmm0
cvtsi2sdl -0x44(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x44(%rbp), %esi
movsd -0x50(%rbp), %xmm0
callq 0x4cd0
movsd %xmm0, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x3b70
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x28(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4ec9
jmp 0x4f3e
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)