// File: 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
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl $0x0, -0x4(%rbp)
movb $0x0, -0xd(%rbp)
movb -0xd(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2bf1
jmp 0x2c3e
movq 0x123d8(%rip), %rdi     # 0x14fd0
leaq 0xa411(%rip), %rsi      # 0xd010
callq 0x2190
movq 0x123d5(%rip), %rdi     # 0x14fe0
leaq -0xc(%rbp), %rsi
callq 0x20f0
cmpl $0x14, -0xc(%rbp)
jl 0x2c29
cmpl $0x2710, -0xc(%rbp)     # imm = 0x2710
jg 0x2c29
movb $0x1, -0xd(%rbp)
jmp 0x2c3c
movq 0x123a0(%rip), %rdi     # 0x14fd0
leaq 0xa417(%rip), %rsi      # 0xd04e
callq 0x2190
jmp 0x2be6
movl -0xc(%rbp), %edi
callq 0x3620
callq 0x2040
cvttsd2si %xmm0, %eax
movl %eax, -0x8(%rbp)
movq 0x12377(%rip), %rdi     # 0x14fd0
leaq 0xa45a(%rip), %rsi      # 0xd0ba
callq 0x2190
movq %rax, %rdi
movl -0x8(%rbp), %esi
callq 0x2280
movq %rax, %rdi
leaq 0xa50d(%rip), %rsi      # 0xd187
callq 0x2190
movq 0x1234a(%rip), %rdi     # 0x14fd0
leaq 0xa443(%rip), %rsi      # 0xd0d0
callq 0x2190
callq 0x2060
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2d29
movl -0x8(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x3640
leaq -0x38(%rbp), %rdi
callq 0x20b0
movq %rax, -0x40(%rbp)
leaq 0xa43d(%rip), %rax      # 0xd101
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0xa42e(%rip), %rax      # 0xd105
movq %rax, -0x70(%rbp)
leaq 0xa423(%rip), %rax      # 0xd105
movq %rax, -0x68(%rbp)
leaq 0xa41a(%rip), %rax      # 0xd107
movq %rax, -0x60(%rbp)
leaq 0xa411(%rip), %rax      # 0xd109
movq %rax, -0x58(%rbp)
leaq 0xa408(%rip), %rax      # 0xd10b
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x80(%rbp), %rsi
leaq 0xa3e7(%rip), %rdi      # 0xd101
callq 0x2160
movl $0x7f, %edi
callq 0x2210
movl -0x8(%rbp), %esi
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3760
movq -0x118(%rbp), %rdi
movl $0x1, %esi
callq 0x38f0
jmp 0x2d52
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x3a60
jmp 0x2d6a
callq 0x2070
movl -0x8(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0xb8(%rbp)
callq 0x2070
movl -0x8(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0xbc(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x3af0
movq %rax, -0x120(%rbp)
jmp 0x2da8
movq -0x120(%rbp), %rax
movq %rax, -0xb4(%rbp)
callq 0x2070
movl -0x8(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0xc8(%rbp)
callq 0x2070
movl -0x8(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0xcc(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x3af0
movq %rax, -0x128(%rbp)
jmp 0x2df4
movq -0x128(%rbp), %rax
movq %rax, -0xc4(%rbp)
movq 0x121c7(%rip), %rdi     # 0x14fd0
leaq 0xa2fe(%rip), %rsi      # 0xd10e
callq 0x2190
jmp 0x2e17
movq 0x121b2(%rip), %rdi     # 0x14fd0
leaq 0xa30a(%rip), %rsi      # 0xd12f
callq 0x2190
movq %rax, -0x130(%rbp)
jmp 0x2e33
movq -0x130(%rbp), %rdi
leaq 0xa33d(%rip), %rsi      # 0xd17e
callq 0x2190
movq %rax, -0x138(%rbp)
jmp 0x2e4f
movq -0x138(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0x2280
movq %rax, -0x140(%rbp)
jmp 0x2e6a
movq -0x140(%rbp), %rdi
leaq 0xa2f7(%rip), %rsi      # 0xd16f
callq 0x2190
movq %rax, -0x148(%rbp)
jmp 0x2e86
movq -0x148(%rbp), %rdi
movl -0xb0(%rbp), %esi
callq 0x2280
movq %rax, -0x150(%rbp)
jmp 0x2ea1
movq -0x150(%rbp), %rdi
leaq 0xa2c3(%rip), %rsi      # 0xd172
callq 0x2190
movq %rax, -0x158(%rbp)
jmp 0x2ebd
movq -0x158(%rbp), %rdi
movl -0xc4(%rbp), %esi
callq 0x2280
movq %rax, -0x160(%rbp)
jmp 0x2ed8
movq -0x160(%rbp), %rdi
leaq 0xa289(%rip), %rsi      # 0xd16f
callq 0x2190
movq %rax, -0x168(%rbp)
jmp 0x2ef4
movq -0x168(%rbp), %rdi
movl -0xc0(%rbp), %esi
callq 0x2280
movq %rax, -0x170(%rbp)
jmp 0x2f0f
movq -0x170(%rbp), %rdi
leaq 0xa263(%rip), %rsi      # 0xd180
callq 0x2190
jmp 0x2f24
movq -0xb4(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc4(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x2410
movl %eax, -0x174(%rbp)
jmp 0x2f62
movl -0x174(%rbp), %eax
movl %eax, -0xd0(%rbp)
movq 0x1205b(%rip), %rdi     # 0x14fd0
leaq 0xa20d(%rip), %rsi      # 0xd189
callq 0x2190
movq %rax, -0x180(%rbp)
jmp 0x2f8a
movq -0x180(%rbp), %rdi
movl -0xd0(%rbp), %esi
callq 0x2280
movq %rax, -0x188(%rbp)
jmp 0x2fa5
movq -0x188(%rbp), %rdi
leaq 0xa20d(%rip), %rsi      # 0xd1c0
callq 0x2190
jmp 0x2fba
movq -0xb4(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xc4(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x29a0
movl %eax, -0x18c(%rbp)
jmp 0x2ff8
movl -0x18c(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq 0x11fc5(%rip), %rdi     # 0x14fd0
leaq 0xa1b7(%rip), %rsi      # 0xd1c9
callq 0x2190
movq %rax, -0x198(%rbp)
jmp 0x3020
movq -0x198(%rbp), %rdi
movl -0xe4(%rbp), %esi
callq 0x2280
movq %rax, -0x1a0(%rbp)
jmp 0x303b
movq -0x1a0(%rbp), %rdi
leaq 0xa177(%rip), %rsi      # 0xd1c0
callq 0x2190
jmp 0x3050
movq -0xb4(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0xc4(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rsi
movq -0x110(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x2a90
movl %eax, -0x1a4(%rbp)
jmp 0x308e
movl -0x1a4(%rbp), %eax
movl %eax, -0xfc(%rbp)
movq 0x11f2f(%rip), %rdi     # 0x14fd0
leaq 0xa137(%rip), %rsi      # 0xd1df
callq 0x2190
movq %rax, -0x1b0(%rbp)
jmp 0x30b6
movq -0x1b0(%rbp), %rdi
movl -0xfc(%rbp), %esi
callq 0x2280
movq %rax, -0x1b8(%rbp)
jmp 0x30d1
movq -0x1b8(%rbp), %rdi
leaq 0xa0e1(%rip), %rsi      # 0xd1c0
callq 0x2190
jmp 0x30e6
movq 0x11ee3(%rip), %rdi     # 0x14fd0
leaq 0xa110(%rip), %rsi      # 0xd204
callq 0x2190
jmp 0x30fb
movl -0x14(%rbp), %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x2130
jmp 0x3109
leaq -0xa0(%rbp), %rdi
callq 0x3b20
jmp 0x3137
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3b20
jmp 0x3142
xorl %eax, %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x22a0
nop