// File: /workspace/github_cpp_makefile_star2_O1/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 $0x468, %rsp            # imm = 0x468
movq %rsi, %r14
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rsp)
movq %rax, 0x58(%rsp)
cmpl $0x2, %edi
jne 0x291c
movq 0x8(%r14), %r14
leaq 0x2a46(%rip), %rsi      # 0x505a
movl $0x8, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x26a1
leaq 0x2a54(%rip), %rsi      # 0x5080
movl $0x6, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x26d2
leaq 0x2a56(%rip), %rsi      # 0x509e
movl $0x4, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x26fe
leaq 0x2a56(%rip), %rsi      # 0x50ba
movl $0x7, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
jne 0x2943
leaq 0x38(%rsp), %rdi
callq 0x4875
movups 0x2a38(%rip), %xmm0     # 0x50c2
movaps %xmm0, 0x80(%rsp)
movabsq $0x74656e2e76725f, %rax # imm = 0x74656E2E76725F
jmp 0x2721
leaq 0x29bb(%rip), %rsi      # 0x5063
leaq 0x38(%rsp), %rdi
callq 0x4460
movups 0x29b7(%rip), %xmm0     # 0x5070
movups %xmm0, 0x8d(%rsp)
movups 0x299b(%rip), %xmm0     # 0x5063
movaps %xmm0, 0x80(%rsp)
jmp 0x2729
leaq 0x29ae(%rip), %rsi      # 0x5087
leaq 0x38(%rsp), %rdi
callq 0x4460
movups 0x299d(%rip), %xmm0     # 0x5087
movaps %xmm0, 0x80(%rsp)
movabsq $0x7478742e323133, %rax # imm = 0x7478742E323133
jmp 0x2721
leaq 0x38(%rsp), %rdi
callq 0x4697
movups 0x2994(%rip), %xmm0     # 0x50a3
movaps %xmm0, 0x80(%rsp)
movabsq $0x7478742e687061, %rax # imm = 0x7478742E687061
movq %rax, 0x8f(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x20b0
movabsq $0x636f72706572702e, %rcx # imm = 0x636F72706572702E
movq %rcx, 0x80(%rsp,%rax)
movabsq $0x6465737365636f, %rcx # imm = 0x6465737365636F
movq %rcx, 0x86(%rsp,%rax)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x38(%rsp), %rsi
callq 0x24a8
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
leaq 0x30(%rsp), %r8
movl %eax, %edi
callq 0x2531
movl 0x34(%rsp), %r15d
movl 0x30(%rsp), %r12d
leaq 0x295b(%rip), %rdi      # 0x5100
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2030
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0x7c(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x29d6
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
je 0x2810
sarq $0x2, %rcx
movq 0x60(%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %esi, %esi
xorl %edi, %edi
cmpl %ebp, (%rax,%rsi,4)
jne 0x2808
movl %edi, (%rdx,%rsi,4)
incl %edi
incq %rsi
cmpq %rsi, %rcx
jne 0x27fe
leaq 0x28fd(%rip), %rsi      # 0x5114
leaq 0x80(%rsp), %rdi
callq 0x21a0
movq %rax, %r14
addl %r12d, %r12d
leaq 0x28e5(%rip), %rsi      # 0x5116
movq %rax, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21d0
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x28c8
leaq 0x38(%rsp), %r15
leaq 0x28bd(%rip), %r12      # 0x5116
xorl %r13d, %r13d
cmpl %ebp, (%rax,%r13,4)
jne 0x28af
xorl %ebx, %ebx
movq %r15, %rdi
movl %r13d, %esi
callq 0x3332
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
jae 0x28af
movq %r15, %rdi
movl %r13d, %esi
callq 0x3332
movq (%rax), %rax
movslq (%rax,%rbx,4), %rax
movq 0x60(%rsp), %rcx
movl (%rcx,%r13,4), %edx
movl (%rcx,%rax,4), %ecx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
incq %rbx
jmp 0x2864
incq %r13
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r13
jb 0x285c
movq %r14, %rdi
callq 0x2170
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x28e7
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x28fe
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x48(%rsp), %rdi
callq 0x2b4a
xorl %eax, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2842(%rip), %rdi      # 0x5165
callq 0x21f0
movq (%r14), %rsi
leaq 0x270e(%rip), %rdi      # 0x5040
xorl %eax, %eax
callq 0x2030
movl $0x1, %edi
callq 0x21b0
leaq 0x278f(%rip), %rdi      # 0x50d9
movq %r14, %rsi
jmp 0x2932
jmp 0x2953
jmp 0x2953
movq %rax, %r14
jmp 0x2979
movq %rax, %r14
jmp 0x2990
jmp 0x295f
movq %rax, %r14
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2979
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2990
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x48(%rsp), %rdi
callq 0x2b4a
movq %r14, %rdi
callq 0x2240