// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
leaq 0x1e29(%rip), %rax      # 0x3aa0
movq %rax, -0x40(%rbp)
leaq -0x100(%rbp), %rdi
leaq 0x4097(%rip), %rsi      # 0x5d20
movl $0xc0, %edx
callq 0x10a0
cmpl $0x1, -0x8(%rbp)
jne 0x1ca3
movl $0x1, %edi
callq 0x1ec0
jmp 0x1ca5
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x100(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x1060
movl %eax, -0x38(%rbp)
cmpl $-0x1, %eax
je 0x1e22
movl -0x38(%rbp), %eax
addl $-0x68, %eax
movl %eax, %ecx
movq %rcx, -0x108(%rbp)
subl $0xc, %eax
ja 0x1e13
movq -0x108(%rbp), %rax
leaq 0x1d79(%rip), %rcx      # 0x3a6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x42d5(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x65, %eax
jne 0x1d17
movl $0x0, -0x34(%rbp)
jmp 0x1d51
movq 0x42ba(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0x1d32
movl $0x1, -0x34(%rbp)
jmp 0x1d4f
movq 0x4297(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1d83(%rip), %rsi      # 0x3ac6
movb $0x0, %al
callq 0x1090
jmp 0x1e8d
jmp 0x1d51
jmp 0x1e1d
xorl %edi, %edi
callq 0x1ec0
jmp 0x1e1d
movq 0x426f(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
leaq 0x1d74(%rip), %rsi      # 0x3ae7
callq 0x10b0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1da0
movq 0x4246(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1d56(%rip), %rsi      # 0x3aea
movb $0x0, %al
callq 0x1090
jmp 0x1e8d
jmp 0x1e1d
movq 0x422f(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
leaq 0x1d7c(%rip), %rsi      # 0x3b2f
callq 0x10b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1de0
movq 0x4206(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1d5d(%rip), %rsi      # 0x3b31
movb $0x0, %al
callq 0x1090
jmp 0x1e8d
jmp 0x1e1d
movq 0x41ef(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1e11
movq 0x41d2(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1d44(%rip), %rsi      # 0x3b4c
movb $0x0, %al
callq 0x1090
jmp 0x1e8d
jmp 0x1e1d
movl $0x1, %edi
callq 0x1ec0
jmp 0x1ca5
cmpq $0x0, -0x20(%rbp)
jne 0x1e33
movl $0x1, %edi
callq 0x1ec0
movq -0x20(%rbp), %rdi
callq 0x1780
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1e61
movq 0x4182(%rip), %rax      # 0x5fd0
movq (%rax), %rdi
leaq 0x1d10(%rip), %rsi      # 0x3b68
movb $0x0, %al
callq 0x1090
jmp 0x1e8d
cmpl $0x0, -0x34(%rbp)
je 0x1e7a
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1b20
jmp 0x1e8b
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1980
jmp 0x1e8d
cmpq $0x0, -0x28(%rbp)
je 0x1e9d
movq -0x28(%rbp), %rdi
callq 0x1040
cmpq $0x0, -0x30(%rbp)
je 0x1ead
movq -0x30(%rbp), %rdi
callq 0x1040
xorl %eax, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)