// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl %edi, %ebx
movq 0x6433(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x338a(%rip), %rdi      # 0x9f39
callq 0x2250
leaq 0x3399(%rip), %r15      # 0x9f54
movq 0x63fe(%rip), %rbp      # 0xcfc0
leaq 0x2587(%rip), %r13      # 0x9150
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2070
cmpl $0x53, %eax
jle 0x6c02
leal -0x65(%rax), %ecx
cmpl $0x14, %ecx
ja 0x6c2a
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%rbp), %r12
movq %r12, %rdi
callq 0x2450
movq %rax, 0x66b0(%rip)      # 0xd2b0
jmp 0x6c57
cmpl $0x44, %eax
je 0x6c1d
cmpl $0x4f, %eax
jne 0x6ceb
movq (%rbp), %rax
movq %rax, 0x66b5(%rip)      # 0xd2d0
jmp 0x6bc9
movq (%rbp), %rax
movq %rax, 0x66a0(%rip)      # 0xd2c8
jmp 0x6bc9
cmpl $0x54, %eax
jne 0x6dd5
movq (%rbp), %rdi
callq 0x2390
movl %eax, 0x6696(%rip)      # 0xd2d8
jmp 0x6bc9
movq (%rbp), %r12
movq %r12, %rdi
callq 0x2450
movq %rax, 0x6661(%rip)      # 0xd2b8
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
movl $0x78, %esi
movq %rax, %rdx
callq 0x2100
jmp 0x6bc9
movl $0x0, 0x6612(%rip)      # 0xd290
jmp 0x6bc9
movb $0x1, 0x660e(%rip)      # 0xd298
jmp 0x6bc9
movq (%rbp), %rax
movq %rax, 0x6626(%rip)      # 0xd2c0
jmp 0x6bc9
movl $0x1, 0x65e7(%rip)      # 0xd290
jmp 0x6bc9
movl $0x2, 0x65d8(%rip)      # 0xd290
jmp 0x6bc9
movb $0x1, %al
movb %al, 0x65db(%rip)       # 0xd2a0
movb %al, 0x685d(%rip)       # 0xd528
jmp 0x6bc9
movb $0x1, 0x65d1(%rip)      # 0xd2a8
jmp 0x6bc9
movl $0x3, 0x65aa(%rip)      # 0xd290
jmp 0x6bc9
cmpl $-0x1, %eax
jne 0x6dd5
cmpb $0x1, 0x659d(%rip)      # 0xd298
movq 0x62d6(%rip), %rbp      # 0xcfd8
jne 0x6d50
movq (%rbp), %rsi
leaq 0x325a(%rip), %rdi      # 0x9f69
callq 0x2250
testl %ebx, %ebx
jle 0x6d50
leal -0x1(%rbx), %r15d
movl %ebx, %r12d
xorl %r13d, %r13d
movq (%r14,%r13,8), %rdi
movq (%rbp), %rsi
callq 0x2250
cmpq %r13, %r15
movl $0x20, %edi
movl $0xa, %eax
cmovel %eax, %edi
movq (%rbp), %rsi
callq 0x22d0
incq %r13
cmpq %r13, %r12
jne 0x6d22
movq 0x6289(%rip), %r12      # 0xcfe0
movl (%r12), %ecx
cmpl %ebx, %ecx
jge 0x6db5
leal 0x1(%rcx), %edx
movq 0x6567(%rip), %rax      # 0xd2d0
cmpl %ebx, %edx
movq 0x6266(%rip), %r13      # 0xcfd8
jge 0x6e0a
testq %rax, %rax
je 0x6d8a
cmpb $0x2d, (%rax)
jne 0x6d8a
xorl %edx, %edx
cmpb $0x0, 0x1(%rax)
je 0x6de6
movslq %ecx, %rdx
leaq (%r14,%rdx,8), %rdx
movq (%rdx), %rsi
cmpb $0x2d, (%rsi)
jne 0x6d9f
cmpb $0x0, 0x1(%rsi)
je 0x6de4
incl %ecx
addq $0x8, %rdx
cmpl %ecx, %ebx
jne 0x6d91
jmp 0x6e0a
callq 0x2a6e
jmp 0x7006
movq 0x621c(%rip), %rax      # 0xcfd8
movq (%rax), %rcx
leaq 0x31b2(%rip), %rdi      # 0x9f78
movl $0x1e, %esi
movl $0x1, %edx
callq 0x2480
callq 0x2a6e
movl $0x1, %edi
callq 0x22a0
movl %ecx, %edx
cmpl %ebx, %edx
jge 0x6e0a
movq (%r13), %rsi
movl $0xa, %edi
callq 0x22d0
movq (%r13), %rcx
leaq 0x3194(%rip), %rdi      # 0x9f97
movl $0x3d, %esi
jmp 0x6e44
testq %rax, %rax
setne %cl
andb 0x648a(%rip), %cl       # 0xd2a0
cmpb $0x1, %cl
jne 0x6e61
cmpb $0x2d, (%rax)
jne 0x6e61
cmpb $0x0, 0x1(%rax)
jne 0x6e61
movq (%r13), %rsi
movl $0xa, %edi
callq 0x22d0
movq (%r13), %rcx
leaq 0x3196(%rip), %rdi      # 0x9fd5
movl $0x31, %esi
movl $0x1, %edx
callq 0x2480
movq (%r13), %rsi
movl $0xa, %edi
callq 0x22d0
jmp 0x6dda
movl $0x2, %edi
callq 0x2420
testl %eax, %eax
jne 0x6e88
testb $0x1, 0x642a(%rip)      # 0xd2a0
jne 0x6e88
movb $0x1, %al
movb %al, 0x640c(%rip)       # 0xd28c
movb %al, 0x66a2(%rip)       # 0xd528
jmp 0x6ef5
cmpb $0x0, 0x6699(%rip)      # 0xd528
jne 0x6ef5
xorl %edi, %edi
callq 0x2420
testl %eax, %eax
jne 0x6ee4
xorl %edi, %edi
callq 0x2400
movq %rax, %r15
leaq 0x29e3(%rip), %rsi      # 0x9890
movq %rax, %rdi
callq 0x2280
movq %rax, 0x6674(%rip)      # 0xd530
testq %rax, %rax
jne 0x6ef5
cmpb $0x1, 0x63d0(%rip)      # 0xd298
jne 0x6edb
leaq 0x3136(%rip), %rdi      # 0xa007
movq %r15, %rsi
xorl %eax, %eax
callq 0x24a0
movb $0x1, 0x6646(%rip)      # 0xd528
jmp 0x6ef5
movq 0x60e5(%rip), %rax      # 0xcfd0
movq (%rax), %rax
movq %rax, 0x663b(%rip)      # 0xd530
movl 0x6395(%rip), %eax      # 0xd290
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x6f7e
cmpl $0x0, 0x63ce(%rip)      # 0xd2d8
jne 0x6f7e
callq 0x2030
movq %rax, %r15
movl $0x0, (%rax)
movl $0xa, %edi
callq 0x2230
cmpl $0x0, (%r15)
jne 0x6f43
testb $0x1, 0x6367(%rip)      # 0xd298
je 0x6f43
movq (%r13), %rsi
leaq 0x30dd(%rip), %rdi      # 0xa01b
callq 0x2250
callq 0x2360
movl $0xfb, %edi
movl $0x1, %esi
movl %eax, %edx
movl $0x6007, %ecx           # imm = 0x6007
xorl %eax, %eax
callq 0x2040
testq %rax, %rax
jne 0x6f7e
testb $0x1, 0x632c(%rip)      # 0xd298
je 0x6f7e
movq (%r13), %rsi
leaq 0x30b6(%rip), %rdi      # 0xa02f
callq 0x2250
movl 0x630c(%rip), %eax      # 0xd290
decl %eax
cmpl $0x1, %eax
ja 0x6f90
callq 0x598f
movslq (%r12), %rax
cmpl %eax, %ebx
jle 0x7006
leaq (%r14,%rax,8), %r15
movl %ebx, %r13d
subl %eax, %r13d
leaq 0x30a4(%rip), %r14      # 0xa04d
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rdx
movq %rdx, 0x658a(%rip)      # 0xd540
movl (%r12), %eax
incl %eax
cmpl %ebx, %eax
jl 0x6ff0
callq 0x60c3
callq 0x6ac7
movq 0x630f(%rip), %rdi      # 0xd2e0
callq 0x21f0
testl %eax, %eax
jne 0x700d
movq 0x6317(%rip), %rdi      # 0xd2f8
callq 0x2290
incq %rbp
cmpl %ebp, %r13d
jne 0x6fab
jmp 0x7006
movq 0x5fe1(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2340
jmp 0x6fc0
xorl %edi, %edi
callq 0x22a0
movq 0x5fc4(%rip), %rbx      # 0xcfd8
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x22d0
movq (%rbx), %rcx
leaq 0x302f(%rip), %rdi      # 0xa05a
movl $0x12, %esi
movl $0x1, %edx
callq 0x2480
movq (%rbx), %rcx
leaq 0x27c3(%rip), %rdi      # 0x9807
movl $0x2, %esi
movl $0x1, %edx
callq 0x2480
xorl %edi, %edi
callq 0x2180
jmp 0x6dda