// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r14d
movq 0x5d48(%rip), %rax      # 0xbfd8
movq (%rax), %rsi
leaq 0x2bcf(%rip), %rdi      # 0x8e69
callq 0x2250
leaq 0x2bde(%rip), %r15      # 0x8e84
movq 0x5d13(%rip), %r13      # 0xbfc0
leaq 0x1dcc(%rip), %rbp      # 0x8080
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2070
leal -0x65(%rax), %ecx
cmpl $0x14, %ecx
ja 0x62ec
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
movq (%r13), %r12
movq %r12, %rdi
callq 0x2450
movq %rax, 0x5fc9(%rip)      # 0xc2b0
jmp 0x638a
cmpl $0x44, %eax
je 0x63c4
cmpl $0x4f, %eax
je 0x63b4
cmpl $0x54, %eax
jne 0x63d4
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x5fc2(%rip)      # 0xc2d8
jmp 0x62b4
movb $0x1, 0x5f79(%rip)      # 0xc298
jmp 0x62b4
andl $0x0, 0x5f68(%rip)      # 0xc290
jmp 0x62b4
movl $0x1, 0x5f5c(%rip)      # 0xc290
jmp 0x62b4
movq (%r13), %rax
movq %rax, 0x5f7c(%rip)      # 0xc2c0
jmp 0x62b4
movb $0x1, %al
movb %al, 0x5f4f(%rip)       # 0xc2a0
movb %al, 0x61d1(%rip)       # 0xc528
jmp 0x62b4
movl $0x2, 0x5f2a(%rip)      # 0xc290
jmp 0x62b4
movb $0x1, 0x5f36(%rip)      # 0xc2a8
jmp 0x62b4
movq (%r13), %r12
movq %r12, %rdi
callq 0x2450
movq %rax, 0x5f2e(%rip)      # 0xc2b8
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
pushq $0x78
popq %rsi
movq %rax, %rdx
callq 0x2100
jmp 0x62b4
movl $0x3, 0x5ee1(%rip)      # 0xc290
jmp 0x62b4
movq (%r13), %rax
movq %rax, 0x5f11(%rip)      # 0xc2d0
jmp 0x62b4
movq (%r13), %rax
movq %rax, 0x5ef9(%rip)      # 0xc2c8
jmp 0x62b4
cmpl $-0x1, %eax
jne 0x64be
cmpb $0x1, 0x5eb4(%rip)      # 0xc298
jne 0x6443
movq 0x5beb(%rip), %rax      # 0xbfd8
movq (%rax), %rsi
leaq 0x2aa2(%rip), %rdi      # 0x8e99
callq 0x2250
leal -0x1(%r14), %r15d
xorl %r12d, %r12d
testl %r14d, %r14d
movl $0x0, %r13d
cmovgl %r14d, %r13d
cmpq %r12, %r13
je 0x6443
movq (%rbx,%r12,8), %rdi
movq 0x5bb8(%rip), %rbp      # 0xbfd8
movq (%rbp), %rsi
callq 0x2250
cmpq %r12, %r15
pushq $0x20
popq %rdi
pushq $0xa
popq %rax
cmovel %eax, %edi
movq (%rbp), %rsi
callq 0x22d0
incq %r12
jmp 0x6410
movq 0x5b96(%rip), %r12      # 0xbfe0
movslq (%r12), %rcx
cmpl %r14d, %ecx
jge 0x64a2
leal 0x1(%rcx), %edx
movq 0x5e73(%rip), %rax      # 0xc2d0
movslq %r14d, %rbp
cmpl %r14d, %edx
jge 0x64f4
testq %rax, %rax
je 0x648f
cmpb $0x2d, (%rax)
jne 0x648f
xorl %edx, %edx
cmpb $0x0, 0x1(%rax)
jne 0x648f
jmp 0x64cd
movq (%rbx,%rcx,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x648c
cmpb $0x0, 0x1(%rdx)
je 0x64cb
incq %rcx
cmpq %rbp, %rcx
jl 0x647d
jmp 0x64f4
callq 0x6262
xorl %edi, %edi
callq 0x22a0
movq 0x5b2f(%rip), %rax      # 0xbfd8
movq (%rax), %rcx
leaq 0x29f5(%rip), %rdi      # 0x8ea8
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
callq 0x6262
pushq $0x1
popq %rdi
callq 0x22a0
movl %ecx, %edx
cmpl %r14d, %edx
jge 0x64f4
movq 0x5aff(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x29d7(%rip), %rdi      # 0x8ec7
pushq $0x3d
jmp 0x6530
testq %rax, %rax
setne %cl
andb 0x5da0(%rip), %cl       # 0xc2a0
cmpb $0x1, %cl
jne 0x6548
cmpb $0x2d, (%rax)
jne 0x6548
cmpb $0x0, 0x1(%rax)
jne 0x6548
movq 0x5ac1(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x29d7(%rip), %rdi      # 0x8f05
pushq $0x31
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%r14), %rsi
movl %ebx, %edi
callq 0x22d0
jmp 0x64c3
pushq $0x2
popq %rdi
callq 0x2420
testl %eax, %eax
jne 0x656d
testb $0x1, 0x5d45(%rip)      # 0xc2a0
jne 0x656d
movb $0x1, %al
movb %al, 0x5d27(%rip)       # 0xc28c
movb %al, 0x5fbd(%rip)       # 0xc528
jmp 0x65da
cmpb $0x0, 0x5fb4(%rip)      # 0xc528
jne 0x65da
xorl %edi, %edi
callq 0x2420
testl %eax, %eax
jne 0x65c9
xorl %edi, %edi
callq 0x2400
movq %rax, %r15
leaq 0x222e(%rip), %rsi      # 0x87c0
movq %rax, %rdi
callq 0x2280
movq %rax, 0x5f8f(%rip)      # 0xc530
testq %rax, %rax
jne 0x65da
cmpb $0x1, 0x5ceb(%rip)      # 0xc298
jne 0x65c0
leaq 0x2981(%rip), %rdi      # 0x8f37
movq %r15, %rsi
xorl %eax, %eax
callq 0x3520
movb $0x1, 0x5f61(%rip)      # 0xc528
jmp 0x65da
movq 0x5a00(%rip), %rax      # 0xbfd0
movq (%rax), %rax
movq %rax, 0x5f56(%rip)      # 0xc530
movl 0x5cb0(%rip), %eax      # 0xc290
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x666c
cmpl $0x0, 0x5ce5(%rip)      # 0xc2d8
jne 0x666c
callq 0x2030
movq %rax, %r15
andl $0x0, (%rax)
pushq $0xa
popq %rdi
callq 0x2230
cmpl $0x0, (%r15)
jne 0x662d
testb $0x1, 0x5c83(%rip)      # 0xc298
je 0x662d
movq 0x59ba(%rip), %rax      # 0xbfd8
movq (%rax), %rsi
leaq 0x2923(%rip), %rdi      # 0x8f4b
callq 0x2250
callq 0x2360
pushq $0x1
popq %rsi
movl $0xfb, %edi
movl %eax, %edx
movl $0x6007, %ecx           # imm = 0x6007
xorl %eax, %eax
callq 0x2040
testq %rax, %rax
jne 0x666c
testb $0x1, 0x5c44(%rip)      # 0xc298
je 0x666c
movq 0x597b(%rip), %rax      # 0xbfd8
movq (%rax), %rsi
leaq 0x28f8(%rip), %rdi      # 0x8f5f
callq 0x2250
movl 0x5c1e(%rip), %eax      # 0xc290
decl %eax
cmpl $0x1, %eax
ja 0x667e
callq 0x493a
movslq (%r12), %r13
leaq 0x28f4(%rip), %r15      # 0x8f7d
cmpq %rbp, %r13
jge 0x649b
movq (%rbx,%r13,8), %rdx
movq %rdx, 0x5ea3(%rip)      # 0xc540
movl (%r12), %eax
incl %eax
cmpl %r14d, %eax
jl 0x66d3
callq 0x5413
callq 0x6193
movq 0x5c27(%rip), %rdi      # 0xc2e0
callq 0x21f0
testl %eax, %eax
jne 0x66e9
movq 0x5c2f(%rip), %rdi      # 0xc2f8
callq 0x2290
incq %r13
jmp 0x6689
movq 0x58fe(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2340
jmp 0x66a8
movq 0x58e8(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x22d0
movq (%r14), %rcx
leaq 0x2885(%rip), %rdi      # 0x8f8a
pushq $0x12
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2480
movq (%r14), %rcx
leaq 0x201a(%rip), %rdi      # 0x8737
pushq $0x2
popq %rsi
movq %rbx, %rdx
callq 0x2480
xorl %edi, %edi
callq 0x2180
jmp 0x64c3