// File: bolongz[P]Systematic-Alias-Sampling/./sas.h
// Function: SystematicAliasSampling::aliastable()
void aliastable(){
            
            if( !normalize() ) std::cout << "Wrong normalization" <<std::endl;;
            Table F(bincount); //define F
            for(size_t i = 0; i < bincount ; i++){
                F[i] = pmf[i] * double(bincount);
            }
            aliasvalue.resize(bincount);
            aliasindices.resize(bincount);
            aliasprobabilities.resize(bincount);
            std::stack<double> G, S;

            /* Denote by G the set of i, if F[i] >= 1, otherwise S*/
            
            for(size_t i = 0; i < bincount ; i++) {
                if(F[i] >= 1.0 || fabs(F[i] - 1.0) < 1e-6) G.push(i);
                else S.push(i);
                
                aliasindices[i] = i;
            }
             
            /* main loop until S is empty */
            while(!G.empty() && !S.empty()){
            
               int j = S.top();
               S.pop(); // remove the top element of stack S
               int k = G.top(); //get the top element in the stack G
               aliasindices[j] = k;
               aliasprobabilities[j] = 1.0 - F[j];
               
               F[k] = (F[k] + F[j]) -1.0;
               if(F[k] < 1.0){
                    G.pop();
                    S.push(k);
               }

            }
            for(size_t i = 0; i < bincount ; i++) {
                aliasvalue[i] = values[aliasindices[i]];
            }
         //   aliasprobabilities = F;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x5d60
testb $0x1, %al
jne 0x3dc5
movq 0xc22e(%rip), %rdi      # 0xffd8
leaq 0x733d(%rip), %rsi      # 0xb0ee
callq 0x2110
movq %rax, %rdi
movq 0xc208(%rip), %rsi      # 0xffc8
callq 0x2130
movq -0x118(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x128(%rbp)
leaq -0x21(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x43e0
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
leaq -0x20(%rbp), %rdi
callq 0x4400
jmp 0x3e00
leaq -0x21(%rbp), %rdi
callq 0x4470
movq $0x0, -0x40(%rbp)
movq -0x118(%rbp), %rcx
movq -0x40(%rbp), %rax
cmpq 0x78(%rcx), %rax
jae 0x3ebb
movq -0x118(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3b70
movq %rax, %rcx
movq -0x118(%rbp), %rax
movsd (%rcx), %xmm0
movq 0x78(%rax), %xmm1
movaps 0x7240(%rip), %xmm2     # 0xb090
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x7244(%rip), %xmm2     # 0xb0a0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x130(%rbp)
movq -0x40(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd -0x130(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3e11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0x4470
jmp 0x43d7
movq -0x118(%rbp), %rax
movq %rax, %rdi
addq $0x30, %rdi
movq 0x78(%rax), %rsi
callq 0x5ee0
jmp 0x3ed4
movq -0x118(%rbp), %rax
movq %rax, %rdi
addq $0x48, %rdi
movq 0x78(%rax), %rsi
callq 0x5ee0
jmp 0x3eed
movq -0x118(%rbp), %rax
movq %rax, %rdi
addq $0x60, %rdi
movq 0x78(%rax), %rsi
callq 0x5ee0
jmp 0x3f06
leaq -0x90(%rbp), %rdi
callq 0x5f70
jmp 0x3f14
leaq -0xe0(%rbp), %rdi
callq 0x5f70
jmp 0x3f22
movq $0x0, -0xe8(%rbp)
movq -0x118(%rbp), %rcx
movq -0xe8(%rbp), %rax
cmpq 0x78(%rcx), %rax
jae 0x40e4
movq -0xe8(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd (%rax), %xmm0
movsd 0x70a7(%rip), %xmm1     # 0xb008
ucomisd %xmm1, %xmm0
jae 0x3fa4
movq -0xe8(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd (%rax), %xmm1
movsd 0x7085(%rip), %xmm0     # 0xb008
subsd %xmm0, %xmm1
movaps 0x70f2(%rip), %xmm0     # 0xb080
pand %xmm0, %xmm1
movsd 0x70ae(%rip), %xmm0     # 0xb048
ucomisd %xmm1, %xmm0
jbe 0x402f
movaps 0x70e5(%rip), %xmm1     # 0xb090
movq -0xe8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x70e1(%rip), %xmm1     # 0xb0a0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x5fa0
jmp 0x3feb
jmp 0x4078
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x43ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x43c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6030
jmp 0x43c2
movaps 0x705a(%rip), %xmm1     # 0xb090
movq -0xe8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7056(%rip), %xmm1     # 0xb0a0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x5fa0
jmp 0x4076
jmp 0x4078
movq -0x118(%rbp), %rdi
movaps 0x700a(%rip), %xmm1     # 0xb090
movq -0xe8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7006(%rip), %xmm1     # 0xb0a0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
addq $0x48, %rdi
movq -0xe8(%rbp), %rsi
callq 0x3b70
movsd -0x138(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0xe8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe8(%rbp)
jmp 0x3f2d
jmp 0x40e6
leaq -0x90(%rbp), %rdi
callq 0x5fd0
movb %al, -0x139(%rbp)
jmp 0x40fa
movb -0x139(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x13a(%rbp)
jne 0x4131
jmp 0x410f
leaq -0xe0(%rbp), %rdi
callq 0x5fd0
movb %al, -0x13b(%rbp)
jmp 0x4123
movb -0x13b(%rbp), %al
xorb $-0x1, %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0x4140
jmp 0x42d4
leaq -0xe0(%rbp), %rdi
callq 0x5ff0
movq %rax, -0x148(%rbp)
jmp 0x4155
movq -0x148(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0xfc(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6010
jmp 0x4174
leaq -0x90(%rbp), %rdi
callq 0x5ff0
movq %rax, -0x150(%rbp)
jmp 0x4189
movq -0x118(%rbp), %rdi
movq -0x150(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x100(%rbp)
cvtsi2sdl -0x100(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
addq $0x48, %rdi
movslq -0xfc(%rbp), %rsi
callq 0x3b70
movsd -0x170(%rbp), %xmm0
movsd %xmm0, (%rax)
movslq -0xfc(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movq -0x118(%rbp), %rdi
movsd 0x6e1c(%rip), %xmm0     # 0xb008
subsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
addq $0x60, %rdi
movslq -0xfc(%rbp), %rsi
callq 0x3b70
movsd -0x168(%rbp), %xmm0
movsd %xmm0, (%rax)
movslq -0x100(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd (%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
movslq -0xfc(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd -0x160(%rbp), %xmm0
addsd (%rax), %xmm0
movsd 0x6db4(%rip), %xmm1     # 0xb008
subsd %xmm1, %xmm0
movsd %xmm0, -0x158(%rbp)
movslq -0x100(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd -0x158(%rbp), %xmm0
movsd %xmm0, (%rax)
movslq -0x100(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x3b70
movsd 0x6d74(%rip), %xmm0     # 0xb008
ucomisd (%rax), %xmm0
jbe 0x42cf
leaq -0x90(%rbp), %rdi
callq 0x6010
jmp 0x42a8
cvtsi2sdl -0x100(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x5fa0
jmp 0x42cd
jmp 0x42cf
jmp 0x40e6
movq $0x0, -0x110(%rbp)
movq -0x118(%rbp), %rcx
movq -0x110(%rbp), %rax
cmpq 0x78(%rcx), %rax
jae 0x4398
movq -0x118(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x180(%rbp)
addq $0x48, %rdi
movq -0x110(%rbp), %rsi
callq 0x3b70
movq -0x180(%rbp), %rdi
movsd (%rax), %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rsi
movq %rsi, %rcx
sarq $0x3f, %rcx
movsd 0x6d02(%rip), %xmm1     # 0xb040
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
andq %rcx, %rax
orq %rax, %rsi
callq 0x3b70
movq -0x118(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
addq $0x30, %rdi
movq -0x110(%rbp), %rsi
callq 0x3b70
movsd -0x178(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x110(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x110(%rbp)
jmp 0x42df
leaq -0xe0(%rbp), %rdi
callq 0x6030
leaq -0x90(%rbp), %rdi
callq 0x6030
leaq -0x20(%rbp), %rdi
callq 0x4ad0
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x6030
leaq -0x20(%rbp), %rdi
callq 0x4ad0
movq -0x30(%rbp), %rdi
callq 0x2200