// File: /workspace/github_c_makefile_star2_O3/dubeyalok7[P]crypto-algo/des/des/main.c
// Function: main
int main(int argc, char *argv[])
{
  uint64_t key = 0;
  const char *keystr = NULL;
  FILE *ifile = NULL, *ofile=NULL;
  int op;

  int optc = 0;

  const char *short_opts = "t:o:k:i:h:";
  const struct option long_opts[]=
  {
    {"help",           no_argument, NULL, 'h'},
    {"task",      required_argument, NULL, 't'},
    {"output",   required_argument, NULL, 'o'},
    {"input",   required_argument, NULL, 'i'},
    {"key",      required_argument, NULL, 'k'},
    {NULL,                       0, NULL,   0}
  };
  if(argc == 1)
    help(EXIT_FAILURE);

  while((optc = getopt_long(argc, argv, short_opts, long_opts, NULL))!= -1)
  {
    switch(optc)
    {
      case 't':
        if(optarg[0]=='e')
          op = ENCRYPT;
        else if(optarg[0] == 'd')
          op = DECRYPT;
        else{
          fprintf(stdout, "error: in-valid type operations\n");
          goto exit;
        }
        break;
      case 'h':
        help(EXIT_SUCCESS);
        break;
      case 'o':
        ofile = fopen(optarg, "w+");
        if(!ofile) {
          fprintf(stdout, "error: not have permission to create/open file or invalid file name\n"); 
          goto exit;
        }
        break;
      case 'i':
        ifile = fopen(optarg, "r");
        if(!ifile) {
          fprintf(stdout, "error: file doesn't exist\n");
          goto exit;
        }
        break;
      case 'k':
        keystr = optarg;
        if(!keystr) {
          fprintf(stdout, "error: key is not provided\n");
          goto exit;
        }
        break;
      default:
        help(EXIT_FAILURE);
    }
  }
  if(!keystr)
    help(EXIT_FAILURE);

  key = key_convert(keystr);
  if(!key){
    fprintf(stdout, "error: check key length\n");
    goto exit;
  }
    
  if(op)
    decrypt(ifile, ofile, key);
  else
    encrypt(ifile, ofile, key);

exit:
  if(ifile)
    fclose(ifile);
  if(ofile)
    fclose(ofile);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r15
movl %edi, %ebp
leaq 0x461f(%rip), %rsi      # 0x5d20
leaq 0x20(%rsp), %rdi
movl $0xc0, %edx
callq 0x1080
cmpl $0x1, %ebp
je 0x193d
xorl %eax, %eax
leaq 0x236a(%rip), %r13      # 0x3a8c
leaq 0x20(%rsp), %rbx
movq 0x48aa(%rip), %r12      # 0x5fd8
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl %ebp, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x1060
cmpl $0x74, %eax
jne 0x177d
movq (%r12), %rax
movzbl (%rax), %eax
xorl %r14d, %r14d
cmpl $0x65, %eax
je 0x1745
cmpl $0x64, %eax
jne 0x183c
movl $0x1, %r14d
jmp 0x1745
leal -0x68(%rax), %ecx
cmpl $0x7, %ecx
ja 0x17fc
leaq 0x22e0(%rip), %rdx      # 0x3a6c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq (%r12), %rdi
leaq 0x237b(%rip), %rsi      # 0x3b1b
callq 0x1090
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x1745
jmp 0x18ea
movq (%r12), %rdi
leaq 0x2314(%rip), %rsi      # 0x3ad3
callq 0x1090
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x1745
jmp 0x18c6
movq (%r12), %rax
testq %rax, %rax
jne 0x1740
movq 0x47e5(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x2343(%rip), %rdi      # 0x3b38
movl $0x1b, %esi
jmp 0x186a
cmpl $-0x1, %eax
jne 0x1911
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1942
callq 0x13b6
testq %rax, %rax
je 0x1854
testl %r14d, %r14d
je 0x1880
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %rax, %rdx
callq 0x15b3
jmp 0x1898
movq 0x478d(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x2265(%rip), %rdi      # 0x3ab2
movl $0x20, %esi
jmp 0x186a
movq 0x4775(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x22ef(%rip), %rdi      # 0x3b54
movl $0x18, %esi
movl $0x1, %edx
callq 0x10b0
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %r14
jmp 0x1898
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %rax, %rdx
callq 0x143f
testq %r14, %r14
je 0x18a5
movq %r14, %rdi
callq 0x1040
testq %rbx, %rbx
je 0x18b2
movq %rbx, %rdi
callq 0x1040
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4703(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x21ff(%rip), %rdi      # 0x3ad6
movl $0x44, %esi
movl $0x1, %edx
callq 0x10b0
xorl %ebx, %ebx
jmp 0x1879
movq 0x46df(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x2222(%rip), %rdi      # 0x3b1d
movl $0x1a, %esi
movl $0x1, %edx
callq 0x10b0
movq 0x10(%rsp), %rbx
jmp 0x18a5
callq 0x10f5
movq 0x46b3(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
leaq 0x2246(%rip), %rdi      # 0x3b6d
movl $0x123, %esi            # imm = 0x123
movl $0x1, %edx
callq 0x10b0
xorl %edi, %edi
callq 0x10a0
callq 0x111a
callq 0x10d0