// File: /workspace/github_cpp_makefile_star2_O3/cegme[P]vose/VoseTree.cc
// Function: VoseTree::add(marble)
double VoseTree::add(marble m) {
  
  // Update the new weight
  total_weight += m.weight;
  double contribution = (double) m.weight / total_weight;

  // Add the marble to another branch
  if(!branches.empty()) {
    double new_total = branches.back() + m.weight;
    branches.push_back(new_total);
  }
  else {
    branches.push_back(m.weight);
  }
    
  // Add this marble to the free marble list
  vosetreenode vtn;
  vtn.isBag = false;
  vtn.ball = m;
  nodes.push_back(vtn);

  // Shrink data structure if necessary
  if (branches.size() - last_bag > max_marbles) {
    // Compress the marbles to make a new bag
    Vose v;
    for(size_t i = last_bag; i != nodes.size(); ++i) {
      v.add(nodes[i].ball);
    }
    v.init();
    vosetreenode vtn2 (v);

    nodes[last_bag] = vtn2;
    nodes.resize(last_bag+1);
    
    branches.resize(last_bag+1);
    branches[last_bag] = total_weight;

    ++last_bag;
    if (last_bag > max_bags) {
      // Merge all the bags into one bag
      Vose z;
      z = merge_bags();
      nodes.resize(1);
      nodes[0] = z;

      // Update the branch and bag locations
      last_bag = 1;
      total_weight = z.weight();

      branches.resize(1);
      branches[0] = total_weight;
    } 
  } 
  
  // Update a random number generator to new range
  std::default_random_engine generator(VoseUtil::RANDOM_SEED);
  std::uniform_real_distribution<double>
    real_distribution(0, total_weight);
  random_branch = std::bind(real_distribution, generator);

  return contribution;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movq %rsi, %r12
movq %rdi, %r13
movq (%rsi), %rcx
movq 0x58(%rdi), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq %rax, 0x58(%rdi)
addq $0x20, %rdi
movq 0x20(%r13), %rax
movq 0x28(%r13), %rsi
cmpq %rsi, %rax
movq %rdi, -0x48(%rbp)
movq %rcx, -0x30(%rbp)
je 0x26d3
movq -0x8(%rsi), %rax
addq %rcx, %rax
cvtsi2sd %rax, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x3f8(%rbp)
cmpq 0x30(%r13), %rsi
jne 0x26e1
leaq -0x3f8(%rbp), %rdx
callq 0x516c
jmp 0x26ec
cmpq 0x30(%r13), %rax
je 0x2e1e
movq (%r12), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%r13)
leaq -0x3e8(%rbp), %r14
leaq -0x3d8(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
xorl %ebx, %ebx
movb %bl, (%rax)
leaq -0x3c0(%rbp), %r15
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2100
movb %bl, -0x38(%r15)
movq (%r12), %rax
movq %rax, -0x30(%r15)
leaq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x20f0
movq 0x28(%r12), %rax
leaq -0x3f8(%rbp), %rsi
movq %rax, 0x30(%rsi)
leaq 0x38(%r13), %r14
movq %r14, %rdi
callq 0x3efa
movq 0x28(%r13), %rax
movq %r13, %rbx
movq 0x50(%r13), %r13
subq 0x20(%rbx), %rax
sarq $0x3, %rax
subq %r13, %rax
cmpq 0x60(%rbx), %rax
movq -0x30(%rbp), %r15
jbe 0x2d4e
movq %r14, -0x40(%rbp)
leaq -0x1a0(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x2100
movq 0x38(%rbx), %r12
movq %rbx, -0x38(%rbp)
movq 0x40(%rbx), %rax
subq %r12, %rax
sarq $0x3, %rax
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
cmpq %rax, %r13
je 0x2845
leaq -0x68(%rbp), %r14
imulq $0xc8, %r13, %rbx
addq $0x8, %rbx
leaq -0x80(%rbp), %r15
movq (%r12,%rbx), %rax
movq %rax, -0x80(%rbp)
movq %r14, -0x78(%rbp)
movq 0x8(%r12,%rbx), %rsi
movq 0x10(%r12,%rbx), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x4420
movq 0x28(%r12,%rbx), %rax
movq %rax, -0x58(%rbp)
leaq -0x1a0(%rbp), %rdi
movq %r15, %rsi
callq 0x6952
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x2815
callq 0x21c0
incq %r13
movq -0x38(%rbp), %rax
movq 0x38(%rax), %r12
movq 0x40(%rax), %rax
subq %r12, %rax
sarq $0x3, %rax
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
addq $0xc8, %rbx
cmpq %rax, %r13
jne 0x27cd
leaq -0x1a0(%rbp), %rdi
callq 0x6984
leaq -0x518(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x3f36
movq -0x38(%rbp), %r13
movq -0x48(%rbp), %r15
leaq -0x330(%rbp), %r12
leaq -0x518(%rbp), %rsi
movq %r12, %rdi
callq 0x400c
movq -0x4a0(%rbp), %rdi
testq %rdi, %rdi
je 0x2893
callq 0x21c0
movq -0x4b8(%rbp), %rdi
testq %rdi, %rdi
je 0x28a4
callq 0x21c0
leaq -0x4d8(%rbp), %r14
movq %r14, %rdi
callq 0x46c4
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x28cd
leaq -0x4f8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x508(%rbp), %rax
testq %rax, %rax
je 0x28ea
leaq -0x518(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x38(%r13), %r14
imulq $0xc8, 0x50(%r13), %rbx
leaq -0x320(%rbp), %rsi
movb -0x10(%rsi), %al
leaq (%r14,%rbx), %rdi
addq $0x10, %rdi
movb %al, -0x10(%rdi)
movq -0x8(%rsi), %rax
movq %rax, -0x8(%rdi)
callq 0x20f0
addq %rbx, %r14
leaq -0x2f8(%rbp), %rbx
movq -0x8(%rbx), %rax
movq %rax, 0x30(%r14)
leaq 0x38(%r14), %rdi
movq %rbx, %rsi
callq 0x4852
leaq 0x58(%r14), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x4852
leaq 0x78(%r14), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x48c6
movq -0x2a0(%rbp), %rax
movq %rax, 0x90(%r14)
movl $0x98, %esi
leaq (%r14,%rsi), %rdi
addq %r12, %rsi
callq 0x49e0
movl $0xb0, %eax
addq %rax, %r14
addq %rax, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x4ac6
movq 0x50(%r13), %rsi
incq %rsi
movq -0x40(%rbp), %rdi
callq 0x40ca
movq 0x50(%r13), %rsi
incq %rsi
movq %r15, %rdi
callq 0x4112
movq 0x58(%r13), %rax
movq 0x20(%r13), %rcx
movq 0x50(%r13), %rdx
movq %rax, (%rcx,%rdx,8)
movq 0x50(%r13), %rax
incq %rax
movq %rax, 0x50(%r13)
cmpq 0x68(%r13), %rax
movq -0x30(%rbp), %r15
jbe 0x2c69
leaq -0x110(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x2100
leaq -0x268(%rbp), %rdi
movq %r13, %rsi
callq 0x2eda
leaq -0x110(%rbp), %rdi
leaq -0x268(%rbp), %r14
movq %r14, %rsi
callq 0x414a
movq 0x78(%r14), %rdi
testq %rdi, %rdi
je 0x2a19
callq 0x21c0
movq -0x208(%rbp), %rdi
testq %rdi, %rdi
je 0x2a2a
callq 0x21c0
leaq -0x228(%rbp), %r14
movq %r14, %rdi
callq 0x46c4
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2a53
leaq -0x248(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x258(%rbp), %rax
testq %rax, %rax
movq -0x40(%rbp), %r14
je 0x2a74
leaq -0x268(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl $0x1, %esi
movq %r14, %rdi
callq 0x40ca
leaq -0x488(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3f36
leaq -0x268(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x400c
movq (%r14), %r15
leaq -0x258(%rbp), %r14
movb -0x10(%r14), %al
movb %al, (%r15)
movq -0x8(%r14), %rax
movq %rax, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq %r14, %rsi
callq 0x2220
movq 0x20(%r14), %rax
movq %rax, 0x30(%r15)
addq $0x38, %r15
leaq -0x230(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x414a
movq 0x78(%r14), %rdi
testq %rdi, %rdi
je 0x2af8
callq 0x21c0
movq -0x1d0(%rbp), %rdi
testq %rdi, %rdi
je 0x2b09
callq 0x21c0
movq %rbx, %r12
leaq -0x1f0(%rbp), %r15
movq %r15, %rdi
callq 0x46c4
movq -0x10(%r15), %rax
testq %rax, %rax
je 0x2b35
leaq -0x210(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x220(%rbp), %rax
testq %rax, %rax
movq -0x30(%rbp), %r15
movq -0x48(%rbp), %rbx
je 0x2b56
movq %r14, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq *%rax
leaq -0x248(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b6b
callq 0x21c0
movq -0x410(%rbp), %rdi
testq %rdi, %rdi
je 0x2b7c
callq 0x21c0
movq -0x428(%rbp), %rdi
testq %rdi, %rdi
je 0x2b8d
callq 0x21c0
leaq -0x448(%rbp), %r14
movq %r14, %rdi
callq 0x46c4
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2bb6
leaq -0x468(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x478(%rbp), %rax
testq %rax, %rax
je 0x2bd3
leaq -0x488(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq $0x1, 0x50(%r13)
movq -0xb8(%rbp), %rax
movq %rax, 0x58(%r13)
movl $0x1, %esi
movq %rbx, %rdi
callq 0x4112
movq %r12, %rbx
movq 0x20(%r13), %rax
movq 0x58(%r13), %rcx
movq %rcx, (%rax)
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x2c12
callq 0x21c0
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x2c23
callq 0x21c0
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
callq 0x46c4
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2c4c
leaq -0xf0(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x100(%rbp), %rax
testq %rax, %rax
je 0x2c69
leaq -0x110(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x280(%rbp), %rdi
testq %rdi, %rdi
je 0x2c7a
callq 0x21c0
movq -0x298(%rbp), %rdi
testq %rdi, %rdi
je 0x2c8b
callq 0x21c0
leaq -0x2b8(%rbp), %rdi
callq 0x46c4
movq -0x2c8(%rbp), %rax
testq %rax, %rax
je 0x2cb4
leaq -0x2d8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x2e8(%rbp), %rax
testq %rax, %rax
je 0x2ccd
movq %rbx, %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq *%rax
leaq -0x310(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ce2
callq 0x21c0
movq -0x128(%rbp), %rdi
testq %rdi, %rdi
je 0x2cf3
callq 0x21c0
movq -0x140(%rbp), %rdi
testq %rdi, %rdi
je 0x2d04
callq 0x21c0
leaq -0x160(%rbp), %r14
movq %r14, %rdi
callq 0x46c4
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2d2d
leaq -0x180(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x190(%rbp), %rax
testq %rax, %rax
je 0x2d4a
leaq -0x1a0(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x38(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sdq 0x58(%rbx), %xmm0
leaq -0x330(%rbp), %rsi
movq $0x0, (%rsi)
movsd %xmm0, 0x8(%rsi)
movq $0x2a, 0x10(%rsi)
movq %rbx, %rdi
callq 0x42c4
movq -0x348(%rbp), %rdi
testq %rdi, %rdi
je 0x2d8b
callq 0x21c0
movq -0x360(%rbp), %rdi
testq %rdi, %rdi
je 0x2d9c
callq 0x21c0
leaq -0x380(%rbp), %rbx
movq %rbx, %rdi
callq 0x46c4
movq -0x10(%rbx), %rax
testq %rax, %rax
je 0x2dc5
leaq -0x3a0(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x3b0(%rbp), %rax
testq %rax, %rax
je 0x2de2
leaq -0x3c0(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x3e8(%rbp), %rdi
leaq -0x3d8(%rbp), %rax
cmpq %rax, %rdi
je 0x2dfa
callq 0x21c0
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
cvtsi2sdq -0x50(%rbp), %xmm1
divsd %xmm1, %xmm0
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdx
callq 0x52a6
jmp 0x26ec
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
movq %rax, %rbx
leaq -0x488(%rbp), %rdi
callq 0x405e
jmp 0x2e5f
jmp 0x2e5c
jmp 0x2e5c
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x405e
jmp 0x2e96
movq %rax, %rbx
leaq -0x518(%rbp), %rdi
callq 0x405e
jmp 0x2eba
jmp 0x2ea4
jmp 0x2ea4
jmp 0x2e84
movq %rax, %rdi
callq 0x4411
jmp 0x2e8e
movq %rax, %rbx
jmp 0x2ec6
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
callq 0x423c
jmp 0x2eba
movq %rax, %rbx
jmp 0x2eba
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x2eba
callq 0x21c0
leaq -0x1a0(%rbp), %rdi
callq 0x405e
leaq -0x3f8(%rbp), %rdi
callq 0x423c
movq %rbx, %rdi
callq 0x22b0