// File: cegme[P]vose/VoseTree.cc
// Function: VoseTree::histogram[abi:cxx11](VoseTree, long)
std::map<std::string, double> 
    VoseTree::histogram(VoseTree tree, long samples) {

    std::map<std::string,double> histogram;
    long hist_sum = 0L;
    for (int i = 0; i != samples; ++i) {
      auto idx = tree.rand_marble();

      if (histogram.find(idx.label) != histogram.end()) {
        histogram[idx.label] += 1.0;
        hist_sum += 1L;
      }
      else {
        histogram.insert(std::make_pair(idx.label, 1.0));
        hist_sum += 1L;
      }
    }
    
    std::map<std::string,double> new_hist;
    std::for_each(histogram.cbegin(), histogram.cend(),
      [&new_hist,hist_sum] (std::pair<const std::string, double> a) {
        //std::cerr << a.first << ", " << (double)a.second/hist_sum << "\n";
        new_hist.insert( std::make_pair(a.first,(double)a.second/hist_sum));
    });

    return new_hist;

  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rsi, -0x138(%rbp)
movq %rdi, -0x130(%rbp)
movq %rdi, %rax
movq %rax, -0x128(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4fd0
movq $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x3a6b
movq -0x138(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x2f00
jmp 0x38ea
leaq -0x80(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x5320
movq %rax, -0x140(%rbp)
jmp 0x3900
movq -0x140(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5350
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x52f0
testb $0x1, %al
jne 0x3937
jmp 0x39a3
leaq -0x80(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x5380
movq %rax, -0x148(%rbp)
jmp 0x394d
movq -0x148(%rbp), %rax
movsd 0x186ac(%rip), %xmm0    # 0x1c008
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x3a40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x3b68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x3a5a
leaq -0x80(%rbp), %rsi
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x54a0
jmp 0x39cd
leaq -0x48(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5460
movb %dl, -0x151(%rbp)
movq %rax, -0x150(%rbp)
jmp 0x39ec
movb -0x151(%rbp), %al
movq -0x150(%rbp), %rcx
movq %rcx, -0xe8(%rbp)
movb %al, -0xe0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x54e0
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x3a40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x54e0
jmp 0x3a5a
leaq -0x88(%rbp), %rdi
callq 0x4200
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x38c7
leaq -0x88(%rbp), %rdi
callq 0x4200
jmp 0x3b68
movq -0x130(%rbp), %rdi
movb $0x0, -0xe9(%rbp)
callq 0x4fd0
leaq -0x48(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x5140
movq -0x170(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x5170
movq %rax, %rcx
movq -0x130(%rbp), %rax
movq %rcx, -0x100(%rbp)
movq %rax, -0x110(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0x110(%rbp), %rdx
movq -0x108(%rbp), %rcx
callq 0x3b80
movq %rdx, -0x168(%rbp)
movq %rax, -0x160(%rbp)
jmp 0x3af5
movq -0x168(%rbp), %rax
movq -0x160(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movq %rax, -0x118(%rbp)
movb $0x1, -0xe9(%rbp)
testb $0x1, -0xe9(%rbp)
jne 0x3b4f
jmp 0x3b43
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
callq 0x5050
jmp 0x3b68
movq -0x130(%rbp), %rdi
callq 0x5050
leaq -0x48(%rbp), %rdi
callq 0x5050
movq -0x128(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x5050
movq -0x90(%rbp), %rdi
callq 0x22f0
nopl (%rax)