// File: 4n6ist[P]usn_analytics/src/main.cpp
// Function: main
int main(int argc, char **argv) {
    
  char *ifname = NULL;
  char *odname = NULL;
  timer measure_time;

  int opt;
  int longindex;
  
  struct option longopts[] = {
    {"help", no_argument, NULL, 'h'},
    {"output", required_argument, NULL, 'o'},
    {"raw", no_argument, NULL, 'r'}, 
    {"utc", no_argument, NULL, 'u'}, 
    {0, 0, 0, 0},
  };

  while((opt = getopt_long(argc, argv, "ho:ru", longopts, &longindex)) != -1) {
    switch(opt) {     
      case 'h':
        usage();
        exit(EXIT_FAILURE);
      case 'o':
        odname = optarg;
        break;
      case 'r':
        raw = true;
        break;
      case 'u':
        lt = false;
        break;
    }
  }
  for (int i = optind; i < argc; i++)
    ifname = argv[i];

  if (!ifname || !odname) {
    usage();
    exit(EXIT_FAILURE);
  }
  
  struct stat st;
  if (is_empty_dir(odname) == false) {
    if (stat(odname, &st) == 0) {
      std::cout << odname << " already exist" << std::endl;
      std::cout << "Please specify a empty directory or new directory" << std::endl;
      exit(EXIT_FAILURE);
    }
    int dresult;
    // try to create directory
#ifdef _WIN32
    dresult = _mkdir(odname);
#else
    dresult = mkdir(odname, 0775);
#endif

    if(dresult != 0) {
      std::cout << "unable to create " << odname << std::endl;
      std::cout << "Please check existence of parent directory and/or permissions" << std::endl;
      exit(EXIT_FAILURE);
    }
  } 

  process(ifname, odname);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x176b0
leaq -0xe0(%rbp), %rdi
leaq 0xbca0(%rip), %rsi      # 0x26cf0
movl $0xa0, %edx
callq 0x3290
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0xe0(%rbp), %rcx
leaq 0x1ac5(%rip), %rdx      # 0x1cb34
leaq -0x38(%rbp), %r8
callq 0x3590
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
je 0x1b105
movl -0x34(%rbp), %eax
addl $-0x68, %eax
movl %eax, %ecx
movq %rcx, -0x190(%rbp)
subl $0xd, %eax
ja 0x1b100
movq -0x190(%rbp), %rax
leaq 0x1872(%rip), %rcx      # 0x1c918
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x1ae00
jmp 0x1b0b6
movl $0x1, %edi
callq 0x3440
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x176f0
jmp 0x1b2f8
movq 0xbec9(%rip), %rax      # 0x26fb0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x1b100
movb $0x1, 0xc250(%rip)      # 0x27347
jmp 0x1b100
movb $0x0, 0xc240(%rip)      # 0x27340
jmp 0x1b05a
movq 0xbebc(%rip), %rax      # 0x26fc8
movl (%rax), %eax
movl %eax, -0xf0(%rbp)
movl -0xf0(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1b143
movq -0x10(%rbp), %rax
movslq -0xf0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x1b114
cmpq $0x0, -0x18(%rbp)
je 0x1b151
cmpq $0x0, -0x20(%rbp)
jne 0x1b162
callq 0x1ae00
jmp 0x1b158
movl $0x1, %edi
callq 0x3440
movq -0x20(%rbp), %rdi
callq 0x17780
movb %al, -0x191(%rbp)
jmp 0x1b173
movb -0x191(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1b2cd
movq -0x20(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x32f0
cmpl $0x0, %eax
jne 0x1b225
movq -0x20(%rbp), %rsi
movq 0xbe15(%rip), %rdi      # 0x26fc0
callq 0x3320
movq %rax, -0x1a0(%rbp)
jmp 0x1b1b9
movq -0x1a0(%rbp), %rdi
leaq 0x1973(%rip), %rsi      # 0x1cb3a
callq 0x3320
movq %rax, -0x1a8(%rbp)
jmp 0x1b1d5
movq -0x1a8(%rbp), %rdi
movq 0xbdc5(%rip), %rsi      # 0x26fa8
callq 0x3380
jmp 0x1b1ea
movq 0xbdcf(%rip), %rdi      # 0x26fc0
leaq 0x1951(%rip), %rsi      # 0x1cb49
callq 0x3320
movq %rax, -0x1b0(%rbp)
jmp 0x1b206
movq -0x1b0(%rbp), %rdi
movq 0xbd94(%rip), %rsi      # 0x26fa8
callq 0x3380
jmp 0x1b21b
movl $0x1, %edi
callq 0x3440
movq -0x20(%rbp), %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x3160
movl %eax, -0x184(%rbp)
cmpl $0x0, -0x184(%rbp)
je 0x1b2cb
movq 0xbd73(%rip), %rdi      # 0x26fc0
leaq 0x1927(%rip), %rsi      # 0x1cb7b
callq 0x3320
movq %rax, -0x1b8(%rbp)
jmp 0x1b262
movq -0x1b8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3320
movq %rax, -0x1c0(%rbp)
jmp 0x1b27b
movq -0x1c0(%rbp), %rdi
movq 0xbd1f(%rip), %rsi      # 0x26fa8
callq 0x3380
jmp 0x1b290
movq 0xbd29(%rip), %rdi      # 0x26fc0
leaq 0x18ef(%rip), %rsi      # 0x1cb8d
callq 0x3320
movq %rax, -0x1c8(%rbp)
jmp 0x1b2ac
movq -0x1c8(%rbp), %rdi
movq 0xbcee(%rip), %rsi      # 0x26fa8
callq 0x3380
jmp 0x1b2c1
movl $0x1, %edi
callq 0x3440
jmp 0x1b2cd
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1ae60
jmp 0x1b2dc
movl $0x0, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x176f0
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0xe8(%rbp), %rdi
callq 0x35c0