// File: 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
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x8, %esi
movl %esi, -0x29c(%rbp)
movl $0x100000, %edx         # imm = 0x100000
movl %edx, -0x298(%rbp)
callq 0x1fd80
movl -0x29c(%rbp), %esi
movl -0x298(%rbp), %edx
leaq -0xf0(%rbp), %rdi
callq 0x1fd80
jmp 0x53de
movl $0x0, -0x100(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x5497
movq -0x8(%rbp), %rax
movl -0x104(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x5481
movq -0x8(%rbp), %rax
movl -0x104(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
movl -0x100(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x1fea0
jmp 0x543d
movl -0x104(%rbp), %esi
leaq -0xf0(%rbp), %rdi
callq 0x1fea0
jmp 0x5451
jmp 0x5481
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x56b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x56a9
jmp 0x5483
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x53f2
leaq -0x80(%rbp), %rdi
callq 0x1ff00
jmp 0x54a2
leaq -0xf0(%rbp), %rdi
callq 0x1ff00
jmp 0x54b0
movl -0x100(%rbp), %edx
leaq -0x150(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1f6b0
jmp 0x54c8
movl -0xc(%rbp), %edx
leaq -0x198(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x1f6b0
jmp 0x54e0
movl -0x10(%rbp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3030
movq %rax, -0x2a8(%rbp)
jmp 0x54f7
movq -0x2a8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x1f730
jmp 0x551a
leaq -0x290(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x1f730
jmp 0x552f
movl $0x0, -0x294(%rbp)
movl -0x294(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x5622
callq 0x30e0
movl -0x100(%rbp), %ecx
xorl %edx, %edx
movl %edx, -0x2b0(%rbp)
divl %ecx
movl %edx, %esi
movl -0x2b0(%rbp), %edx
leaq -0x218(%rbp), %rdi
callq 0x1f780
movl %eax, -0x2ac(%rbp)
jmp 0x5579
movl -0x2ac(%rbp), %esi
leaq -0x290(%rbp), %rdi
callq 0x1f890
movl %eax, -0x2b4(%rbp)
jmp 0x5593
movl -0x2b4(%rbp), %edx
movq -0x1a0(%rbp), %rax
movl -0x294(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
jmp 0x5539
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x569d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5691
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5685
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x1f760
jmp 0x5685
movq -0x1a0(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x1f760
leaq -0x218(%rbp), %rdi
callq 0x1f760
leaq -0x198(%rbp), %rdi
callq 0x1f6e0
leaq -0x150(%rbp), %rdi
callq 0x1f6e0
leaq -0xf0(%rbp), %rdi
callq 0x1fdb0
leaq -0x80(%rbp), %rdi
callq 0x1fdb0
movq -0x2c0(%rbp), %rax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x1f760
leaq -0x198(%rbp), %rdi
callq 0x1f6e0
leaq -0x150(%rbp), %rdi
callq 0x1f6e0
leaq -0xf0(%rbp), %rdi
callq 0x1fdb0
leaq -0x80(%rbp), %rdi
callq 0x1fdb0
movq -0xf8(%rbp), %rdi
callq 0x3530
nopw (%rax,%rax)