// File: /workspace/github_c_makefile_star2_O1/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 0x56ab(%rip), %rax      # 0xbfd8
movq (%rax), %rsi
leaq 0x2534(%rip), %rdi      # 0x8e6b
callq 0x2240
leaq 0x2543(%rip), %r15      # 0x8e86
movq 0x5676(%rip), %rbp      # 0xbfc0
leaq 0x172f(%rip), %r13      # 0x8080
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2070
cmpl $0x53, %eax
jle 0x698a
leal -0x65(%rax), %ecx
cmpl $0x14, %ecx
ja 0x69b2
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%rbp), %r12
movq %r12, %rdi
callq 0x2440
movq %rax, 0x5918(%rip)      # 0xc2a0
jmp 0x69df
cmpl $0x44, %eax
je 0x69a5
cmpl $0x4f, %eax
jne 0x6a73
movq (%rbp), %rax
movq %rax, 0x591d(%rip)      # 0xc2c0
jmp 0x6951
movq (%rbp), %rax
movq %rax, 0x5908(%rip)      # 0xc2b8
jmp 0x6951
cmpl $0x54, %eax
jne 0x6b71
movq (%rbp), %rdi
callq 0x2380
movl %eax, 0x58fe(%rip)      # 0xc2c8
jmp 0x6951
movq (%rbp), %r12
movq %r12, %rdi
callq 0x2440
movq %rax, 0x58c9(%rip)      # 0xc2a8
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
movl $0x78, %esi
movq %rax, %rdx
callq 0x2100
jmp 0x6951
movl $0x0, 0x587a(%rip)      # 0xc280
jmp 0x6951
movb $0x1, 0x5876(%rip)      # 0xc288
jmp 0x6951
movq (%rbp), %rax
movq %rax, 0x588e(%rip)      # 0xc2b0
jmp 0x6951
movl $0x1, 0x584f(%rip)      # 0xc280
jmp 0x6951
movl $0x2, 0x5840(%rip)      # 0xc280
jmp 0x6951
movb $0x1, %al
movb %al, 0x5843(%rip)       # 0xc290
movb %al, 0x5ac5(%rip)       # 0xc518
jmp 0x6951
movb $0x1, 0x5839(%rip)      # 0xc298
jmp 0x6951
movl $0x3, 0x5812(%rip)      # 0xc280
jmp 0x6951
cmpl $-0x1, %eax
jne 0x6b71
cmpb $0x1, 0x5805(%rip)      # 0xc288
movq 0x554e(%rip), %rbp      # 0xbfd8
jne 0x6ad8
movq (%rbp), %rsi
leaq 0x2404(%rip), %rdi      # 0x8e9b
callq 0x2240
testl %ebx, %ebx
jle 0x6ad8
leal -0x1(%rbx), %r15d
movl %ebx, %r12d
xorl %r13d, %r13d
movq (%r14,%r13,8), %rdi
movq (%rbp), %rsi
callq 0x2240
cmpq %r13, %r15
movl $0x20, %edi
movl $0xa, %eax
cmovel %eax, %edi
movq (%rbp), %rsi
callq 0x22c0
incq %r13
cmpq %r13, %r12
jne 0x6aaa
movq 0x5501(%rip), %r12      # 0xbfe0
movl (%r12), %r13d
cmpl %ebx, %r13d
jge 0x6b51
leal 0x1(%r13), %eax
cmpl %ebx, %eax
jge 0x6bac
movq 0x57c5(%rip), %rdi      # 0xc2c0
testq %rdi, %rdi
je 0x6b12
leaq 0x1d9a(%rip), %rsi      # 0x88a1
callq 0x2320
xorl %ecx, %ecx
testl %eax, %eax
je 0x6b83
cmpl %ebx, %r13d
jge 0x6b80
movslq %r13d, %rax
leaq (%r14,%rax,8), %rbp
leaq 0x1d7c(%rip), %r15      # 0x88a1
movq (%rbp), %rdi
movq %r15, %rsi
callq 0x2320
testl %eax, %eax
je 0x6b80
incl %r13d
addq $0x8, %rbp
cmpl %r13d, %ebx
jne 0x6b25
movl %ebx, %ecx
jmp 0x6b83
callq 0x2891
xorl %edi, %edi
callq 0x2290
movq 0x5480(%rip), %rax      # 0xbfd8
movq (%rax), %rcx
leaq 0x2348(%rip), %rdi      # 0x8eaa
movl $0x1e, %esi
movl $0x1, %edx
callq 0x2470
callq 0x2891
movl $0x1, %edi
callq 0x2290
movl %r13d, %ecx
cmpl %ebx, %ecx
jge 0x6bac
movq 0x544a(%rip), %rbx      # 0xbfd8
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x22c0
movq (%rbx), %rcx
leaq 0x2324(%rip), %rdi      # 0x8ec9
movl $0x3d, %esi
jmp 0x6bf6
movq 0x570d(%rip), %rdi      # 0xc2c0
testq %rdi, %rdi
setne %al
andb 0x56d1(%rip), %al       # 0xc290
cmpb $0x1, %al
jne 0x6c12
leaq 0x1cd7(%rip), %rsi      # 0x88a1
callq 0x2320
testl %eax, %eax
jne 0x6c12
movq 0x53fe(%rip), %rbx      # 0xbfd8
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x22c0
movq (%rbx), %rcx
leaq 0x2316(%rip), %rdi      # 0x8f07
movl $0x31, %esi
movl $0x1, %edx
callq 0x2470
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x22c0
jmp 0x6b76
movl $0x2, %edi
callq 0x2410
testl %eax, %eax
movq 0x53b3(%rip), %r13      # 0xbfd8
jne 0x6c3e
testb $0x1, 0x5662(%rip)      # 0xc290
jne 0x6c3e
movb $0x1, %al
movb %al, 0x5644(%rip)       # 0xc27c
movb %al, 0x58da(%rip)       # 0xc518
cmpb $0x0, 0x58d3(%rip)      # 0xc518
jne 0x6cab
xorl %edi, %edi
callq 0x2410
testl %eax, %eax
jne 0x6c9a
xorl %edi, %edi
callq 0x23f0
movq %rax, %r15
leaq 0x1b5d(%rip), %rsi      # 0x87c0
movq %rax, %rdi
callq 0x2270
movq %rax, 0x58ae(%rip)      # 0xc520
testq %rax, %rax
jne 0x6cab
cmpb $0x1, 0x560a(%rip)      # 0xc288
jne 0x6c91
leaq 0x22b2(%rip), %rdi      # 0x8f39
movq %r15, %rsi
xorl %eax, %eax
callq 0x2490
movb $0x1, 0x5880(%rip)      # 0xc518
jmp 0x6cab
movq 0x532f(%rip), %rax      # 0xbfd0
movq (%rax), %rax
movq %rax, 0x5875(%rip)      # 0xc520
movl 0x55cf(%rip), %eax      # 0xc280
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x6d34
cmpl $0x0, 0x5608(%rip)      # 0xc2c8
jne 0x6d34
callq 0x2030
movq %rax, %r15
movl $0x0, (%rax)
movl $0xa, %edi
callq 0x2220
cmpl $0x0, (%r15)
jne 0x6cf9
testb $0x1, 0x55a1(%rip)      # 0xc288
je 0x6cf9
movq (%r13), %rsi
leaq 0x2259(%rip), %rdi      # 0x8f4d
callq 0x2240
callq 0x2350
movl $0xfb, %edi
movl $0x1, %esi
movl %eax, %edx
movl $0x6007, %ecx           # imm = 0x6007
xorl %eax, %eax
callq 0x2040
testq %rax, %rax
jne 0x6d34
testb $0x1, 0x5566(%rip)      # 0xc288
je 0x6d34
movq (%r13), %rsi
leaq 0x2232(%rip), %rdi      # 0x8f61
callq 0x2240
movl 0x5546(%rip), %eax      # 0xc280
decl %eax
cmpl $0x1, %eax
ja 0x6d46
callq 0x5796
movslq (%r12), %rax
cmpl %eax, %ebx
jle 0x6b4a
leaq (%r14,%rax,8), %r15
movl %ebx, %r13d
subl %eax, %r13d
leaq 0x221c(%rip), %r14      # 0x8f7f
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rdx
movq %rdx, 0x57c0(%rip)      # 0xc530
movl (%r12), %eax
incl %eax
cmpl %ebx, %eax
jl 0x6dad
callq 0x5e6a
callq 0x6847
movq 0x5545(%rip), %rdi      # 0xc2d0
callq 0x21e0
testl %eax, %eax
jne 0x6dc3
movq 0x554d(%rip), %rdi      # 0xc2e8
callq 0x2280
incq %rbp
cmpl %ebp, %r13d
jne 0x6d65
jmp 0x6b4a
movq 0x5224(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2330
jmp 0x6d7a
movq 0x520e(%rip), %rbx      # 0xbfd8
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x22c0
movq (%rbx), %rcx
leaq 0x21ab(%rip), %rdi      # 0x8f8c
movl $0x12, %esi
movl $0x1, %edx
callq 0x2470
movq (%rbx), %rcx
leaq 0x193d(%rip), %rdi      # 0x8737
movl $0x2, %esi
movl $0x1, %edx
callq 0x2470
xorl %edi, %edi
callq 0x2170
jmp 0x6b76