// File: /workspace/github_cpp_makefile_star2_O3/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 0x291b
movq 0x8(%r14), %r14
leaq 0x2a4d(%rip), %rsi      # 0x505a
movl $0x8, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x269a
leaq 0x2a5b(%rip), %rsi      # 0x5080
movl $0x6, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x26cb
leaq 0x2a5d(%rip), %rsi      # 0x509e
movl $0x4, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
je 0x26f7
leaq 0x2a5d(%rip), %rsi      # 0x50ba
movl $0x7, %edx
movq %r14, %rdi
callq 0x20c0
testl %eax, %eax
jne 0x2942
leaq 0x38(%rsp), %rdi
callq 0x4889
movups 0x2a3f(%rip), %xmm0     # 0x50c2
movaps %xmm0, 0x80(%rsp)
movabsq $0x74656e2e76725f, %rax # imm = 0x74656E2E76725F
jmp 0x271a
leaq 0x29c2(%rip), %rsi      # 0x5063
leaq 0x38(%rsp), %rdi
callq 0x4474
movups 0x29be(%rip), %xmm0     # 0x5070
movups %xmm0, 0x8d(%rsp)
movups 0x29a2(%rip), %xmm0     # 0x5063
movaps %xmm0, 0x80(%rsp)
jmp 0x2722
leaq 0x29b5(%rip), %rsi      # 0x5087
leaq 0x38(%rsp), %rdi
callq 0x4474
movups 0x29a4(%rip), %xmm0     # 0x5087
movaps %xmm0, 0x80(%rsp)
movabsq $0x7478742e323133, %rax # imm = 0x7478742E323133
jmp 0x271a
leaq 0x38(%rsp), %rdi
callq 0x46ab
movups 0x299b(%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 0x2498
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
leaq 0x30(%rsp), %r8
movl %eax, %edi
callq 0x2524
movl 0x34(%rsp), %r15d
movl 0x30(%rsp), %r12d
leaq 0x2962(%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 0x2809
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 0x2801
movl %edi, (%rdx,%rsi,4)
incl %edi
incq %rsi
cmpq %rsi, %rcx
jne 0x27f7
leaq 0x2904(%rip), %rsi      # 0x5114
leaq 0x80(%rsp), %rdi
callq 0x21a0
movq %rax, %r14
addl %r12d, %r12d
leaq 0x28ec(%rip), %rsi      # 0x5116
movq %rax, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21d0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
je 0x28c7
leaq 0x38(%rsp), %r15
leaq 0x28c1(%rip), %r12      # 0x5116
xorl %r13d, %r13d
cmpl %ebp, (%rax,%r13,4)
jne 0x28b5
xorl %ebx, %ebx
movq %r15, %rdi
movl %r13d, %esi
callq 0x3334
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
jae 0x28ab
movq %r15, %rdi
movl %r13d, %esi
callq 0x3334
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 0x2860
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
incq %r13
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rdx, %r13
jb 0x2858
movq %r14, %rdi
callq 0x2170
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x28e6
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x28fd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x48(%rsp), %rdi
callq 0x2b52
xorl %eax, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2843(%rip), %rdi      # 0x5165
callq 0x21f0
movq (%r14), %rsi
leaq 0x270f(%rip), %rdi      # 0x5040
xorl %eax, %eax
callq 0x2030
movl $0x1, %edi
callq 0x21b0
leaq 0x2790(%rip), %rdi      # 0x50d9
movq %r14, %rsi
jmp 0x2931
jmp 0x2952
jmp 0x2952
movq %rax, %r14
jmp 0x2978
movq %rax, %r14
jmp 0x298f
jmp 0x295e
movq %rax, %r14
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2978
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x298f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x48(%rsp), %rdi
callq 0x2b52
movq %r14, %rdi
callq 0x2240
nop