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

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

  char output_name[1000];
  if (strncmp(argv[1],"slashdot",8) == 0)
  {
    snap_loader(&graph, SLASHDOT_FILE);
    strcpy(output_name, SLASHDOT_FILE);
  }
  else if (strncmp(argv[1],"amazon",6) == 0)
  {
    snap_loader(&graph, AMAZON_FILE);
    strcpy(output_name, AMAZON_FILE);
  }
  else if (strncmp(argv[1],"4elt",4) == 0)
  {
    elt_loader(&graph);
    strcpy(output_name, ELT_FILE);
  }
  else if (strncmp(argv[1],"twitter",7) == 0)
  {
    twitter_loader(&graph);
    strcpy(output_name, TWITTER_FILE);
  }
  else
  {
    printf("Invalid dataset name %s\n",argv[1]);
    exit(1);
  }
  strcat(output_name, ".preprocessed");

  vector<int> component;
  int largest_component = find_largest_component(component, graph);

  int n,m;
  count_nodes_edges(largest_component, component, graph, &n, &m);;

  printf("Nodes %d, edges %d\n",n,m);

  //assign new id
  vector<int> remap(component.size(), -1);
  int node_id = 0;
  for (size_t i=0; i<component.size(); i++)
  {
    if (component[i] == largest_component)
    {
      remap[i] = node_id;
      node_id ++;
    }
  }

  FILE *fp = fopen(output_name, "w");
  fprintf(fp, "%d %d\n",n,m*2);
  for (size_t i=0; i<component.size(); i++)
  {
    if (component[i] == largest_component)
    {
      for (size_t j=0; j<graph.get_neighbors(i).size(); j++)
      {
        int neighbor = graph.get_neighbors(i)[j];
        fprintf(fp, "%d %d\n",remap[i],remap[neighbor]);
      }
    }
  }

  fclose(fp);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
andq $0x0, 0x28(%rsp)
andl $0x0, 0x30(%rsp)
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rsp)
andq $0x0, 0x48(%rsp)
cmpl $0x2, %edi
jne 0x27d4
movq 0x8(%r14), %r14
leaq 0x2b02(%rip), %rsi      # 0x502a
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x25a7
leaq 0x2b12(%rip), %rsi      # 0x5050
pushq $0x6
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x25d2
leaq 0x2b16(%rip), %rsi      # 0x506e
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x25fb
leaq 0x2b18(%rip), %rsi      # 0x508a
pushq $0x7
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
jne 0x27f9
leaq 0x28(%rsp), %rdi
callq 0x41ba
movups 0x2afc(%rip), %xmm0     # 0x5092
movaps %xmm0, 0x70(%rsp)
movabsq $0x74656e2e76725f, %rax # imm = 0x74656E2E76725F
jmp 0x261b
leaq 0x2a85(%rip), %rsi      # 0x5033
leaq 0x28(%rsp), %rdi
callq 0x3e6c
movups 0x2a81(%rip), %xmm0     # 0x5040
movups %xmm0, 0x7d(%rsp)
movups 0x2a68(%rip), %xmm0     # 0x5033
movaps %xmm0, 0x70(%rsp)
jmp 0x2620
leaq 0x2a7e(%rip), %rsi      # 0x5057
leaq 0x28(%rsp), %rdi
callq 0x3e6c
movups 0x2a6d(%rip), %xmm0     # 0x5057
movaps %xmm0, 0x70(%rsp)
movabsq $0x7478742e323133, %rax # imm = 0x7478742E323133
jmp 0x261b
leaq 0x28(%rsp), %rdi
callq 0x406e
movups 0x2a67(%rip), %xmm0     # 0x5073
movaps %xmm0, 0x70(%rsp)
movabsq $0x7478742e687061, %rax # imm = 0x7478742E687061
movq %rax, 0x7f(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x20b0
movabsq $0x636f72706572702e, %rcx # imm = 0x636F72706572702E
movq %rcx, 0x70(%rsp,%rax)
movabsq $0x6465737365636f, %rcx # imm = 0x6465737365636F
movq %rcx, 0x76(%rsp,%rax)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x28(%rsp), %rsi
callq 0x23df
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movl %eax, %edi
callq 0x2456
movl 0xc(%rsp), %r12d
movl 0x8(%rsp), %r13d
leaq 0x2a40(%rip), %rdi      # 0x50d0
xorl %r14d, %r14d
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2030
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0x54(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0x58(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x2872
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq 0x58(%rsp), %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x26f3
cmpl %ebp, (%rax,%rsi,4)
jne 0x26ee
movl %r14d, (%rdx,%rsi,4)
incl %r14d
incq %rsi
jmp 0x26dd
leaq 0x29ea(%rip), %rsi      # 0x50e4
leaq 0x70(%rsp), %rdi
callq 0x21a0
movq %rax, %r14
addl %r13d, %r13d
leaq 0x29d5(%rip), %r15      # 0x50e6
movq %rax, %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x21d0
leaq 0x28(%rsp), %r12
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r13
jae 0x279a
cmpl %ebp, (%rax,%r13,4)
jne 0x2795
xorl %ebx, %ebx
movq %r12, %rdi
movl %r13d, %esi
callq 0x2dc4
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
jae 0x2795
movq %r12, %rdi
movl %r13d, %esi
callq 0x2dc4
movq (%rax), %rax
movslq (%rax,%rbx,4), %rax
movq 0x58(%rsp), %rcx
movl (%rcx,%r13,4), %edx
movl (%rcx,%rax,4), %ecx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
incq %rbx
jmp 0x274a
incq %r13
jmp 0x272c
movq %r14, %rdi
callq 0x2170
leaq 0x58(%rsp), %rdi
callq 0x2be0
leaq 0x10(%rsp), %rdi
callq 0x2be0
leaq 0x38(%rsp), %rdi
callq 0x28c8
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x295a(%rip), %rdi      # 0x5135
callq 0x21f0
movq (%r14), %rsi
leaq 0x2826(%rip), %rdi      # 0x5010
xorl %eax, %eax
callq 0x2030
pushq $0x1
popq %rdi
callq 0x21b0
leaq 0x28a9(%rip), %rdi      # 0x50a9
movq %r14, %rsi
jmp 0x27ea
jmp 0x2809
jmp 0x2809
movq %rax, %r14
jmp 0x2822
movq %rax, %r14
jmp 0x282c
jmp 0x2815
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x2be0
leaq 0x10(%rsp), %rdi
callq 0x2be0
leaq 0x38(%rsp), %rdi
callq 0x28c8
movq %r14, %rdi
callq 0x2240