// File: /workspace/github_c_makefile_star2_O0/Leeheng86[P]word2vec/word2vec.c
// Function: CreateBinaryTree()
void CreateBinaryTree() {
  long long a, b, i, min1i, min2i, pos1, pos2, point[MAX_CODE_LENGTH];
  char code[MAX_CODE_LENGTH];
  long long *count = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
  long long *binary = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
  long long *parent_node = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
  for (a = 0; a < vocab_size; a++) count[a] = vocab[a].cn;
  for (a = vocab_size; a < vocab_size * 2; a++) count[a] = 1e15;
  pos1 = vocab_size - 1;
  pos2 = vocab_size;
  // Following algorithm constructs the Huffman tree by adding one node at a time
  for (a = 0; a < vocab_size - 1; a++) {
    // First, find two smallest nodes 'min1, min2'
    if (pos1 >= 0) {
      if (count[pos1] < count[pos2]) {
        min1i = pos1;
        pos1--;
      } else {
        min1i = pos2;
        pos2++;
      }
    } else {
      min1i = pos2;
      pos2++;
    }
    if (pos1 >= 0) {
      if (count[pos1] < count[pos2]) {
        min2i = pos1;
        pos1--;
      } else {
        min2i = pos2;
        pos2++;
      }
    } else {
      min2i = pos2;
      pos2++;
    }
    count[vocab_size + a] = count[min1i] + count[min2i];
    parent_node[min1i] = vocab_size + a;
    parent_node[min2i] = vocab_size + a;
    binary[min2i] = 1;
  }
  // Now assign binary code to each vocabulary word
  for (a = 0; a < vocab_size; a++) {
    b = a;
    i = 0;
    while (1) {
      code[i] = binary[b];
      point[i] = b;
      i++;
      b = parent_node[b];
      if (b == vocab_size * 2 - 2) break;
    }
    vocab[a].codelen = i;
    vocab[a].point[0] = vocab_size - 2;
    for (b = 0; b < i; b++) {
      vocab[a].code[i - b - 1] = code[b];
      vocab[a].point[i - b] = point[b] - vocab_size;
    }
  }
  free(count);
  free(binary);
  free(parent_node);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq 0x1051e(%rip), %rdi     # 0x14510
shlq %rdi
addq $0x1, %rdi
movl $0x8, %esi
callq 0x31b0
movq %rax, -0x1b8(%rbp)
movq 0x104ff(%rip), %rdi     # 0x14510
shlq %rdi
addq $0x1, %rdi
movl $0x8, %esi
callq 0x31b0
movq %rax, -0x1c0(%rbp)
movq 0x104e0(%rip), %rdi     # 0x14510
shlq %rdi
addq $0x1, %rdi
movl $0x8, %esi
callq 0x31b0
movq %rax, -0x1c8(%rbp)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq 0x104b5(%rip), %rax     # 0x14510
jge 0x408c
movq 0x10494(%rip), %rax     # 0x144f8
imulq $0x28, -0x8(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x1b8(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x4050
movq 0x1047d(%rip), %rax     # 0x14510
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x1046e(%rip), %rcx     # 0x14510
shlq %rcx
cmpq %rcx, %rax
jge 0x40d1
movq -0x1b8(%rbp), %rax
movq -0x8(%rbp), %rcx
movabsq $0x38d7ea4c68000, %rdx  # imm = 0x38D7EA4C68000
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x4097
movq 0x10438(%rip), %rax     # 0x14510
subq $0x1, %rax
movq %rax, -0x30(%rbp)
movq 0x10429(%rip), %rax     # 0x14510
movq %rax, -0x38(%rbp)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10412(%rip), %rcx     # 0x14510
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x4265
cmpq $0x0, -0x30(%rbp)
jl 0x415e
movq -0x1b8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x1b8(%rbp), %rcx
movq -0x38(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x4148
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x415c
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x4172
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
jl 0x41c5
movq -0x1b8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x1b8(%rbp), %rcx
movq -0x38(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x41af
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x41c3
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x41d9
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x1b8(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x1b8(%rbp), %rax
movq -0x28(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq -0x1b8(%rbp), %rax
movq 0x1030b(%rip), %rcx     # 0x14510
addq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x102fc(%rip), %rdx     # 0x14510
addq -0x8(%rbp), %rdx
movq -0x1c8(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x102e2(%rip), %rdx     # 0x14510
addq -0x8(%rbp), %rdx
movq -0x1c8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x1c0(%rbp), %rax
movq -0x28(%rbp), %rcx
movq $0x1, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x40f3
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq 0x10298(%rip), %rax     # 0x14510
jge 0x43c1
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x1c0(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, -0x1b0(%rbp,%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, -0x180(%rbp,%rax,8)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x1c8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x1022c(%rip), %rcx     # 0x14510
shlq %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
jne 0x42f2
jmp 0x42f4
jmp 0x428e
movq -0x18(%rbp), %rax
movb %al, %cl
movq 0x101f7(%rip), %rax     # 0x144f8
imulq $0x28, -0x8(%rbp), %rdx
addq %rdx, %rax
movb %cl, 0x20(%rax)
movq 0x101fd(%rip), %rax     # 0x14510
subq $0x2, %rax
movl %eax, %ecx
movq 0x101d8(%rip), %rax     # 0x144f8
imulq $0x28, -0x8(%rbp), %rdx
addq %rdx, %rax
movq 0x8(%rax), %rax
movl %ecx, (%rax)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x43ae
movq -0x10(%rbp), %rax
movb -0x1b0(%rbp,%rax), %dl
movq 0x101a6(%rip), %rax     # 0x144f8
imulq $0x28, -0x8(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
subq -0x10(%rbp), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x180(%rbp,%rax,8), %rax
subq 0x10190(%rip), %rax     # 0x14510
movl %eax, %edx
movq 0x1016f(%rip), %rax     # 0x144f8
imulq $0x28, -0x8(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
subq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x4336
jmp 0x43b0
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x426d
movq -0x1b8(%rbp), %rdi
callq 0x3340
movq -0x1c0(%rbp), %rdi
callq 0x3340
movq -0x1c8(%rbp), %rdi
callq 0x3340
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nop