// File: epfml[P]Bi-Sent2Vec/src/model.cc
// Function: fasttext::Model::buildTree(std::vector<long, std::allocator<long>> const&)
void Model::buildTree(const std::vector<int64_t>& counts) {
  tree.resize(2 * osz_ - 1);
  for (int32_t i = 0; i < 2 * osz_ - 1; i++) {
    tree[i].parent = -1;
    tree[i].left = -1;
    tree[i].right = -1;
    tree[i].count = 1e15;
    tree[i].binary = false;
  }
  for (int32_t i = 0; i < osz_; i++) {
    tree[i].count = counts[i];
  }
  int32_t leaf = osz_ - 1;
  int32_t node = osz_;
  for (int32_t i = osz_; i < 2 * osz_ - 1; i++) {
    int32_t mini[2];
    for (int32_t j = 0; j < 2; j++) {
      if (leaf >= 0 && tree[leaf].count < tree[node].count) {
        mini[j] = leaf--;
      } else {
        mini[j] = node++;
      }
    }
    tree[i].left = mini[0];
    tree[i].right = mini[1];
    tree[i].count = tree[mini[0]].count + tree[mini[1]].count;
    tree[mini[0]].parent = i;
    tree[mini[1]].parent = i;
    tree[mini[1]].binary = true;
  }
  for (int32_t i = 0; i < osz_; i++) {
    std::vector<int32_t> path;
    std::vector<bool> code;
    int32_t j = i;
    while (tree[j].parent != -1) {
      path.push_back(tree[j].parent - osz_);
      code.push_back(tree[j].binary);
      j = tree[j].parent;
    }
    paths.push_back(path);
    codes.push_back(code);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rax, %rdi
addq $0xf8, %rdi
movl 0x88(%rax), %eax
shll %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x23db0
movl $0x0, -0x14(%rbp)
movq -0x98(%rbp), %rcx
movl -0x14(%rbp), %eax
movl 0x88(%rcx), %ecx
shll %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x23186
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
addq $0xf8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
addq $0xf8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
addq $0xf8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movabsq $0x38d7ea4c68000, %rcx  # imm = 0x38D7EA4C68000
movq %rcx, 0x10(%rax)
addq $0xf8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x23e40
movb $0x0, 0x18(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x230c2
movl $0x0, -0x18(%rbp)
movq -0x98(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x88(%rcx), %eax
jge 0x231e3
movq -0x10(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x23d90
movq -0x98(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
addq $0xf8, %rdi
movslq -0x18(%rbp), %rsi
callq 0x23e40
movq -0xa0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2318d
movq -0x98(%rbp), %rax
movl 0x88(%rax), %ecx
subl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movl 0x88(%rax), %ecx
movl %ecx, -0x20(%rbp)
movl 0x88(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x98(%rbp), %rcx
movl -0x24(%rbp), %eax
movl 0x88(%rcx), %ecx
shll %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x233f8
movl $0x0, -0x30(%rbp)
cmpl $0x2, -0x30(%rbp)
jge 0x232bd
cmpl $0x0, -0x1c(%rbp)
jl 0x2329a
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
addq $0xf8, %rdi
movslq -0x20(%rbp), %rsi
callq 0x23e40
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq 0x10(%rcx), %rax
jge 0x2329a
movl -0x1c(%rbp), %ecx
movl %ecx, %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movslq -0x30(%rbp), %rax
movl %ecx, -0x2c(%rbp,%rax,4)
jmp 0x232ad
movl -0x20(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movslq -0x30(%rbp), %rax
movl %ecx, -0x2c(%rbp,%rax,4)
jmp 0x232af
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2322c
movq -0x98(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0xc8(%rbp)
addq $0xf8, %rdi
movslq -0x24(%rbp), %rsi
callq 0x23e40
movl -0xc8(%rbp), %ecx
movq -0x98(%rbp), %rdi
movl %ecx, 0x4(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0xc4(%rbp)
addq $0xf8, %rdi
movslq -0x24(%rbp), %rsi
callq 0x23e40
movl -0xc4(%rbp), %ecx
movq -0x98(%rbp), %rdi
movl %ecx, 0x8(%rax)
addq $0xf8, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movq 0x10(%rax), %rax
movq %rax, -0xc0(%rbp)
addq $0xf8, %rdi
movslq -0x28(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movq -0xc0(%rbp), %rax
addq 0x10(%rcx), %rax
movq %rax, -0xb8(%rbp)
addq $0xf8, %rdi
movslq -0x24(%rbp), %rsi
callq 0x23e40
movq -0xb8(%rbp), %rcx
movq -0x98(%rbp), %rdi
movq %rcx, 0x10(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0xb0(%rbp)
addq $0xf8, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x23e40
movl -0xb0(%rbp), %ecx
movq -0x98(%rbp), %rdi
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0xac(%rbp)
addq $0xf8, %rdi
movslq -0x28(%rbp), %rsi
callq 0x23e40
movl -0xac(%rbp), %ecx
movq -0x98(%rbp), %rdi
movl %ecx, (%rax)
addq $0xf8, %rdi
movslq -0x28(%rbp), %rsi
callq 0x23e40
movb $0x1, 0x18(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x23208
movl $0x0, -0x34(%rbp)
movq -0x98(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x88(%rcx), %eax
jge 0x23549
leaq -0x50(%rbp), %rdi
callq 0xe440
leaq -0x78(%rbp), %rdi
callq 0xedd0
movl -0x34(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x7c(%rbp), %rsi
callq 0x23e40
cmpl $-0x1, (%rax)
je 0x234f7
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x7c(%rbp), %rsi
callq 0x23e40
movq -0x98(%rbp), %rcx
movl (%rax), %eax
movl 0x88(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x80(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xe6b0
jmp 0x23487
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x7c(%rbp), %rsi
callq 0x23e40
movzbl 0x18(%rax), %esi
andl $0x1, %esi
leaq -0x78(%rbp), %rdi
callq 0x23e60
jmp 0x234b0
movq -0x98(%rbp), %rdi
addq $0xf8, %rdi
movslq -0x7c(%rbp), %rsi
callq 0x23e40
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
jmp 0x2342d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xf050
leaq -0x50(%rbp), %rdi
callq 0xe530
jmp 0x23552
movq -0x98(%rbp), %rdi
addq $0xc8, %rdi
leaq -0x50(%rbp), %rsi
callq 0x23f30
jmp 0x23510
movq -0x98(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x78(%rbp), %rsi
callq 0x23fa0
jmp 0x23529
leaq -0x78(%rbp), %rdi
callq 0xf050
leaq -0x50(%rbp), %rdi
callq 0xe530
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x233ff
addq $0xd0, %rsp
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x57a0
nop