// File: pollo[P]graph-partitioning/graph_partitioning.cpp
// Function: main
int main(int argc, char** argv)
{
  Graph graph;

  if (argc != 4)
  {
    printf("Invalid number of parameters\n");
    printf("Usage: %s <dataset name> <heuristic names> <partitions number>\n",
           argv[0]);
    exit(1);
  }

  if (strncmp(argv[1],"slashdot",8) == 0)
    snap_loader(&graph, SLASHDOT_FILE);
  else if (strncmp(argv[1],"amazon",6) == 0) {
    snap_loader(&graph, AMAZON_FILE);
  }
  else if (strncmp(argv[1],"livejournal",11) == 0)
    snap_loader(&graph, LIVEJOURNAL_FILE);
  else if (strncmp(argv[1],"facebook",8) == 0)
    snap_loader(&graph, FACEBOOK_FILE);
  else if (strncmp(argv[1],"4elt",4) == 0)
    elt_loader(&graph);
  else if (strncmp(argv[1],"twitter",7) == 0)
    twitter_loader(&graph);
  else if (strncmp(argv[1],"pre.amazon",11) == 0) {
    preprocessed_loader(&graph, AMAZON_FILE);
  }
  else
  {
    printf("Invalid dataset name %s\n",argv[1]);
    exit(1);
  }

  int partitions_number = strtol(argv[3], NULL, 10);
  if (partitions_number < 1 || partitions_number > MAX_PARTITIONS)
  {
    printf("Invalid partition number %s\n",argv[3]);
    exit(1);
  }

  bool heuristics_valid = false;
  if (strstr(argv[2],"LDG") != NULL)
  {
    run_heuristic("LDG",partitions_number,argv[1],graph);
    heuristics_valid = true;
  }

  if (strstr(argv[2],"FENNEL") != NULL)
  {
    run_heuristic("FENNEL",partitions_number,argv[1],graph);
    heuristics_valid = true;
  }

  if (strstr(argv[2],"NNEIGHBORS") != NULL)
  {
    run_heuristic("NNEIGHBORS",partitions_number,argv[1],graph);
    heuristics_valid = true;
  }

  if (!heuristics_valid)
  {
    printf("Invalid heuristic name %s\n",argv[2]);
    exit(1);
  }

  return 0;
}

// Assembly:
subq $0x58, %rsp
movl $0x0, 0x54(%rsp)
movl %edi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x29e0
cmpl $0x4, 0x50(%rsp)
je 0x2675
leaq 0x9aa4(%rip), %rdi      # 0xc0d1
xorl %eax, %eax
callq 0x2030
jmp 0x2636
movq 0x48(%rsp), %rax
movq (%rax), %rsi
leaq 0x9aaa(%rip), %rdi      # 0xc0ef
xorl %eax, %eax
callq 0x2030
jmp 0x264e
movl $0x1, %edi
callq 0x21d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2a10
jmp 0x296a
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9aaa(%rip), %rsi      # 0xc12f
movl $0x8, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x26ac
leaq 0x9a9d(%rip), %rsi      # 0xc138
leaq 0x20(%rsp), %rdi
callq 0x7b90
jmp 0x26a7
jmp 0x2811
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9b11(%rip), %rsi      # 0xc1cd
movl $0x6, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x26e3
leaq 0x9a83(%rip), %rsi      # 0xc155
leaq 0x20(%rsp), %rdi
callq 0x7b90
jmp 0x26de
jmp 0x280f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9a79(%rip), %rsi      # 0xc16c
movl $0xb, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x271a
leaq 0x9a6f(%rip), %rsi      # 0xc178
leaq 0x20(%rsp), %rdi
callq 0x7b90
jmp 0x2715
jmp 0x280d
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9a6b(%rip), %rsi      # 0xc195
movl $0x8, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x2751
leaq 0x9a5e(%rip), %rsi      # 0xc19e
leaq 0x20(%rsp), %rdi
callq 0x7b90
jmp 0x274c
jmp 0x280b
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9a5b(%rip), %rsi      # 0xc1bc
movl $0x4, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x2781
leaq 0x20(%rsp), %rdi
callq 0x7de0
jmp 0x277c
jmp 0x2809
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9a30(%rip), %rsi      # 0xc1c1
movl $0x7, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x27ae
leaq 0x20(%rsp), %rdi
callq 0x8010
jmp 0x27ac
jmp 0x2807
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9a0b(%rip), %rsi      # 0xc1c9
movl $0xb, %edx
callq 0x20c0
cmpl $0x0, %eax
jne 0x27e2
leaq 0x9981(%rip), %rsi      # 0xc155
leaq 0x20(%rsp), %rdi
callq 0x7cc0
jmp 0x27e0
jmp 0x2805
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x99e2(%rip), %rdi      # 0xc1d4
xorl %eax, %eax
callq 0x2030
jmp 0x27fb
movl $0x1, %edi
callq 0x21d0
jmp 0x2807
jmp 0x2809
jmp 0x280b
jmp 0x280d
jmp 0x280f
jmp 0x2811
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2200
movl %eax, 0x10(%rsp)
cmpl $0x1, 0x10(%rsp)
jl 0x283d
cmpl $0x2710, 0x10(%rsp)     # imm = 0x2710
jle 0x2860
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x99a0(%rip), %rdi      # 0xc1ed
xorl %eax, %eax
callq 0x2030
jmp 0x2856
movl $0x1, %edi
callq 0x21d0
movb $0x0, 0xf(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x978f(%rip), %rsi      # 0xc004
callq 0x2060
cmpq $0x0, %rax
je 0x28a5
movl 0x10(%rsp), %esi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x9770(%rip), %rdi      # 0xc004
leaq 0x20(%rsp), %rcx
callq 0x23a0
jmp 0x28a0
movb $0x1, 0xf(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9753(%rip), %rsi      # 0xc008
callq 0x2060
cmpq $0x0, %rax
je 0x28e5
movl 0x10(%rsp), %esi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x9734(%rip), %rdi      # 0xc008
leaq 0x20(%rsp), %rcx
callq 0x23a0
jmp 0x28e0
movb $0x1, 0xf(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x971a(%rip), %rsi      # 0xc00f
callq 0x2060
cmpq $0x0, %rax
je 0x2925
movl 0x10(%rsp), %esi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x96fb(%rip), %rdi      # 0xc00f
leaq 0x20(%rsp), %rcx
callq 0x23a0
jmp 0x2920
movb $0x1, 0xf(%rsp)
testb $0x1, 0xf(%rsp)
jne 0x294f
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x96de(%rip), %rdi      # 0xc01a
xorl %eax, %eax
callq 0x2030
jmp 0x2945
movl $0x1, %edi
callq 0x21d0
movl $0x0, 0x54(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2a10
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x2270
nopw %cs:(%rax,%rax)
nop