// File: /workspace/github_cpp_makefile_star2_O3/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 0x10ef2
movslq 0x88(%rbx), %rax
leal -0x1(,%rax,2), %edi
testq %rax, %rax
jle 0x10b9f
cmpl $0x2, %edi
movl $0x1, %ecx
cmovgel %edi, %ecx
movq (%r14), %rdx
shlq $0x5, %rcx
xorl %esi, %esi
movabsq $0x38d7ea4c68000, %r8   # imm = 0x38D7EA4C68000
movq $-0x1, (%rdx,%rsi)
movl $0xffffffff, 0x8(%rdx,%rsi) # imm = 0xFFFFFFFF
movq %r8, 0x10(%rdx,%rsi)
movb $0x0, 0x18(%rdx,%rsi)
addq $0x20, %rsi
cmpq %rsi, %rcx
jne 0x10b55
testl %eax, %eax
jle 0x10b9f
movq (%r15), %rcx
movq (%r14), %rdx
leaq (,%rax,8), %rsi
xorl %r8d, %r8d
movq (%rcx,%r8), %r9
movq %r9, 0x10(%rdx,%r8,4)
addq $0x8, %r8
cmpq %r8, %rsi
jne 0x10b8d
cmpl %edi, %eax
jge 0x10c4e
leaq 0x20(%rsp), %rcx
leal -0x1(%rax), %esi
movq (%r14), %rdx
movslq %edi, %rdi
movq %rsp, %r8
movq %rax, %r9
movl %eax, %r10d
movq (%r14), %r11
movb $0x1, %bpl
movq %rcx, %r15
testl %esi, %esi
js 0x10bec
movl %esi, %r12d
shlq $0x5, %r12
movq 0x10(%r11,%r12), %r12
movslq %r10d, %r13
shlq $0x5, %r13
cmpq 0x10(%r11,%r13), %r12
jge 0x10bec
movl %esi, %r12d
decl %esi
jmp 0x10bf2
movl %r10d, %r12d
incl %r10d
movl %r12d, (%r15)
movq %r8, %r15
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x10bc7
movslq 0x20(%rsp), %r11
movq %r9, %r15
shlq $0x5, %r15
movl %r11d, 0x4(%rdx,%r15)
movslq (%rsp), %r12
movl %r12d, 0x8(%rdx,%r15)
shlq $0x5, %r11
shlq $0x5, %r12
movq 0x10(%rdx,%r12), %r13
addq 0x10(%rdx,%r11), %r13
movq %r13, 0x10(%rdx,%r15)
movl %r9d, (%rdx,%r11)
movl %r9d, (%rdx,%r12)
movb $0x1, 0x18(%rdx,%r12)
incq %r9
cmpq %rdi, %r9
jne 0x10bbe
testl %eax, %eax
jle 0x10d68
leaq 0xc8(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0xe0(%rbx), %rax
movq %rax, 0x48(%rsp)
movq %rsp, %r13
leaq 0x20(%rsp), %rbp
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq (%r14), %rax
movq %r15, %rcx
shlq $0x5, %rcx
movl (%rax,%rcx), %eax
cmpl $-0x1, %eax
je 0x10d0e
movq %r15, %r12
subl 0x88(%rbx), %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x10cd6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x10ce3
movq %r13, %rdi
leaq 0x1c(%rsp), %rdx
callq 0xb082
movq (%r14), %rax
shlq $0x5, %r12
movzbl 0x18(%rax,%r12), %esi
movq %rbp, %rdi
callq 0x10f26
movq (%r14), %rax
movslq (%rax,%r12), %r12
movq %r12, %rcx
shlq $0x5, %rcx
movl (%rax,%rcx), %eax
cmpl $-0x1, %eax
jne 0x10cb3
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x10f74
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x10fa0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x10d3f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x10d55
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
incq %r15
movslq 0x88(%rbx), %rax
cmpq %rax, %r15
jl 0x10c79
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10d7b
jmp 0x10d7b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x10d95
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x10dab
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x45b0
nop