// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0xb8, %rsp
cmpl $0x1, %edi
jg 0x26c2
movq 0x3942(%rip), %rdi      # 0x5ff0
leaq 0x197a(%rip), %rsi      # 0x402f
callq 0x2140
pushq $0x1
popq %rbx
jmp 0x2881
movq %rsi, %rbx
leaq 0x1986(%rip), %rsi      # 0x4052
leaq 0x98(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2b78
movq 0x8(%rbx), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x2b78
leaq 0x1963(%rip), %rsi      # 0x405b
leaq 0x78(%rsp), %rdi
movq %rsp, %rdx
callq 0x2b78
pushq $0x8
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x3641(%rip), %rax      # 0x5d58
addq $0x10, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x3892(%rip), %rdi      # 0x5fd0
leaq 0x1921(%rip), %rsi      # 0x4066
callq 0x2140
movq %rax, %r14
movq %rsp, %rdi
leaq 0x98(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x2bb3
movq %rsp, %rsi
movq %r14, %rdi
callq 0x2130
leaq 0x190e(%rip), %rsi      # 0x4082
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movq %rsp, %rdi
callq 0x22a8
movq %rsp, %rdi
leaq 0x98(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x2bb3
movq %rsp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ec
movq %rsp, %rdi
callq 0x22a8
movq (%rbx), %rax
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq *(%rax)
movq %rsp, %rdi
leaq 0x78(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x2bb3
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x254d
movq %rsp, %rdi
callq 0x22a8
movq 0x37da(%rip), %rdi      # 0x5fd0
leaq 0x1899(%rip), %rsi      # 0x4096
callq 0x2140
movq %rax, %r14
movq %rsp, %rdi
leaq 0x78(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x2bb3
movq %rsp, %rsi
movq %r14, %rdi
callq 0x2130
leaq 0x1859(%rip), %rsi      # 0x4082
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movq %rsp, %rdi
callq 0x22a8
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x2f24
leaq 0x40(%rsp), %rdi
callq 0x2f24
leaq 0x78(%rsp), %rdi
callq 0x22a8
leaq 0x58(%rsp), %rdi
callq 0x22a8
leaq 0x98(%rsp), %rdi
callq 0x22a8
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r14
retq
jmp 0x29da
movq %rdx, %r14
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22a8
jmp 0x28a9
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x29ea
movq %rbx, %rdi
callq 0x2180
movq %rsp, %rdi
movq %rax, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2090
movq 0x371b(%rip), %rdi      # 0x5ff0
movq %rsp, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
leaq 0x1798(%rip), %rsi      # 0x4084
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movq %rsp, %rdi
callq 0x22a8
callq 0x2220
jmp 0x299e
jmp 0x29da
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22a8
callq 0x2220
jmp 0x29ea
movq %rdx, %r14
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22a8
jmp 0x293e
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x29ea
movq %rbx, %rdi
callq 0x2180
movq %rsp, %rdi
movq %rax, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2090
movq 0x3686(%rip), %rdi      # 0x5ff0
movq %rsp, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
leaq 0x1703(%rip), %rsi      # 0x4084
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movq %rsp, %rdi
callq 0x22a8
callq 0x2220
pushq $0x1
popq %rbx
jmp 0x284c
jmp 0x29da
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22a8
callq 0x2220
jmp 0x29ea
movq %rax, %rdi
callq 0x2beb
jmp 0x29da
movq %rax, %rbx
jmp 0x29fe
movq %rax, %rbx
jmp 0x2a08
movq %rax, %rbx
jmp 0x2a12
movq %rax, %rbx
jmp 0x2a1f
jmp 0x29df
movq %rax, %rbx
jmp 0x29ea
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22a8
leaq 0x20(%rsp), %rdi
callq 0x2f24
leaq 0x40(%rsp), %rdi
callq 0x2f24
leaq 0x78(%rsp), %rdi
callq 0x22a8
leaq 0x58(%rsp), %rdi
callq 0x22a8
leaq 0x98(%rsp), %rdi
callq 0x22a8
movq %rbx, %rdi
callq 0x2250
nop