// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x700, %rsp            # imm = 0x700
leaq 0x7204(%rip), %rdi      # 0xe1d6
leaq 0xd367(%rip), %rsi      # 0x14340
movb $0x0, %al
callq 0x3060
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movl %eax, %edi
callq 0x3270
leaq 0xd349(%rip), %rdi      # 0x14340
leaq 0x7063(%rip), %rsi      # 0xe061
callq 0x3330
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x7026
leaq 0x704f(%rip), %rdi      # 0xe064
movb $0x0, %al
callq 0x3060
movl $0x1, %edi
callq 0x3350
jmp 0x7028
movq -0x8(%rbp), %rdi
callq 0x3430
cmpl $0x0, %eax
je 0x703b
jmp 0x734a
movq -0x8(%rbp), %rdi
leaq 0x71b9(%rip), %rsi      # 0xe1ff
xorl %eax, %eax
leaq -0x70(%rbp), %rdx
movq %rdx, -0x6a0(%rbp)
leaq -0xe0(%rbp), %rcx
callq 0x3520
leaq -0x101(%rbp), %rdi
movq %rdi, -0x698(%rbp)
callq 0x34e0
movq -0x6a0(%rbp), %rsi
movq -0x698(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0x8780
jmp 0x708e
leaq -0x101(%rbp), %rdi
callq 0x32d0
leaq -0x139(%rbp), %rdi
movq %rdi, -0x6a8(%rbp)
callq 0x34e0
movq -0x6a8(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x8780
jmp 0x70c9
leaq -0x139(%rbp), %rdi
callq 0x32d0
cmpl $0x1, 0xd4a0(%rip)      # 0x1457c
jne 0x717d
leaq 0xd4cf(%rip), %rdi      # 0x145b8
leaq -0x100(%rbp), %rsi
callq 0x8a50
movb %dl, -0x6b1(%rbp)
movq %rax, -0x6b0(%rbp)
jmp 0x7104
movb -0x6b1(%rbp), %al
movq -0x6b0(%rbp), %rcx
movq %rcx, -0x150(%rbp)
movb %al, -0x148(%rbp)
jmp 0x717d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x101(%rbp), %rdi
callq 0x32d0
jmp 0x7778
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x139(%rbp), %rdi
callq 0x32d0
jmp 0x7339
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x732d
cmpl $0x2, 0xd3f8(%rip)      # 0x1457c
jne 0x71c2
leaq 0xd45b(%rip), %rdi      # 0x145e8
leaq -0x138(%rbp), %rsi
callq 0x8a50
movb %dl, -0x6c1(%rbp)
movq %rax, -0x6c0(%rbp)
jmp 0x71a8
movb -0x6c1(%rbp), %al
movq -0x6c0(%rbp), %rcx
movq %rcx, -0x160(%rbp)
movb %al, -0x158(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3120
jmp 0x71d7
leaq -0x1a0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x3120
jmp 0x71ec
leaq 0xd38d(%rip), %rdi      # 0x14580
leaq -0x180(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0x6780
jmp 0x7208
leaq -0x1a0(%rbp), %rdi
callq 0x3190
leaq -0x180(%rbp), %rdi
callq 0x3190
cmpl $0x0, 0xd0f5(%rip)      # 0x1431c
je 0x7310
leaq -0x1c0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x3120
jmp 0x7242
leaq -0x1e0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3120
jmp 0x7257
leaq 0xd322(%rip), %rdi      # 0x14580
leaq -0x1c0(%rbp), %rsi
leaq -0x1e0(%rbp), %rdx
callq 0x6780
jmp 0x7273
leaq -0x1e0(%rbp), %rdi
callq 0x3190
leaq -0x1c0(%rbp), %rdi
callq 0x3190
jmp 0x7310
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x72c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3190
leaq -0x180(%rbp), %rdi
callq 0x3190
jmp 0x732d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x7302
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3190
leaq -0x1c0(%rbp), %rdi
callq 0x3190
jmp 0x732d
leaq -0x138(%rbp), %rdi
callq 0x3190
leaq -0x100(%rbp), %rdi
callq 0x3190
jmp 0x7028
leaq -0x138(%rbp), %rdi
callq 0x3190
leaq -0x100(%rbp), %rdi
callq 0x3190
jmp 0x7778
movq -0x8(%rbp), %rdi
callq 0x3280
cmpl $0x1, 0xd222(%rip)      # 0x1457c
jne 0x7379
leaq 0xd255(%rip), %rdi      # 0x145b8
callq 0x8aa0
movq %rax, %rsi
leaq 0x6e94(%rip), %rdi      # 0xe206
movb $0x0, %al
callq 0x3060
cmpl $0x2, 0xd1fc(%rip)      # 0x1457c
jne 0x739f
leaq 0xd25f(%rip), %rdi      # 0x145e8
callq 0x8aa0
movq %rax, %rsi
leaq 0x6e83(%rip), %rdi      # 0xe21b
movb $0x0, %al
callq 0x3060
leaq -0x221(%rbp), %rdi
movq %rdi, -0x6d0(%rbp)
callq 0x34e0
movq -0x6d0(%rbp), %rdx
leaq 0xcf80(%rip), %rsi      # 0x14340
leaq -0x220(%rbp), %rdi
callq 0x8780
jmp 0x73ce
leaq 0x6dc0(%rip), %rsi      # 0xe195
leaq -0x220(%rbp), %rdi
callq 0x3540
movq %rax, -0x6d8(%rbp)
jmp 0x73ea
movq -0x6d8(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x3120
jmp 0x73ff
leaq -0x220(%rbp), %rdi
callq 0x3190
leaq -0x221(%rbp), %rdi
callq 0x32d0
movslq 0xced2(%rip), %rdi      # 0x142f0
shlq $0x3, %rdi
callq 0x33c0
movq %rax, -0x230(%rbp)
movl $0x0, -0x234(%rbp)
movl -0x234(%rbp), %eax
cmpl 0xceac(%rip), %eax      # 0x142f0
jge 0x74ca
movq -0x230(%rbp), %rdi
movslq -0x234(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movslq -0x234(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0xa11(%rip), %rdx      # 0x6a60
callq 0x3510
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
jmp 0x7438
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x74b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3190
leaq -0x221(%rbp), %rdi
callq 0x32d0
jmp 0x7778
movl $0x0, -0x238(%rbp)
movl -0x238(%rbp), %eax
cmpl 0xce10(%rip), %eax      # 0x142f0
jge 0x7529
movq -0x230(%rbp), %rax
movslq -0x238(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3240
jmp 0x74ff
jmp 0x7501
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x74d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x776c
leaq -0x200(%rbp), %rdi
callq 0x3110
movq %rax, %rsi
leaq 0x6cf2(%rip), %rdi      # 0xe231
xorl %eax, %eax
callq 0x3060
jmp 0x7548
leaq -0x438(%rbp), %rdi
leaq -0x200(%rbp), %rsi
movl $0x4, %edx
callq 0x3550
jmp 0x7562
movl $0x0, -0x43c(%rbp)
movl -0x43c(%rbp), %eax
cmpl 0xcd78(%rip), %eax      # 0x142f0
jge 0x7702
leaq -0x669(%rbp), %rdi
movq %rdi, -0x6e0(%rbp)
callq 0x34e0
movq -0x6e0(%rbp), %rdx
leaq 0xcda1(%rip), %rsi      # 0x14340
leaq -0x668(%rbp), %rdi
callq 0x8780
jmp 0x75ad
leaq 0x6be1(%rip), %rsi      # 0xe195
leaq -0x668(%rbp), %rdi
callq 0x3540
movq %rax, -0x6e8(%rbp)
jmp 0x75c9
movslq -0x43c(%rbp), %rsi
leaq -0x690(%rbp), %rdi
callq 0x8830
jmp 0x75de
movq -0x6e8(%rbp), %rdi
leaq -0x690(%rbp), %rsi
callq 0x3570
movq %rax, -0x6f0(%rbp)
jmp 0x75fa
movq -0x6f0(%rbp), %rsi
leaq -0x648(%rbp), %rdi
movl $0x4, %edx
callq 0x3470
jmp 0x7614
leaq -0x690(%rbp), %rdi
callq 0x3190
leaq -0x668(%rbp), %rdi
callq 0x3190
leaq -0x669(%rbp), %rdi
callq 0x32d0
leaq -0x648(%rbp), %rdi
callq 0x3460
movq %rax, -0x6f8(%rbp)
jmp 0x764d
movq -0x6f8(%rbp), %rsi
leaq -0x438(%rbp), %rdi
callq 0x30b0
jmp 0x7662
leaq -0x648(%rbp), %rdi
callq 0x30c0
movl -0x43c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x43c(%rbp)
jmp 0x756c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x76d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x76c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x690(%rbp), %rdi
callq 0x3190
leaq -0x668(%rbp), %rdi
callq 0x3190
leaq -0x669(%rbp), %rdi
callq 0x32d0
jmp 0x7760
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x648(%rbp), %rdi
callq 0x30c0
jmp 0x7760
leaq 0x7343(%rip), %rdi      # 0xea4c
xorl %eax, %eax
callq 0x3060
jmp 0x7712
leaq -0x200(%rbp), %rdi
callq 0x3110
movq %rax, %rsi
leaq 0xcc18(%rip), %rdi      # 0x14340
callq 0x3260
leaq -0x438(%rbp), %rdi
callq 0x3410
leaq -0x200(%rbp), %rdi
callq 0x3190
addq $0x700, %rsp            # imm = 0x700
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x3410
leaq -0x200(%rbp), %rdi
callq 0x3190
movq -0x110(%rbp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)