// File: DavidNKraemer[P]convex-hull/main.cpp
// Function: main
int main(int argc, char *argv[]) {
  if (argc < 2) {
    std::cerr << "You must pass in the testing file\n";
    return EXIT_FAILURE;
  }
  std::string test_points_dir = "./tests/";
  std::string filename = argv[1];

  std::string results_dir = "./results/";

  CvHullBase *method = nullptr;

  // split method
  if (argc > 3) {
    // if you have other method, handle here
    // since currently we only have graham scan
    method = new GrahamScan();
  }
  else
    method = new GrahamScan();

  std::vector<Point2D> pc;
  std::vector<Point2D> ch;

  //
  // Estimate the size of pc and ch by using reserve!

  std::cout << "Fetching point cloud from [" 
    << test_points_dir + filename << "]" << std::endl;

  try {
    loadtxt(test_points_dir + filename, pc);
  } 

  catch (std::string err) {
    std::cerr << err << std::endl << "Aborting program." << std::endl;
    return 1;
  }

  compute_cvhull(pc, ch, *method);
  try {
    write2txt(results_dir + filename, ch);
  } 

  catch (std::string err) {
    std::cerr << err << std::endl << "Aborting program." << std::endl;
    return 1;
  }

  std::cout << "The result has been written to [" 
    << results_dir + filename << "]" << std::endl;

  if (method)
    delete method;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x397e
movq 0x868a(%rip), %rdi      # 0xbff0
leaq 0x46c2(%rip), %rsi      # 0x802f
callq 0x31c0
movl $0x1, -0x4(%rbp)
jmp 0x3fd7
leaq -0x31(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x3350
movq -0x1a0(%rbp), %rdx
leaq 0x46b6(%rip), %rsi      # 0x8052
leaq -0x30(%rbp), %rdi
callq 0x4450
jmp 0x39a7
leaq -0x31(%rbp), %rdi
callq 0x3210
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x3350
movq -0x1b0(%rbp), %rsi
movq -0x1a8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4450
jmp 0x39e8
leaq -0x69(%rbp), %rdi
callq 0x3210
leaq -0x91(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x3350
movq -0x1b8(%rbp), %rdx
leaq 0x4649(%rip), %rsi      # 0x805b
leaq -0x90(%rbp), %rdi
callq 0x4450
jmp 0x3a20
leaq -0x91(%rbp), %rdi
callq 0x3210
movq $0x0, -0xa0(%rbp)
cmpl $0x3, -0x8(%rbp)
jle 0x3ae8
movl $0x8, %edi
callq 0x31d0
movq %rax, -0x1c0(%rbp)
jmp 0x3a54
movq -0x1c0(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x30f0
movq -0x1c0(%rbp), %rdi
callq 0x4500
movq -0x1c0(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x3b28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3210
jmp 0x4019
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x3210
jmp 0x4010
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x3210
jmp 0x4007
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3ffb
movl $0x8, %edi
callq 0x31d0
movq %rax, -0x1c8(%rbp)
jmp 0x3afb
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x30f0
movq -0x1c8(%rbp), %rdi
callq 0x4500
movq -0x1c8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4540
leaq -0xd0(%rbp), %rdi
callq 0x4540
movq 0x8489(%rip), %rdi      # 0xbfd0
leaq 0x4518(%rip), %rsi      # 0x8066
callq 0x31c0
movq %rax, -0x1d0(%rbp)
jmp 0x3b5c
leaq -0xf0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x4560
jmp 0x3b72
movq -0x1d0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x31b0
movq %rax, -0x1d8(%rbp)
jmp 0x3b8e
movq -0x1d8(%rbp), %rdi
leaq 0x44e6(%rip), %rsi      # 0x8082
callq 0x31c0
movq %rax, -0x1e0(%rbp)
jmp 0x3baa
movq -0x1e0(%rbp), %rdi
movq 0x8400(%rip), %rsi      # 0xbfb8
callq 0x31f0
jmp 0x3bbf
leaq -0xf0(%rbp), %rdi
callq 0x33b8
leaq -0x110(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x4560
jmp 0x3be1
leaq -0x110(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3530
jmp 0x3bf6
leaq -0x110(%rbp), %rdi
callq 0x33b8
jmp 0x3d4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x33b8
jmp 0x3fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3c5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x33b8
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3fe3
movq -0x40(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x3260
movq %rax, %rsi
leaq -0x130(%rbp), %rdi
callq 0x30b0
jmp 0x3c8c
movq -0x1e8(%rbp), %rdi
callq 0x30a0
movq 0x8351(%rip), %rdi      # 0xbff0
leaq -0x130(%rbp), %rsi
callq 0x31b0
movq %rax, -0x1f0(%rbp)
jmp 0x3cb4
movq -0x1f0(%rbp), %rdi
movq 0x82f6(%rip), %rsi      # 0xbfb8
callq 0x31f0
movq %rax, -0x1f8(%rbp)
jmp 0x3cd0
movq -0x1f8(%rbp), %rdi
leaq 0x43a6(%rip), %rsi      # 0x8084
callq 0x31c0
movq %rax, -0x200(%rbp)
jmp 0x3cec
movq -0x200(%rbp), %rdi
movq 0x82be(%rip), %rsi      # 0xbfb8
callq 0x31f0
jmp 0x3d01
movl $0x1, -0x4(%rbp)
movl $0x1, -0x134(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x33b8
callq 0x3300
jmp 0x3d44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x33b8
callq 0x3300
jmp 0x3d49
jmp 0x3fa1
jmp 0x3fe3
movq -0xa0(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x45f0
jmp 0x3d6a
leaq -0x158(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x4560
jmp 0x3d83
leaq -0x158(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3730
jmp 0x3d98
leaq -0x158(%rbp), %rdi
callq 0x33b8
jmp 0x3ec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3dcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x33b8
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3fe3
movq -0x40(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3260
movq %rax, %rsi
leaq -0x178(%rbp), %rdi
callq 0x30b0
jmp 0x3e00
movq -0x208(%rbp), %rdi
callq 0x30a0
movq 0x81dd(%rip), %rdi      # 0xbff0
leaq -0x178(%rbp), %rsi
callq 0x31b0
movq %rax, -0x210(%rbp)
jmp 0x3e28
movq -0x210(%rbp), %rdi
movq 0x8182(%rip), %rsi      # 0xbfb8
callq 0x31f0
movq %rax, -0x218(%rbp)
jmp 0x3e44
movq -0x218(%rbp), %rdi
leaq 0x4232(%rip), %rsi      # 0x8084
callq 0x31c0
movq %rax, -0x220(%rbp)
jmp 0x3e60
movq -0x220(%rbp), %rdi
movq 0x814a(%rip), %rsi      # 0xbfb8
callq 0x31f0
jmp 0x3e75
movl $0x1, -0x4(%rbp)
movl $0x1, -0x134(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x33b8
callq 0x3300
jmp 0x3eb8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x33b8
callq 0x3300
jmp 0x3ebd
jmp 0x3fa1
jmp 0x3fe3
movq 0x8107(%rip), %rdi      # 0xbfd0
leaq 0x41c6(%rip), %rsi      # 0x8096
callq 0x31c0
movq %rax, -0x228(%rbp)
jmp 0x3ede
leaq -0x198(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x4560
jmp 0x3ef7
movq -0x228(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x31b0
movq %rax, -0x230(%rbp)
jmp 0x3f13
movq -0x230(%rbp), %rdi
leaq 0x4161(%rip), %rsi      # 0x8082
callq 0x31c0
movq %rax, -0x238(%rbp)
jmp 0x3f2f
movq -0x238(%rbp), %rdi
movq 0x807b(%rip), %rsi      # 0xbfb8
callq 0x31f0
jmp 0x3f44
leaq -0x198(%rbp), %rdi
callq 0x33b8
cmpq $0x0, -0xa0(%rbp)
je 0x3f97
movq -0xa0(%rbp), %rax
movq %rax, -0x240(%rbp)
cmpq $0x0, %rax
je 0x3f7b
movq -0x240(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x3f97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x33b8
jmp 0x3fe3
movl $0x0, -0x134(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4620
leaq -0xb8(%rbp), %rdi
callq 0x4620
leaq -0x90(%rbp), %rdi
callq 0x33b8
leaq -0x68(%rbp), %rdi
callq 0x33b8
leaq -0x30(%rbp), %rdi
callq 0x33b8
movl -0x4(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
leaq -0xd0(%rbp), %rdi
callq 0x4620
leaq -0xb8(%rbp), %rdi
callq 0x4620
leaq -0x90(%rbp), %rdi
callq 0x33b8
leaq -0x68(%rbp), %rdi
callq 0x33b8
leaq -0x30(%rbp), %rdi
callq 0x33b8
movq -0x40(%rbp), %rdi
callq 0x3340
movq %rax, %rdi
callq 0x45e0
nopw (%rax,%rax)