// File: /workspace/github_c_makefile_star2_O3/Leeheng86[P]word2vec/word2vec.c
// Function: RandomWalk()
void RandomWalk() {
  printf("Starting random walk using edge file %s\n", train_file);
  srand((unsigned)time(NULL));
  //std::unordered_map<std::string, std::vector<std::string> > umap;
  FILE *fin;
  fin = fopen(train_file, "rb");
  if (fin == NULL) {
    printf("ERROR: training data file not found!\n");
    exit(1);
  }
  // Create Graph
  // Single thread since std::unordered_map is not thread safe on writing
  while (1) {
    if (feof(fin)) break;
    char ca[MAX_STRING], cb[MAX_STRING];
    fscanf(fin, "%s %s\n", ca, cb);
    std::string a(ca);
    std::string b(cb);

    // remember the original position
    if (discard == 1) {
      left_node.insert(a);
    }
    if (discard == 2) {
      right_node.insert(b);
    }

    addLink(umap, a, b);
    if (undirected) addLink(umap, b, a);
  }
  fclose(fin);
  if (discard == 1) {
    printf("# of left node: %lu\n", left_node.size());
  }
  if (discard == 2) {
    printf("# of right node: %lu\n", right_node.size());
  }

  // Random Walk
  std::string new_train_file = std::string(train_file).append("_walks");

  pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
  for (int a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, RandomWalkThread, (void *)(long long)a);
  for (int a = 0; a < num_threads; a++) pthread_join(pt[a], NULL);

  printf("Loaded and preprocessed threads produced edge file, save all walks to file %s\n", new_train_file.c_str());
  std::ofstream of_walks(new_train_file, std::ios_base::binary);
  for (int a = 0; a < num_threads; a++) {
    std::ifstream if_a(std::string(train_file).append("_walks").append(std::to_string((long long)a)), std::ios_base::binary);
    of_walks << if_a.rdbuf();
  }

  printf("\n");
  strcpy(train_file, new_train_file.c_str());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
leaq 0x21ac(%rip), %rdi      # 0x71eb
leaq 0x627a(%rip), %rbx      # 0xb2c0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
xorl %edi, %edi
callq 0x21f0
movl %eax, %edi
callq 0x2210
leaq 0x206c(%rip), %rsi      # 0x70d1
movq %rbx, %rdi
callq 0x22a0
testq %rax, %rax
je 0x561f
movq %rax, %r14
movq %rax, %rdi
callq 0x2370
testl %eax, %eax
jne 0x52e2
leaq 0xe0(%rsp), %r12
leaq 0x2f0(%rsp), %r13
leaq 0xc0(%rsp), %rbp
leaq 0xa0(%rsp), %r15
movq %r14, %rdi
leaq 0x2161(%rip), %rsi      # 0x7214
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2440
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
callq 0x2110
leaq (%rsp,%rax), %rdx
addq $0xe0, %rdx
movq %rsp, %rdi
movq %r12, %rsi
callq 0x6bc0
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, %rdi
callq 0x2110
leaq (%rsp,%rax), %rdx
addq $0x2f0, %rdx            # imm = 0x2F0
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x6bc0
movl 0x63e5(%rip), %eax      # 0xb4fc
cmpl $0x1, %eax
jne 0x5131
leaq 0x6415(%rip), %rdi      # 0xb538
movq %rsp, %rsi
callq 0x6c90
movl 0x63cb(%rip), %eax      # 0xb4fc
cmpl $0x2, %eax
jne 0x5147
leaq 0x642b(%rip), %rdi      # 0xb568
leaq 0x20(%rsp), %rsi
callq 0x6c90
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x624e
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x624e
leaq 0x6369(%rip), %rdi      # 0xb500
movq %rbp, %rsi
movq %r15, %rdx
callq 0x496b
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x51c7
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x51ec
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2240
cmpl $0x0, 0x60a1(%rip)      # 0xb294
je 0x529b
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x624e
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x624e
leaq 0x62b3(%rip), %rdi      # 0xb500
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x496b
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x527f
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x529b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x52b7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x52d2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r14, %rdi
callq 0x2370
testl %eax, %eax
je 0x50a9
movq %r14, %rdi
callq 0x2220
movl 0x620c(%rip), %eax      # 0xb4fc
cmpl $0x1, %eax
jne 0x5310
movq 0x6264(%rip), %rsi      # 0xb560
leaq 0x1f18(%rip), %rdi      # 0x721b
xorl %eax, %eax
callq 0x2050
movl 0x61ec(%rip), %eax      # 0xb4fc
cmpl $0x2, %eax
jne 0x532a
movq 0x6274(%rip), %rsi      # 0xb590
leaq 0x1f0d(%rip), %rdi      # 0x7230
xorl %eax, %eax
callq 0x2050
leaq 0xf0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x5f83(%rip), %r14      # 0xb2c0
movq %r14, %rdi
callq 0x2110
leaq (%rax,%r14), %rdx
leaq 0xe0(%rsp), %rdi
movq %r14, %rsi
callq 0x6bc0
leaq 0x1e4a(%rip), %rsi      # 0x71aa
leaq 0xe0(%rsp), %rdi
callq 0x2460
movq %rsp, %rdi
leaq 0x10(%rsp), %rcx
movq %rcx, (%rdi)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x624e
movq 0xe0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x53a4
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x2240
movslq 0x5ebd(%rip), %r14      # 0xb268
leaq (,%r14,8), %rdi
callq 0x2300
testq %r14, %r14
jle 0x5411
movq %rax, %rbx
xorl %r14d, %r14d
leaq -0x895(%rip), %r15      # 0x4b35
movq %rax, %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2430
incq %r14
movslq 0x5e81(%rip), %rax      # 0xb268
addq $0x8, %r12
cmpq %rax, %r14
jl 0x53cd
testl %eax, %eax
jle 0x5411
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
xorl %esi, %esi
callq 0x21e0
incq %r14
movslq 0x5e5c(%rip), %rax      # 0xb268
cmpq %rax, %r14
jl 0x53f7
movq %rsp, %rbx
movq (%rbx), %rsi
leaq 0x1e28(%rip), %rdi      # 0x7246
xorl %eax, %eax
callq 0x2050
leaq 0x2f0(%rsp), %rdi
movq %rbx, %rsi
movl $0x4, %edx
callq 0x2470
cmpl $0x0, 0x5e27(%rip)      # 0xb268
jle 0x55a0
leaq 0x30(%rsp), %r12
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbp
leaq 0xe0(%rsp), %r14
movq %r12, 0x20(%rsp)
leaq 0x5e58(%rip), %r13      # 0xb2c0
movq %r13, %rdi
callq 0x2110
leaq (%rax,%r13), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x6bc0
movq %rbp, %rbx
movq %rbp, %rdi
leaq 0x1d1e(%rip), %rsi      # 0x71aa
callq 0x2460
movq %rax, %r13
movl $0x1, %ebp
cmpq $0xa, %r15
jb 0x54ee
movl $0x4, %ebp
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x54e7
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x54ec
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x54ee
movq %rcx, %rax
movabsq $0x346dc5d63886594b, %rdx # imm = 0x346DC5D63886594B
mulq %rdx
shrq $0xb, %rdx
addl $0x4, %ebp
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x54a7
addl $-0x3, %ebp
jmp 0x54ee
addl $-0x2, %ebp
jmp 0x54ee
decl %ebp
movl %ebp, %esi
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x2d, %edx
callq 0x2280
movq 0x40(%rsp), %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x61d2
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r13, %rdi
callq 0x20d0
movq %r14, %rdi
movq %rax, %rsi
movl $0x4, %edx
callq 0x23a0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
movq %rbx, %rbp
je 0x5559
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x5570
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x2f0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x2090
movq %r14, %rdi
callq 0x20a0
incq %r15
movslq 0x5cd1(%rip), %rax      # 0xb268
cmpq %rax, %r15
jl 0x545c
movl $0xa, %edi
callq 0x2310
movq (%rsp), %rsi
leaq 0x5d0b(%rip), %rdi      # 0xb2c0
callq 0x2200
movq 0x5a1f(%rip), %rax      # 0xafe0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x2f8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x2f0(%rsp,%rcx)
callq 0x21b0
leaq 0x3e8(%rsp), %rdi
callq 0x20e0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x560d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1daa(%rip), %rdi      # 0x73d0
callq 0x2360
movl $0x1, %edi
callq 0x22c0
jmp 0x5702
jmp 0x56a4
movq %rax, %r15
movq 0xe0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x57a7
movq 0xf0(%rsp), %rsi
jmp 0x579f
movq %rax, %r15
jmp 0x568a
movq %rax, %r15
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x568a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x572b
movq 0x70(%rsp), %rsi
jmp 0x56f8
movq %rax, %r15
jmp 0x57a7
jmp 0x5702
movq %rax, %r15
jmp 0x56db
movq %rax, %r15
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x56db
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x572b
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x572b
movq %rax, %r15
jmp 0x578c
movq %rax, %r15
jmp 0x577f
jmp 0x5711
movq %rax, %r15
jmp 0x5768
movq %rax, %r15
leaq 0xe0(%rsp), %rdi
callq 0x20a0
jmp 0x577f
movq %rax, %r15
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x578c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x578c
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x5768
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x577f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x2f0(%rsp), %rdi
callq 0x2350
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x57a7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r15, %rdi
callq 0x23f0