// File: /workspace/github_cpp_makefile_star2_O1/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 $0x508, %rsp            # imm = 0x508
movq %rsi, %r14
movq %rdi, %r12
movq (%rsi), %rcx
movq 0x58(%rdi), %rax
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq %rax, 0x58(%rdi)
addq $0x20, %rdi
movq 0x28(%r12), %rsi
cmpq %rsi, 0x20(%r12)
movq %rdi, -0x40(%rbp)
movq %rcx, -0x50(%rbp)
je 0x26d3
movq -0x8(%rsi), %rax
addq %rcx, %rax
cvtsi2sd %rax, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x410(%rbp)
cmpq 0x30(%r12), %rsi
jne 0x26e1
leaq -0x410(%rbp), %rdx
callq 0x5556
jmp 0x26ed
cmpq 0x30(%r12), %rsi
je 0x3003
movq (%r14), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%r12)
leaq -0x400(%rbp), %r15
leaq -0x3f0(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
xorl %ebx, %ebx
movb %bl, (%rax)
leaq -0x3d8(%rbp), %r13
movl $0x90, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2100
movb %bl, -0x38(%r13)
movq (%r14), %rax
movq %rax, -0x30(%r13)
leaq 0x8(%r14), %rsi
movq %r15, %rdi
callq 0x20f0
movq 0x28(%r14), %rax
leaq -0x410(%rbp), %rsi
movq %rax, 0x30(%rsi)
leaq 0x38(%r12), %rbx
movq %rbx, %rdi
callq 0x4304
movq 0x28(%r12), %rax
movq 0x50(%r12), %r13
subq 0x20(%r12), %rax
sarq $0x3, %rax
subq %r13, %rax
cmpq 0x60(%r12), %rax
jbe 0x2f31
movq %rbx, -0x38(%rbp)
leaq -0x348(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x2100
movq 0x38(%r12), %r15
movq %r12, -0x30(%rbp)
movq 0x40(%r12), %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
cmpq %rax, %r13
je 0x2843
leaq -0x68(%rbp), %r14
imulq $0xc8, %r13, %rbx
addq $0x8, %rbx
leaq -0x80(%rbp), %r12
movq (%r15,%rbx), %rax
movq %rax, -0x80(%rbp)
movq %r14, -0x78(%rbp)
movq 0x8(%r15,%rbx), %rsi
movq 0x10(%r15,%rbx), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x4742
movq 0x28(%r15,%rbx), %rax
movq %rax, -0x58(%rbp)
leaq -0x348(%rbp), %rdi
movq %r12, %rsi
callq 0x6da2
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x2813
callq 0x21c0
incq %r13
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r15
movq 0x40(%rax), %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
addq $0xc8, %rbx
cmpq %rax, %r13
jne 0x27cb
leaq -0x348(%rbp), %rdi
callq 0x6dd4
leaq -0x530(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x4340
movq -0x30(%rbp), %r12
movq -0x40(%rbp), %r13
leaq -0x2b8(%rbp), %r14
leaq -0x530(%rbp), %rsi
movq %r14, %rdi
callq 0x4416
movq -0x4b8(%rbp), %rdi
testq %rdi, %rdi
je 0x2891
callq 0x21c0
movq -0x4d0(%rbp), %rdi
testq %rdi, %rdi
je 0x28a2
callq 0x21c0
leaq -0x4f0(%rbp), %r15
movq %r15, %rdi
callq 0x49e2
movq -0x10(%r15), %rax
testq %rax, %rax
je 0x28cb
leaq -0x510(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x520(%rbp), %rax
testq %rax, %rax
je 0x28e8
leaq -0x530(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x38(%r12), %r15
imulq $0xc8, 0x50(%r12), %rbx
leaq -0x2a8(%rbp), %rsi
movb -0x10(%rsi), %al
leaq (%r15,%rbx), %rdi
addq $0x10, %rdi
movb %al, -0x10(%rdi)
movq -0x8(%rsi), %rax
movq %rax, -0x8(%rdi)
callq 0x20f0
addq %rbx, %r15
leaq -0x280(%rbp), %rbx
movq -0x8(%rbx), %rax
movq %rax, 0x30(%r15)
leaq 0x38(%r15), %rdi
movq %rbx, %rsi
callq 0x4b66
leaq 0x58(%r15), %rdi
leaq -0x260(%rbp), %rsi
callq 0x4b66
leaq 0x78(%r15), %rdi
leaq -0x240(%rbp), %rsi
callq 0x4bda
movq -0x228(%rbp), %rax
movq %rax, 0x90(%r15)
movl $0x98, %esi
leaq (%r15,%rsi), %rdi
addq %r14, %rsi
callq 0x4cf0
movl $0xb0, %eax
addq %rax, %r15
addq %rax, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4dc8
movq 0x50(%r12), %rsi
incq %rsi
movq -0x38(%rbp), %rdi
callq 0x44d4
movq 0x50(%r12), %rsi
incq %rsi
movq %r13, %rdi
callq 0x451c
movq 0x58(%r12), %rax
movq 0x20(%r12), %rcx
movq 0x50(%r12), %rdx
movq %rax, (%rcx,%rdx,8)
movq 0x50(%r12), %rax
incq %rax
movq %rax, 0x50(%r12)
cmpq 0x68(%r12), %rax
jbe 0x2e4c
leaq -0x1d8(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x2100
leaq -0x148(%rbp), %rdi
movq %r12, %rsi
callq 0x30c0
leaq -0x1d8(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x50ba
leaq -0x1b8(%rbp), %r12
leaq -0x128(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x50ba
xorpd %xmm0, %xmm0
leaq -0x1f0(%rbp), %rdi
movapd %xmm0, (%rdi)
movups 0x20(%r12), %xmm0
movq 0x30(%r12), %rax
movups 0x20(%r14), %xmm1
movups %xmm1, 0x20(%r12)
movq 0x30(%r14), %rcx
movq %rcx, 0x30(%r12)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, 0x20(%r14)
xorl %ebx, %ebx
movq %rbx, 0x30(%r14)
callq 0x49e2
movq 0x40(%r12), %rdi
movups 0x38(%r14), %xmm0
movups 0x48(%r14), %xmm1
movups %xmm0, 0x38(%r12)
movups %xmm1, 0x48(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%r14)
movq %rbx, 0x50(%r14)
testq %rdi, %rdi
je 0x2a9e
callq 0x21c0
movq -0x160(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0x160(%rbp)
movupd -0xc8(%rbp), %xmm0
movupd %xmm0, -0x158(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0xd0(%rbp)
movq $0x0, -0xc0(%rbp)
testq %rdi, %rdi
je 0x2ae4
callq 0x21c0
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x2af5
callq 0x21c0
leaq -0x108(%rbp), %r15
movq 0x20(%r15), %rdi
testq %rdi, %rdi
je 0x2b0a
callq 0x21c0
movq %r15, %rdi
callq 0x49e2
movq -0x118(%rbp), %rax
testq %rax, %rax
je 0x2b2b
movq %r14, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq *%rax
movq -0x138(%rbp), %rax
testq %rax, %rax
movq -0x38(%rbp), %rbx
je 0x2b4c
leaq -0x148(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl $0x1, %esi
movq %rbx, %rdi
callq 0x44d4
leaq -0x4a0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x4340
leaq -0x148(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0x4416
movq (%rbx), %r13
leaq -0x138(%rbp), %r15
movb -0x10(%r15), %al
movb %al, (%r13)
movq -0x8(%r15), %rax
movq %rax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x20(%r15), %rax
movq %rax, 0x30(%r13)
leaq 0x38(%r13), %rdi
leaq -0x110(%rbp), %rsi
callq 0x50ba
leaq 0x58(%r13), %rdi
leaq -0xf0(%rbp), %r15
movq %r15, %rsi
callq 0x50ba
xorl %ebx, %ebx
leaq -0x1f0(%rbp), %rdi
movq %rbx, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq 0x78(%r13), %rax
movupd 0x80(%r13), %xmm0
movq 0x20(%r15), %rcx
movq %rcx, 0x78(%r13)
movq 0x28(%r15), %rcx
movq %rcx, 0x80(%r13)
movq 0x30(%r15), %rcx
movq %rcx, 0x88(%r13)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movupd %xmm0, 0x8(%rdi)
movq %rcx, 0x20(%r15)
movq %rdx, 0x28(%r15)
movq %rsi, 0x30(%r15)
callq 0x49e2
movq 0x38(%r15), %rax
movq %rax, 0x90(%r13)
movq 0x98(%r13), %rdi
movq 0x40(%r15), %rax
movq %rax, 0x98(%r13)
movq 0x48(%r15), %rax
movq %rax, 0xa0(%r13)
movq 0x50(%r15), %rax
movq %rax, 0xa8(%r13)
movq %rbx, 0x50(%r15)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%r15)
testq %rdi, %rdi
je 0x2c7f
callq 0x21c0
movq 0xb0(%r13), %rdi
movq -0x98(%rbp), %rax
movq %rax, 0xb0(%r13)
movq -0x90(%rbp), %rax
movq %rax, 0xb8(%r13)
movq -0x88(%rbp), %rax
movq %rax, 0xc0(%r13)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x98(%rbp)
movq $0x0, -0x88(%rbp)
testq %rdi, %rdi
je 0x2cd1
callq 0x21c0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x2ce2
callq 0x21c0
leaq -0xd0(%rbp), %r13
movq 0x20(%r13), %rdi
testq %rdi, %rdi
je 0x2cf7
callq 0x21c0
movq %r13, %rdi
callq 0x49e2
movq -0xe0(%rbp), %rax
testq %rax, %rax
je 0x2d18
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq -0x100(%rbp), %rax
testq %rax, %rax
movq -0x30(%rbp), %rbx
movq -0x40(%rbp), %r15
je 0x2d3d
leaq -0x110(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x2d4e
callq 0x21c0
movq -0x428(%rbp), %rdi
testq %rdi, %rdi
je 0x2d5f
callq 0x21c0
movq -0x440(%rbp), %rdi
testq %rdi, %rdi
je 0x2d70
callq 0x21c0
leaq -0x460(%rbp), %r14
movq %r14, %rdi
callq 0x49e2
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2d99
leaq -0x480(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x490(%rbp), %rax
testq %rax, %rax
je 0x2db6
leaq -0x4a0(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq $0x1, 0x50(%rbx)
movq -0x180(%rbp), %rax
movq %rax, 0x58(%rbx)
movl $0x1, %esi
movq %r15, %rdi
callq 0x451c
movq 0x20(%rbx), %rax
movq 0x58(%rbx), %rcx
movq %rcx, (%rax)
movq -0x160(%rbp), %rdi
testq %rdi, %rdi
je 0x2df2
callq 0x21c0
leaq -0x198(%rbp), %r14
movq 0x20(%r14), %rdi
testq %rdi, %rdi
leaq -0x280(%rbp), %rbx
je 0x2e0e
callq 0x21c0
movq %r14, %rdi
callq 0x49e2
movq -0x1a8(%rbp), %rax
testq %rax, %rax
je 0x2e2f
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
movq -0x1c8(%rbp), %rax
testq %rax, %rax
je 0x2e4c
leaq -0x1d8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x208(%rbp), %rdi
testq %rdi, %rdi
je 0x2e5d
callq 0x21c0
movq -0x220(%rbp), %rdi
testq %rdi, %rdi
je 0x2e6e
callq 0x21c0
leaq -0x240(%rbp), %rdi
callq 0x49e2
movq -0x250(%rbp), %rax
testq %rax, %rax
je 0x2e97
leaq -0x260(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x270(%rbp), %rax
testq %rax, %rax
je 0x2eb0
movq %rbx, %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq *%rax
leaq -0x298(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ec5
callq 0x21c0
movq -0x2d0(%rbp), %rdi
testq %rdi, %rdi
je 0x2ed6
callq 0x21c0
movq -0x2e8(%rbp), %rdi
testq %rdi, %rdi
je 0x2ee7
callq 0x21c0
leaq -0x308(%rbp), %r14
movq %r14, %rdi
callq 0x49e2
movq -0x10(%r14), %rax
testq %rax, %rax
je 0x2f10
leaq -0x328(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x338(%rbp), %rax
testq %rax, %rax
je 0x2f2d
leaq -0x348(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x30(%rbp), %r12
xorps %xmm0, %xmm0
cvtsi2sdq 0x58(%r12), %xmm0
leaq -0x2b8(%rbp), %rsi
movq $0x0, (%rsi)
movsd %xmm0, 0x8(%rsi)
movq $0x2a, 0x10(%rsi)
movq %r12, %rdi
callq 0x45dc
movq -0x360(%rbp), %rdi
testq %rdi, %rdi
je 0x2f6f
callq 0x21c0
movq -0x378(%rbp), %rdi
testq %rdi, %rdi
je 0x2f80
callq 0x21c0
leaq -0x398(%rbp), %rbx
movq %rbx, %rdi
callq 0x49e2
movq -0x10(%rbx), %rax
testq %rax, %rax
je 0x2fa9
leaq -0x3b8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x3c8(%rbp), %rax
testq %rax, %rax
je 0x2fc6
leaq -0x3d8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x400(%rbp), %rdi
leaq -0x3f0(%rbp), %rax
cmpq %rax, %rdi
je 0x2fde
callq 0x21c0
xorps %xmm0, %xmm0
cvtsi2sdq -0x50(%rbp), %xmm0
cvtsi2sdq -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdx
callq 0x5690
jmp 0x26ed
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
movq %rax, %rbx
leaq -0x4a0(%rbp), %rdi
callq 0x4468
jmp 0x3044
jmp 0x3041
jmp 0x3041
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
jmp 0x3069
movq %rax, %rbx
leaq -0x1d8(%rbp), %rdi
callq 0x4468
jmp 0x307b
movq %rax, %rbx
leaq -0x530(%rbp), %rdi
callq 0x4468
jmp 0x309f
jmp 0x3089
jmp 0x3089
jmp 0x3069
movq %rax, %rdi
callq 0x4733
jmp 0x3073
movq %rax, %rbx
jmp 0x30ab
movq %rax, %rbx
leaq -0x2b8(%rbp), %rdi
callq 0x4554
jmp 0x309f
movq %rax, %rbx
jmp 0x309f
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x309f
callq 0x21c0
leaq -0x348(%rbp), %rdi
callq 0x4468
leaq -0x410(%rbp), %rdi
callq 0x4554
movq %rbx, %rdi
callq 0x22b0
nop