// File: /workspace/github_cpp_makefile_star2_O2/roornelas[P]small-world/test_graph.cpp
// Function: main
int main() {

  int side, people;
  bool right_size = false;

  while (!right_size) {
    std::cout << "How many people are in the network? In the range 20 - 10,000\n";
    std::cin >> people;
    if (people >= 20 && people <= 10000) {
      right_size = true;
    } else {
      std::cout << "The number of people has to be in the range 20 - 10,000 so your graph can be built in less than 20 seconds\n";
    }
  }
  side = ceil(sqrt(people));
  std::cout << "Side length of grid: " << side << "\n";
  std::cout << "Building a custom randomized graph just for you\n" ;
  pid_t pid = fork();
  
  if (pid == 0) {
    std::string s = std::to_string(side);
    char *pchar = (char*)s.c_str();
    char *argv[] = {"gui", pchar, "1", "1", "2", "5", "20", NULL};
    execv("gui", argv);
    exit(127);
  }
  else {
    Graph s(side);
    s.set_p(1);
    s.set_q_r(1, 2);

    pair<int, int> start = make_pair(rand() % side, rand() % side);
    pair<int, int> end = make_pair(rand() % side, rand() % side);
    std::cout << "Done! Let us run the algorithms\n" ;
    std::cout << "The number of people it took to transmit a message from person " <<
              "(" << start.first << ", " << start.second << ") to person " "(" << end.first << ", " << end.second << ") is: \n\n" ;
    int bfs = searchBFS(&s, start, end);
    std::cout << "Optimal possible result (Using breadth first search): " << bfs << " steps\n\n";
    int rw = searchRW(&s, start, end);
    std::cout << "Using a Random Walk: " << rw << " steps\n\n";
    int greedy = searchGreedy(&s, start, end);
    std::cout << "Using Kleinberg's simple algorithm: " << greedy << " steps\n\n";

    std::cout << "All tests passed!\n";
    waitpid(pid, 0, 0);
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq 0x584a(%rip), %rbx      # 0x7fd0
leaq 0x2883(%rip), %r14      # 0x5010
movq 0x584c(%rip), %r15      # 0x7fe0
leaq 0xc(%rsp), %r12
leaq 0x28ae(%rip), %r13      # 0x504e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2150
movq %r15, %rdi
movq %r12, %rsi
callq 0x20d0
movl 0xc(%rsp), %eax
addl $-0x14, %eax
cmpl $0x26fd, %eax           # imm = 0x26FD
jb 0x27d1
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2150
jmp 0x27a0
cvtsi2sdl 0xc(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x27e7
sqrtsd %xmm0, %xmm0
jmp 0x27ec
callq 0x20f0
callq 0x2040
cvttsd2si %xmm0, %ebp
movq 0x57d4(%rip), %rbx      # 0x7fd0
leaq 0x28b7(%rip), %rsi      # 0x50ba
movq %rbx, %rdi
callq 0x2150
movq %rax, %rdi
movl %ebp, %esi
callq 0x2220
leaq 0x296b(%rip), %rsi      # 0x5187
movq %rax, %rdi
callq 0x2150
leaq 0x28a5(%rip), %rsi      # 0x50d0
movq %rbx, %rdi
callq 0x2150
callq 0x2050
testl %eax, %eax
je 0x2a36
movl %eax, %ebx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x2b4c
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x2c56
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
callq 0x2d46
callq 0x2060
cltd
idivl %ebp
movl %edx, %r14d
callq 0x2060
cltd
idivl %ebp
movl %edx, %r12d
callq 0x2060
cltd
idivl %ebp
movl %edx, %r15d
callq 0x2060
cltd
idivl %ebp
movl %edx, %r13d
movq 0x5731(%rip), %rdi      # 0x7fd0
leaq 0x2868(%rip), %rsi      # 0x510e
callq 0x2150
movq 0x571e(%rip), %rdi      # 0x7fd0
leaq 0x2876(%rip), %rsi      # 0x512f
callq 0x2150
leaq 0x28b9(%rip), %rsi      # 0x517e
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl %r14d, %esi
callq 0x2220
leaq 0x2890(%rip), %rsi      # 0x516f
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl %r12d, %esi
callq 0x2220
leaq 0x2879(%rip), %rsi      # 0x5172
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl %r15d, %esi
callq 0x2220
leaq 0x285c(%rip), %rsi      # 0x516f
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl %r13d, %esi
callq 0x2220
leaq 0x2853(%rip), %rsi      # 0x5180
movq %rax, %rdi
callq 0x2150
shlq $0x20, %r12
orq %r12, %r14
shlq $0x20, %r13
orq %r13, %r15
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x237c
movl %eax, %ebp
movq 0x5674(%rip), %rdi      # 0x7fd0
leaq 0x2826(%rip), %rsi      # 0x5189
callq 0x2150
movq %rax, %rdi
movl %ebp, %esi
callq 0x2220
leaq 0x2847(%rip), %rsi      # 0x51c0
movq %rax, %rdi
callq 0x2150
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2611
movl %eax, %ebp
movq 0x5636(%rip), %rdi      # 0x7fd0
leaq 0x2828(%rip), %rsi      # 0x51c9
callq 0x2150
movq %rax, %rdi
movl %ebp, %esi
callq 0x2220
leaq 0x2809(%rip), %rsi      # 0x51c0
movq %rax, %rdi
callq 0x2150
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x26ae
movl %eax, %ebp
movq 0x55f8(%rip), %rdi      # 0x7fd0
leaq 0x2800(%rip), %rsi      # 0x51df
callq 0x2150
movq %rax, %rdi
movl %ebp, %esi
callq 0x2220
leaq 0x27cb(%rip), %rsi      # 0x51c0
movq %rax, %rdi
callq 0x2150
movq 0x55cc(%rip), %rdi      # 0x7fd0
leaq 0x27f9(%rip), %rsi      # 0x5204
callq 0x2150
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2100
leaq 0x10(%rsp), %rdi
callq 0x2dc0
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2af2
movq (%rbx), %rax
leaq 0x26b2(%rip), %rdi      # 0x5101
leaq 0x10(%rsp), %rsi
movq %rdi, (%rsi)
movq %rax, 0x8(%rsi)
leaq 0x26a3(%rip), %rax      # 0x5105
movq %rax, 0x10(%rsi)
movq %rax, 0x18(%rsi)
leaq 0x2696(%rip), %rax      # 0x5107
movq %rax, 0x20(%rsi)
leaq 0x268d(%rip), %rax      # 0x5109
movq %rax, 0x28(%rsi)
leaq 0x2684(%rip), %rax      # 0x510b
movq %rax, 0x30(%rsi)
andq $0x0, 0x38(%rsi)
callq 0x2120
pushq $0x7f
popq %rdi
callq 0x21b0
jmp 0x2aa5
jmp 0x2aa5
jmp 0x2aa5
jmp 0x2aa5
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2dc0
movq %rbx, %rdi
callq 0x2240