// File: /workspace/github_cpp_makefile_star2_O1/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 0x10eda
movslq 0x88(%rbx), %rax
leal -0x1(,%rax,2), %esi
testq %rax, %rax
jle 0x10b3e
cmpl $0x2, %esi
movl $0x1, %ecx
cmovgel %esi, %ecx
movq (%r14), %rdx
shlq $0x5, %rcx
xorl %edi, %edi
movabsq $0x38d7ea4c68000, %r8   # imm = 0x38D7EA4C68000
movq $-0x1, (%rdx,%rdi)
movl $0xffffffff, 0x8(%rdx,%rdi) # imm = 0xFFFFFFFF
movq %r8, 0x10(%rdx,%rdi)
movb $0x0, 0x18(%rdx,%rdi)
addq $0x20, %rdi
cmpq %rdi, %rcx
jne 0x10b1b
testl %eax, %eax
jle 0x10b65
movq (%r15), %rcx
movq (%r14), %rdx
leaq (,%rax,8), %rdi
xorl %r8d, %r8d
movq (%rcx,%r8), %r9
movq %r9, 0x10(%rdx,%r8,4)
addq $0x8, %r8
cmpq %r8, %rdi
jne 0x10b53
cmpl %esi, %eax
jge 0x10c00
leal -0x1(%rax), %edx
movq (%r14), %rcx
movslq %esi, %rsi
movl %eax, %edi
movq (%r14), %r8
xorl %r9d, %r9d
testl %edx, %edx
js 0x10ba3
movl %edx, %r10d
shlq $0x5, %r10
movq 0x10(%r8,%r10), %r10
movslq %edi, %r11
shlq $0x5, %r11
cmpq 0x10(%r8,%r11), %r10
jge 0x10ba3
movl %edx, %r10d
decl %edx
jmp 0x10ba8
movl %edi, %r10d
incl %edi
movl %r10d, (%rsp,%r9,4)
incq %r9
cmpq $0x1, %r9
je 0x10b7e
movslq (%rsp), %r8
movq %rax, %r9
shlq $0x5, %r9
movl %r8d, 0x4(%rcx,%r9)
movslq 0x4(%rsp), %r10
movl %r10d, 0x8(%rcx,%r9)
shlq $0x5, %r8
shlq $0x5, %r10
movq 0x10(%rcx,%r10), %r11
addq 0x10(%rcx,%r8), %r11
movq %r11, 0x10(%rcx,%r9)
movl %eax, (%rcx,%r8)
movl %eax, (%rcx,%r10)
movb $0x1, 0x18(%rcx,%r10)
incq %rax
cmpq %rsi, %rax
jne 0x10b78
cmpl $0x0, 0x88(%rbx)
jle 0x10d3e
leaq 0xc8(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0xe0(%rbx), %rax
movq %rax, 0x48(%rsp)
xorl %r12d, %r12d
movq %rsp, %rbp
xorl %r13d, %r13d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %r12, 0x40(%rsp)
movq %r12, (%rsp)
movl %r12d, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movl %r12d, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq (%r14), %rax
movq %r13, %rcx
shlq $0x5, %rcx
cmpl $-0x1, (%rax,%rcx)
je 0x10cca
addq %rcx, %rax
movq %r13, %r15
movl (%rax), %eax
subl 0x88(%rbx), %eax
movl %eax, 0x2c(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x10c8e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x10c9d
leaq 0x30(%rsp), %rdi
leaq 0x2c(%rsp), %rdx
callq 0xb088
movq (%r14), %rax
shlq $0x5, %r15
movzbl 0x18(%rax,%r15), %esi
movq %rbp, %rdi
callq 0x10f0e
movq (%r14), %rcx
movslq (%rcx,%r15), %r15
movq %r15, %rdx
shlq $0x5, %rdx
leaq (%rcx,%rdx), %rax
cmpl $-0x1, (%rcx,%rdx)
jne 0x10c69
movq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x10f5c
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x10f88
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x10d14
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %r12, (%rsp)
movl %r12d, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movl %r12d, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10d2b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
incq %r13
movslq 0x88(%rbx), %rax
cmpq %rax, %r13
jl 0x10c2e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10d51
jmp 0x10d51
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x10d82
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
xorl %eax, %eax
movq %rax, (%rsp)
movl %eax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10d99
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x45b0
nop