// File: /workspace/github_c_makefile_star2_O0/otrtool[P]otrtool/src/main.c
// Function: main
int main(int argc, char *argv[]) {
  fputs("OTR-Tool, " VERSION "\n", stderr);

  int i;
  int opt;
  while ( (opt = getopt(argc, argv, "hvgifxyk:e:p:D:O:uT:")) != -1) {
    switch (opt) {
      case 'h':
        usageError();
        exit(EXIT_SUCCESS);
        break;
      case 'v':
        opts.verbosity = VERB_DEBUG;
        break;
      case 'g':
        opts.guimode = 1;
        interactive = 0;
        break;
      case 'i':
        opts.action = ACTION_INFO;
        break;
      case 'f':
        opts.action = ACTION_FETCHKEY;
        break;
      case 'x':
        opts.action = ACTION_DECRYPT;
        break;
      case 'y':
        opts.action = ACTION_VERIFY;
        break;
      case 'k':
        opts.keyphrase = optarg;
        break;
      case 'e':
        opts.email = strdup(optarg);
        memset(optarg, 'x', strlen(optarg));
        break;
      case 'p':
        opts.password = strdup(optarg);
        memset(optarg, 'x', strlen(optarg));
        break;
      case 'D':
        opts.destdir = optarg;
        break;
      case 'O':
        opts.destfile = optarg;
        break;
      case 'u':
        opts.unlinkmode = 1;
        break;
      case 'T':
        opts.n_threads = atoi(optarg);
        break;
      default:
        usageError();
        exit(EXIT_FAILURE);
    }
  }
  if (opts.verbosity >= VERB_DEBUG) {
    fputs("command line: ", stderr);
    for (i = 0; i < argc; ++i) {
      fputs(argv[i], stderr);
      fputc((i == argc - 1) ? '\n' : ' ', stderr);
    }
  }
  
  if (optind >= argc) {
    fprintf(stderr, "Missing argument: otrkey-file\n");
    usageError();
    exit(EXIT_FAILURE);
  }
  if (argc > optind + 1) {
    if (opts.destfile != NULL && strcmp(opts.destfile, "-") == 0) {
      i = 0;
    }
    else for (i = optind; i < argc; i++) {
      if (strcmp(argv[i], "-") == 0)
        break;
    }
    if (i < argc)
      ERROR("Usage error: piping is not possible with multiple input files");
  }
  if (opts.guimode && opts.destfile != NULL && strcmp(opts.destfile, "-") == 0)
    ERROR("Usage error: options -g and -O - are incompatible");

  if (!isatty(2) && opts.guimode == 0) {
    logfilemode = 1;
    interactive = 0;
  }
  if (interactive) {
    if (!isatty(0)) {
      const char *ttyname = ctermid(NULL); /* usually /dev/tty */
      ttyfile = fopen(ttyname, "r");
      if (ttyfile == NULL) {
        if (opts.verbosity >= VERB_DEBUG)
          perrorf("cannot open TTY: %s", ttyname);
        interactive = 0;
      }
    }
    else ttyfile = stdin;
  }

  if ((opts.action == ACTION_DECRYPT || opts.action == ACTION_VERIFY)
      && opts.n_threads == 0) {
    errno = 0;
    nice(10);
    if (errno == 0 && opts.verbosity >= VERB_DEBUG)
      fputs("NICE was set to 10\n", stderr);

    // Set I/O scheduling class using the Linux-specific ioprio_set syscall
    // If this causes problems, just delete the ionice-stuff
    #if defined(__linux__) && defined(__NR_ioprio_set)
      if (syscall(__NR_ioprio_set, 1, getpid(), 7 | 3 << 13) == 0
           && opts.verbosity >= VERB_DEBUG)
        fputs("IONICE class was set to Idle\n", stderr);
    #endif
  }
  if (opts.action == ACTION_FETCHKEY || opts.action == ACTION_DECRYPT) {
    keycache_open();
  }

  for (i = optind; i < argc; i++) {
    filename = argv[i];
    if (argc > optind + 1)
      fprintf(stderr, "\n==> %s <==\n", filename);
    openFile();
    processFile();
    if (fclose(file) != 0)
      PERROR("Error closing file");
    free(header);
  }
  
  exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x48cb(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x27c6(%rip), %rdi      # 0xaedd
callq 0x2240
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x27ce(%rip), %rdx      # 0xaef8
callq 0x2070
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x88d6
movl -0x18(%rbp), %eax
addl $-0x44, %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x35, %eax
ja 0x88c2
movq -0x28(%rbp), %rax
leaq 0x1915(%rip), %rcx      # 0xa070
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x86d0
xorl %edi, %edi
callq 0x2290
movl $0x1, 0x4b2a(%rip)      # 0xd2a4
jmp 0x88d1
movl $0x1, 0x4b1f(%rip)      # 0xd2a8
movl $0x0, 0x4acd(%rip)      # 0xd260
jmp 0x88d1
movl $0x0, 0x4afe(%rip)      # 0xd2a0
jmp 0x88d1
movl $0x1, 0x4aef(%rip)      # 0xd2a0
jmp 0x88d1
movl $0x2, 0x4ae0(%rip)      # 0xd2a0
jmp 0x88d1
movl $0x3, 0x4ad1(%rip)      # 0xd2a0
jmp 0x88d1
movq 0x47e5(%rip), %rax      # 0xcfc0
movq (%rax), %rax
movq %rax, 0x4adb(%rip)      # 0xd2c0
jmp 0x88d1
movq 0x47cf(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x2440
movq %rax, 0x4ab0(%rip)      # 0xd2b0
movq 0x47b9(%rip), %rax      # 0xcfc0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x47ab(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x20c0
movq -0x30(%rbp), %rdi
movq %rax, %rdx
movl $0x78, %esi
callq 0x2110
jmp 0x88d1
movq 0x4786(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x2440
movq %rax, 0x4a6f(%rip)      # 0xd2b8
movq 0x4770(%rip), %rax      # 0xcfc0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x4762(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x20c0
movq -0x38(%rbp), %rdi
movq %rax, %rdx
movl $0x78, %esi
callq 0x2110
jmp 0x88d1
movq 0x4740(%rip), %rax      # 0xcfc0
movq (%rax), %rax
movq %rax, 0x4a3e(%rip)      # 0xd2c8
jmp 0x88d1
movq 0x472d(%rip), %rax      # 0xcfc0
movq (%rax), %rax
movq %rax, 0x4a33(%rip)      # 0xd2d0
jmp 0x88d1
movl $0x1, 0x4a03(%rip)      # 0xd2ac
jmp 0x88d1
movq 0x470e(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x2380
movl %eax, 0x4a18(%rip)      # 0xd2d8
jmp 0x88d1
callq 0x86d0
movl $0x1, %edi
callq 0x2290
jmp 0x871c
cmpl $0x1, 0x49c7(%rip)      # 0xd2a4
jb 0x8953
movq 0x46f2(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x261d(%rip), %rdi      # 0xaf0d
callq 0x2240
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x8951
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x46c1(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
callq 0x2240
movl -0x14(%rbp), %ecx
movl -0x8(%rbp), %edx
subl $0x1, %edx
movl $0x20, %edi
movl $0xa, %eax
cmpl %edx, %ecx
cmovel %eax, %edi
movq 0x469a(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
callq 0x22c0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x88fc
jmp 0x8953
movq 0x4686(%rip), %rax      # 0xcfe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x8988
movq 0x4670(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x25aa(%rip), %rsi      # 0xaf1c
movb $0x0, %al
callq 0x2330
callq 0x86d0
movl $0x1, %edi
callq 0x2290
movl -0x8(%rbp), %eax
movq 0x464e(%rip), %rcx      # 0xcfe0
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8a6a
cmpq $0x0, 0x4929(%rip)      # 0xd2d0
je 0x89ca
movq 0x4920(%rip), %rdi      # 0xd2d0
leaq 0x1f5c(%rip), %rsi      # 0xa913
callq 0x2320
cmpl $0x0, %eax
jne 0x89ca
movl $0x0, -0x14(%rbp)
jmp 0x8a0c
movq 0x460f(%rip), %rax      # 0xcfe0
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x8a0a
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1f22(%rip), %rsi      # 0xa913
callq 0x2320
cmpl $0x0, %eax
jne 0x89fd
jmp 0x8a0a
jmp 0x89ff
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x89d6
jmp 0x8a0c
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x8a68
jmp 0x8a16
movq 0x45bb(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1def(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movq 0x45a3(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x24fc(%rip), %rsi      # 0xaf3b
movb $0x0, %al
callq 0x2330
movq 0x458b(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1dbf(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movl $0x1, %edi
callq 0x2290
jmp 0x8a6a
cmpl $0x0, 0x4837(%rip)      # 0xd2a8
je 0x8ae9
cmpq $0x0, 0x4855(%rip)      # 0xd2d0
je 0x8ae9
movq 0x484c(%rip), %rdi      # 0xd2d0
leaq 0x1e88(%rip), %rsi      # 0xa913
callq 0x2320
cmpl $0x0, %eax
jne 0x8ae9
jmp 0x8a97
movq 0x453a(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1d6e(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movq 0x4522(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x24b9(%rip), %rsi      # 0xaf79
movb $0x0, %al
callq 0x2330
movq 0x450a(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1d3e(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movl $0x1, %edi
callq 0x2290
movl $0x2, %edi
callq 0x2410
cmpl $0x0, %eax
jne 0x8b15
cmpl $0x0, 0x47a9(%rip)      # 0xd2a8
jne 0x8b15
movl $0x1, 0x4791(%rip)      # 0xd29c
movl $0x0, 0x474b(%rip)      # 0xd260
cmpl $0x0, 0x4744(%rip)      # 0xd260
je 0x8b92
xorl %edi, %edi
callq 0x2410
cmpl $0x0, %eax
jne 0x8b7f
xorl %eax, %eax
movl %eax, %edi
callq 0x23f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1cf0(%rip), %rsi      # 0xa832
callq 0x2270
movq %rax, 0x49da(%rip)      # 0xd528
cmpq $0x0, 0x49d2(%rip)      # 0xd528
jne 0x8b7d
cmpl $0x1, 0x4745(%rip)      # 0xd2a4
jb 0x8b73
movq -0x20(%rbp), %rsi
leaq 0x243f(%rip), %rdi      # 0xafab
movb $0x0, %al
callq 0x42b0
movl $0x0, 0x46e3(%rip)      # 0xd260
jmp 0x8b90
movq 0x444a(%rip), %rax      # 0xcfd0
movq (%rax), %rax
movq %rax, 0x4998(%rip)      # 0xd528
jmp 0x8b92
cmpl $0x2, 0x4707(%rip)      # 0xd2a0
je 0x8ba8
cmpl $0x3, 0x46fe(%rip)      # 0xd2a0
jne 0x8c37
cmpl $0x0, 0x4729(%rip)      # 0xd2d8
jne 0x8c37
callq 0x2030
movl $0x0, (%rax)
movl $0xa, %edi
callq 0x2220
callq 0x2030
cmpl $0x0, (%rax)
jne 0x8bf3
cmpl $0x1, 0x46c9(%rip)      # 0xd2a4
jb 0x8bf3
movq 0x43f4(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x23d1(%rip), %rdi      # 0xafbf
callq 0x2240
callq 0x2350
movl %eax, %edx
movl $0xfb, %edi
movl $0x1, %esi
movl $0x6007, %ecx           # imm = 0x6007
movb $0x0, %al
callq 0x2040
cmpq $0x0, %rax
jne 0x8c35
cmpl $0x1, 0x4687(%rip)      # 0xd2a4
jb 0x8c35
movq 0x43b2(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x23a3(%rip), %rdi      # 0xafd3
callq 0x2240
jmp 0x8c37
cmpl $0x1, 0x4662(%rip)      # 0xd2a0
je 0x8c49
cmpl $0x2, 0x4659(%rip)      # 0xd2a0
jne 0x8c4e
callq 0x6100
movq 0x438b(%rip), %rax      # 0xcfe0
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x8d3d
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x48bf(%rip)      # 0xd538
movl -0x8(%rbp), %eax
movq 0x435d(%rip), %rcx      # 0xcfe0
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8cab
movq 0x4345(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
movq 0x489b(%rip), %rdx      # 0xd538
leaq 0x234d(%rip), %rsi      # 0xaff1
movb $0x0, %al
callq 0x2330
callq 0x6f80
callq 0x85c0
movq 0x4624(%rip), %rdi      # 0xd2e0
callq 0x21f0
cmpl $0x0, %eax
je 0x8d23
jmp 0x8cc8
movq 0x4309(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1b3d(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movq 0x42f1(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x230d(%rip), %rsi      # 0xaffe
movb $0x0, %al
callq 0x2330
movq 0x42d9(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x1aa0(%rip), %rsi      # 0xa7a9
movb $0x0, %al
callq 0x2330
xorl %eax, %eax
movl %eax, %edi
callq 0x2180
movl $0x1, %edi
callq 0x2290
movq 0x45ce(%rip), %rdi      # 0xd2f8
callq 0x2280
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8c5a
xorl %edi, %edi
callq 0x2290