// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xf8(%rdi), %r14
movslq 0x88(%rdi), %rax
leaq -0x1(,%rax,2), %rsi
movq %r14, %rdi
callq 0xea6a
movl 0x88(%rbx), %eax
movslq %eax, %rcx
leaq -0x1(,%rcx,2), %rdx
movq 0xf8(%rbx), %rsi
xorl %edi, %edi
testl %edx, %edx
movl $0x0, %r8d
cmovgl %edx, %r8d
shlq $0x5, %r8
movabsq $0x38d7ea4c68000, %r9   # imm = 0x38D7EA4C68000
cmpq %rdi, %r8
je 0xe72d
orq $-0x1, (%rsi,%rdi)
orl $-0x1, 0x8(%rsi,%rdi)
movq %r9, 0x10(%rsi,%rdi)
movb $0x0, 0x18(%rsi,%rdi)
addq $0x20, %rdi
jmp 0xe70e
movq (%r15), %rsi
movq (%r14), %rdi
xorl %r8d, %r8d
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
shlq $0x3, %r9
cmpq %r8, %r9
je 0xe75a
movq (%rsi,%r8), %r10
movq %r10, 0x10(%rdi,%r8,4)
addq $0x8, %r8
jmp 0xe746
leal -0x1(%rax), %edi
movq (%r14), %rsi
movl %eax, %r8d
cmpq %rdx, %rcx
jge 0xe7f5
movq (%r14), %r9
xorl %r10d, %r10d
cmpq $0x2, %r10
je 0xe7ad
testl %edi, %edi
js 0xe79d
movl %edi, %r11d
shlq $0x5, %r11
movq 0x10(%r9,%r11), %r11
movslq %r8d, %r15
shlq $0x5, %r15
cmpq 0x10(%r9,%r15), %r11
jge 0xe79d
movl %edi, %r11d
decl %edi
jmp 0xe7a3
movl %r8d, %r11d
incl %r8d
movl %r11d, 0x18(%rsp,%r10,4)
incq %r10
jmp 0xe772
movslq 0x18(%rsp), %r9
movq %rcx, %r10
shlq $0x5, %r10
movl %r9d, 0x4(%rsi,%r10)
movslq 0x1c(%rsp), %r11
movl %r11d, 0x8(%rsi,%r10)
shlq $0x5, %r9
shlq $0x5, %r11
movq 0x10(%rsi,%r11), %r15
addq 0x10(%rsi,%r9), %r15
movq %r15, 0x10(%rsi,%r10)
movl %ecx, (%rsi,%r9)
movl %ecx, (%rsi,%r11)
movb $0x1, 0x18(%rsi,%r11)
incq %rcx
jmp 0xe763
leaq 0xc8(%rbx), %rcx
movq %rcx, 0x10(%rsp)
leaq 0xe0(%rbx), %rcx
movq %rcx, 0x8(%rsp)
xorl %ecx, %ecx
leaq 0x40(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x4(%rsp), %r15
cmpl %eax, %ecx
jge 0xe8cf
andq $0x0, 0x50(%rsp)
andq $0x0, 0x18(%rsp)
andl $0x0, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
andl $0x0, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq (%r14), %rax
movl %ecx, (%rsp)
movslq %ecx, %r12
shlq $0x5, %r12
movl (%rax,%r12), %eax
cmpl $-0x1, %eax
je 0xe895
subl 0x88(%rbx), %eax
movl %eax, 0x4(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x9292
movq (%r14), %rax
movzbl 0x18(%rax,%r12), %esi
movq %rbp, %rdi
callq 0xea9e
movq (%r14), %rax
movl (%rax,%r12), %ecx
jmp 0xe856
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xeadc
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0xeb08
movq %rbp, %rdi
callq 0x896e
movq %r13, %rdi
callq 0x8c0e
movl (%rsp), %ecx
incl %ecx
movl 0x88(%rbx), %eax
jmp 0xe81e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe8e2
jmp 0xe8e2
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x896e
leaq 0x40(%rsp), %rdi
callq 0x8c0e
movq %rbx, %rdi
callq 0x45d0
nop