// File: /workspace/github_c_makefile_star2_O1/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 0x2425(%rip), %rdi      # 0x719f
leaq 0x653f(%rip), %rbx      # 0xb2c0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
xorl %edi, %edi
callq 0x21f0
movl %eax, %edi
callq 0x2210
leaq 0x22e5(%rip), %rsi      # 0x7085
movq %rbx, %rdi
callq 0x22a0
testq %rax, %rax
je 0x5357
movq %rax, %r14
movq %rax, %rdi
callq 0x2370
testl %eax, %eax
jne 0x5019
leaq 0xe0(%rsp), %r12
leaq 0x2f0(%rsp), %r13
leaq 0xc0(%rsp), %rbp
leaq 0xa0(%rsp), %r15
movq %r14, %rdi
leaq 0x23da(%rip), %rsi      # 0x71c8
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 0x6910
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 0x6910
cmpl $0x1, 0x66a9(%rip)      # 0xb4fc
jne 0x4e64
leaq 0x66dc(%rip), %rdi      # 0xb538
movq %rsp, %rsi
callq 0x69da
cmpl $0x2, 0x6691(%rip)      # 0xb4fc
jne 0x4e7e
leaq 0x66f4(%rip), %rdi      # 0xb568
leaq 0x20(%rsp), %rsi
callq 0x69da
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x5f62
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x5f62
leaq 0x6632(%rip), %rdi      # 0xb500
movq %rbp, %rsi
movq %r15, %rdx
callq 0x46c1
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x4efe
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x4f23
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2240
cmpl $0x0, 0x636a(%rip)      # 0xb294
je 0x4fd2
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x5f62
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 0x5f62
leaq 0x657c(%rip), %rdi      # 0xb500
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x46c1
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x4fb6
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x4fd2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x4fee
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5009
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r14, %rdi
callq 0x2370
testl %eax, %eax
je 0x4de4
movq %r14, %rdi
callq 0x2220
cmpl $0x1, 0x64d4(%rip)      # 0xb4fc
jne 0x503f
movq 0x652f(%rip), %rsi      # 0xb560
leaq 0x2197(%rip), %rdi      # 0x71cf
xorl %eax, %eax
callq 0x2050
cmpl $0x2, 0x64b6(%rip)      # 0xb4fc
jne 0x505d
movq 0x6541(%rip), %rsi      # 0xb590
leaq 0x218e(%rip), %rdi      # 0x71e4
xorl %eax, %eax
callq 0x2050
leaq 0xf0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x6250(%rip), %r14      # 0xb2c0
movq %r14, %rdi
callq 0x2110
leaq (%rax,%r14), %rdx
leaq 0xe0(%rsp), %rdi
movq %r14, %rsi
callq 0x6910
leaq 0x20cb(%rip), %rsi      # 0x715e
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 0x5f62
movq 0xe0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x50d7
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x2240
movslq 0x618a(%rip), %r14      # 0xb268
leaq (,%r14,8), %rdi
callq 0x2300
movq %rax, %rbx
testq %r14, %r14
jle 0x5123
xorl %r14d, %r14d
leaq -0x877(%rip), %r15      # 0x4886
movq %rbx, %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2430
incq %r14
movslq 0x614e(%rip), %rax      # 0xb268
addq $0x8, %r12
cmpq %rax, %r14
jl 0x5100
cmpl $0x0, 0x613e(%rip)      # 0xb268
jle 0x5149
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
xorl %esi, %esi
callq 0x21e0
incq %r14
movslq 0x6124(%rip), %rax      # 0xb268
cmpq %rax, %r14
jl 0x512f
movq %rsp, %rbx
movq (%rbx), %rsi
leaq 0x20a4(%rip), %rdi      # 0x71fa
xorl %eax, %eax
callq 0x2050
leaq 0x2f0(%rsp), %rdi
movq %rbx, %rsi
movl $0x4, %edx
callq 0x2470
cmpl $0x0, 0x60ef(%rip)      # 0xb268
jle 0x52d8
leaq 0x30(%rsp), %r12
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbp
leaq 0xe0(%rsp), %r14
movq %r12, 0x20(%rsp)
leaq 0x6120(%rip), %r13      # 0xb2c0
movq %r13, %rdi
callq 0x2110
leaq (%rax,%r13), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x6910
movq %rbp, %rbx
movq %rbp, %rdi
leaq 0x1f9a(%rip), %rsi      # 0x715e
callq 0x2460
movq %rax, %r13
movl $0x1, %ebp
cmpq $0xa, %r15
jb 0x5226
movl $0x4, %ebp
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x521f
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x5224
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x5226
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 0x51df
addl $-0x3, %ebp
jmp 0x5226
addl $-0x2, %ebp
jmp 0x5226
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 0x5ee6
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 0x5291
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x52a8
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 0x5f99(%rip), %rax      # 0xb268
cmpq %rax, %r15
jl 0x5194
movl $0xa, %edi
callq 0x2310
movq (%rsp), %rsi
leaq 0x5fd3(%rip), %rdi      # 0xb2c0
callq 0x2200
movq 0x5ce7(%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 0x5345
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 0x2026(%rip), %rdi      # 0x7384
callq 0x2360
movl $0x1, %edi
callq 0x22c0
jmp 0x5458
jmp 0x53dc
movq %rax, %r15
movq 0xe0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x54dc
movq 0xf0(%rsp), %rsi
jmp 0x54d4
movq %rax, %r15
jmp 0x53c2
movq %rax, %r15
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x53c2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x5460
movq 0x70(%rsp), %rsi
jmp 0x5430
movq %rax, %r15
jmp 0x54dc
jmp 0x5458
movq %rax, %r15
jmp 0x5413
movq %rax, %r15
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x5413
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x5460
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x5460
movq %rax, %r15
jmp 0x54b4
jmp 0x5441
movq %rax, %r15
jmp 0x549d
movq %rax, %r15
leaq 0xe0(%rsp), %rdi
callq 0x20a0
jmp 0x54b4
movq %rax, %r15
jmp 0x54c1
movq %rax, %r15
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x54c1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x54c1
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x549d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x54b4
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 0x54dc
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r15, %rdi
callq 0x23f0