// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/display_test.cpp
// Function: generatePositions(unsigned int*, unsigned int, unsigned int)
usint*
generatePositions(weight_type* weights, usint size, usint number)
{
  DeltaEncoder weight_encoder(2 * sizeof(usint));
  DeltaEncoder pos_encoder(2 * sizeof(usint));
  usint sum = 0;
  for(usint i = 0; i < size; i++)
  {
    if(weights[i] > 0)
    {
      sum += weights[i];
      weight_encoder.addBit(sum);
      pos_encoder.addBit(i);
    }
  }
  weight_encoder.flush();
  pos_encoder.flush();
  DeltaVector weight_vector(weight_encoder, sum);
  DeltaVector pos_vector(pos_encoder, size);

  usint* result = new usint[number];
  DeltaVector::Iterator weight_iter(weight_vector);
  DeltaVector::Iterator pos_iter(pos_vector);
  for(usint i = 0; i < number; i++)
  {
    result[i] = pos_iter.select(weight_iter.rank(rand() % sum));
  }

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r15
leaq 0x108(%rsp), %rdi
movl $0x8, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x12e32
leaq 0x98(%rsp), %rdi
movl $0x8, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x12e32
movl %ebx, 0x4(%rsp)
testl %ebp, %ebp
movl %ebp, (%rsp)
je 0x4d12
movl %ebp, %r14d
xorl %r12d, %r12d
leaq 0x108(%rsp), %r13
leaq 0x98(%rsp), %rbp
xorl %eax, %eax
movl (%r15,%r12,4), %ebx
testl %ebx, %ebx
je 0x4d04
addl %eax, %ebx
movq %r13, %rdi
movl %ebx, %esi
callq 0x12eae
movq %rbp, %rdi
movl %r12d, %esi
callq 0x12eae
jmp 0x4d06
movl %eax, %ebx
incq %r12
movl %ebx, %eax
cmpq %r12, %r14
jne 0x4ce3
jmp 0x4d14
xorl %ebx, %ebx
leaq 0x108(%rsp), %rdi
callq 0x12ee2
leaq 0x98(%rsp), %rdi
callq 0x12ee2
leaq 0x50(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movl %ebx, %edx
callq 0x123e8
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl (%rsp), %edx
callq 0x123e8
movl %ebp, %r13d
leaq (,%r13,4), %rdi
callq 0x3030
movq %rax, %r14
leaq 0x1f0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x12400
leaq 0x178(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x12400
testl %ebp, %ebp
je 0x4dd3
xorl %ebp, %ebp
leaq 0x1f0(%rsp), %r15
leaq 0x178(%rsp), %r12
callq 0x30a0
xorl %edx, %edx
divl %ebx
movq %r15, %rdi
movl %edx, %esi
xorl %edx, %edx
callq 0x1240c
movq %r12, %rdi
movl %eax, %esi
callq 0x125ae
movl %eax, (%r14,%rbp,4)
incq %rbp
cmpq %rbp, %r13
jne 0x4da8
leaq 0x178(%rsp), %rdi
callq 0x12406
leaq 0x1f0(%rsp), %rdi
callq 0x12406
leaq 0x8(%rsp), %rdi
callq 0x123ee
leaq 0x50(%rsp), %rdi
callq 0x123ee
leaq 0x98(%rsp), %rdi
callq 0x12e3c
leaq 0x108(%rsp), %rdi
callq 0x12e3c
movq %r14, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4e5f
jmp 0x4e37
movq %rax, %rbx
jmp 0x4e6c
movq %rax, %rbx
jmp 0x4e76
jmp 0x4e4a
movq %rax, %rbx
jmp 0x4e8d
jmp 0x4e4a
movq %rax, %rbx
jmp 0x4e80
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x12406
leaq 0x1f0(%rsp), %rdi
callq 0x12406
leaq 0x8(%rsp), %rdi
callq 0x123ee
leaq 0x50(%rsp), %rdi
callq 0x123ee
leaq 0x98(%rsp), %rdi
callq 0x12e3c
leaq 0x108(%rsp), %rdi
callq 0x12e3c
movq %rbx, %rdi
callq 0x3440