#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fmea(int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ generateKeys(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int msb(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strtoll(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char usage[] =
      "rsa by Jason Giancono\nUSAGE: rsa <FLAG>\nFLAGS:\t\t-g: generate "
      "keys\n\t\t-d <input filename> <output filename> <key> <n modulo>: "
      "decrypt file using key and modulo and output to <output "
      "filename>\n\t\t-e <input filename> <output filename> <key> <n modulo>: "
      "encrypt file using key and modulo and output to <output filename>\n";
  srand(time(NULL));
  int error = 0;
  if ((argc != 1) && !strcmp(argv[1], "-g")) {
    uint64_t pub, priv, n;
    generateKeys(&pub, &priv, &n);
    printf("\nKeys:\t\t\tPublic: \t%llu\n\t\t\tPrivate: \t%llu\n\t\t\tN: "
           "\t\t%llu\n",
           pub, priv, n);
  } else if (argc == 6) {
    uint64_t key, n;
    FILE *input, *output;
    input = fopen(argv[2], "r");
    output = fopen(argv[3], "w");
    key = strtoll(argv[4], NULL, 10);
    n = strtoll(argv[5], NULL, 10);
    int arraySize = (msb(n) - 1) / 8;
    if (output != NULL) {
      if (input != NULL) {
        if (!strcmp(argv[1], "-e")) {
          while ((!feof(input)) && !ferror(input) && !ferror(output)) {
            char block[8];
            memset(block, 0, 8);
            int ii;
            for (ii = 0; ii < arraySize; ii++) {
              block[ii] = getc(input);
            }
            uint64_t *m = (uint64_t *)block;
            *m = fmea(*m, key, n);
            for (ii = 0; ii < arraySize + 1; ii++) {
              putc(block[ii], output);
            }
          }
        } else if (!strcmp(argv[1], "-d")) {
          while ((!feof(input)) && !ferror(input) && !ferror(output)) {
            char block[8];
            memset(block, 0, 8);
            int ii;
            for (ii = 0; ii < arraySize + 1; ii++) {
              block[ii] = getc(input);
            }
            uint64_t *m = (uint64_t *)block;
            *m = fmea(*m, key, n);
            for (ii = 0; ii < (arraySize); ii++) {
              if (!feof(input) && (block[ii] != EOF))
                putc(block[ii], output);
            }
          }
        } else
          error = 1;
      } else
        error = 1;
    } else
      error = 1;
    if (error || ferror(output) || ferror(input)) {
      error = 1;
      perror("An Error Occurred");
      if (output != NULL)
        fclose(output);
      if (input != NULL)
        fclose(input);
    } else {
      fclose(output);
      fclose(input);
    }
  } else
    printf("Wrong number of args \n\n%s", usage);
  return error;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x150(%rbp),%rdi
lea    0xdc9(%rip),%rsi
mov    $0x13b,%edx
call   10d0 <memcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x0,-0x154(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     12c2 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xec7(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12c2 <main+0xb2>
lea    -0x158(%rbp),%rdi
lea    -0x15c(%rbp),%rsi
lea    -0x160(%rbp),%rdx
call   1120 <generateKeys@plt>
movslq -0x158(%rbp),%rsi
mov    -0x15c(%rbp),%edx
mov    -0x160(%rbp),%ecx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1795 <main+0x585>
cmpl   $0x6,-0x8(%rbp)
jne    177b <main+0x56b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe9a(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x170(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x178(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoll@plt>
mov    %eax,-0x164(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoll@plt>
mov    %eax,-0x168(%rbp)
mov    -0x168(%rbp),%edi
call   10c0 <msb@plt>
sub    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x17c(%rbp)
cmpq   $0x0,-0x178(%rbp)
je     16cc <main+0x4bc>
cmpq   $0x0,-0x170(%rbp)
je     16bd <main+0x4ad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    14f0 <main+0x2e0>
jmp    1394 <main+0x184>
mov    -0x170(%rbp),%rdi
call   10b0 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a9(%rbp)
jne    13ef <main+0x1df>
mov    -0x170(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1a9(%rbp)
jne    13ef <main+0x1df>
mov    -0x178(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x1a9(%rbp)
mov    -0x1a9(%rbp),%al
test   $0x1,%al
jne    1402 <main+0x1f2>
jmp    14eb <main+0x2db>
lea    -0x184(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
movl   $0x0,-0x188(%rbp)
mov    -0x188(%rbp),%eax
cmp    -0x17c(%rbp),%eax
jge    1461 <main+0x251>
mov    -0x170(%rbp),%rdi
call   1130 <getc@plt>
mov    %al,%cl
movslq -0x188(%rbp),%rax
mov    %cl,-0x184(%rbp,%rax,1)
mov    -0x188(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x188(%rbp)
jmp    141f <main+0x20f>
lea    -0x184(%rbp),%rax
mov    %rax,-0x190(%rbp)
mov    -0x190(%rbp),%rax
mov    (%rax),%edi
mov    -0x164(%rbp),%esi
mov    -0x168(%rbp),%edx
call   10f0 <fmea@plt>
mov    %eax,%ecx
mov    -0x190(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x188(%rbp)
mov    -0x188(%rbp),%eax
mov    -0x17c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    14e6 <main+0x2d6>
movslq -0x188(%rbp),%rax
mov    -0x184(%rbp,%rax,1),%al
mov    -0x178(%rbp),%rsi
movsbl %al,%edi
call   1090 <putc@plt>
mov    -0x188(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x188(%rbp)
jmp    149e <main+0x28e>
jmp    1394 <main+0x184>
jmp    16b8 <main+0x4a8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc7d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    16a9 <main+0x499>
jmp    1512 <main+0x302>
mov    -0x170(%rbp),%rdi
call   10b0 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1aa(%rbp)
jne    156d <main+0x35d>
mov    -0x170(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1aa(%rbp)
jne    156d <main+0x35d>
mov    -0x178(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x1aa(%rbp)
mov    -0x1aa(%rbp),%al
test   $0x1,%al
jne    1580 <main+0x370>
jmp    16a4 <main+0x494>
lea    -0x198(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
movl   $0x0,-0x19c(%rbp)
mov    -0x19c(%rbp),%eax
mov    -0x17c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    15e4 <main+0x3d4>
mov    -0x170(%rbp),%rdi
call   1130 <getc@plt>
mov    %al,%cl
movslq -0x19c(%rbp),%rax
mov    %cl,-0x198(%rbp,%rax,1)
mov    -0x19c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x19c(%rbp)
jmp    159d <main+0x38d>
lea    -0x198(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%rax
mov    (%rax),%edi
mov    -0x164(%rbp),%esi
mov    -0x168(%rbp),%edx
call   10f0 <fmea@plt>
mov    %eax,%ecx
mov    -0x1a8(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x19c(%rbp)
mov    -0x19c(%rbp),%eax
cmp    -0x17c(%rbp),%eax
jge    169f <main+0x48f>
mov    -0x170(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
jne    1686 <main+0x476>
movslq -0x19c(%rbp),%rax
movsbl -0x198(%rbp,%rax,1),%eax
ff
mov    0x298a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1686 <main+0x476>
movslq -0x19c(%rbp),%rax
mov    -0x198(%rbp,%rax,1),%al
mov    -0x178(%rbp),%rsi
movsbl %al,%edi
call   1090 <putc@plt>
jmp    168b <main+0x47b>
mov    -0x19c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x19c(%rbp)
jmp    1621 <main+0x411>
jmp    1512 <main+0x302>
jmp    16b3 <main+0x4a3>
movl   $0x1,-0x154(%rbp)
jmp    16b8 <main+0x4a8>
jmp    16c7 <main+0x4b7>
movl   $0x1,-0x154(%rbp)
jmp    16d6 <main+0x4c6>
movl   $0x1,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jne    170f <main+0x4ff>
mov    -0x178(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    170f <main+0x4ff>
mov    -0x170(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     175e <main+0x54e>
movl   $0x1,-0x154(%rbp)
lea    0xa5f(%rip),%rdi
call   1110 <perror@plt>
cmpq   $0x0,-0x178(%rbp)
je     173f <main+0x52f>
mov    -0x178(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x170(%rbp)
je     1759 <main+0x549>
mov    -0x170(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1776 <main+0x566>
mov    -0x178(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x170(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1790 <main+0x580>
lea    -0x150(%rbp),%rsi
lea    0xa08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1795 <main+0x585>
mov    -0x154(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xdd3(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    $0x13b,%edx
call   10d0 <memcpy@plt>
xor    %ebp,%ebp
xor    %edi,%edi
call   10e0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmp    $0x1,%ebx
je     1362 <main+0x152>
mov    0x8(%r15),%rdi
lea    0xedb(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1444 <main+0x234>
cmp    $0x6,%ebx
jne    1362 <main+0x152>
mov    0x10(%r15),%rdi
lea    0xef4(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%rbx
mov    0x18(%r15),%rdi
lea    0xee3(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%r14
mov    0x20(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoll@plt>
mov    %eax,0x24(%rsp)
mov    0x28(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoll@plt>
mov    %eax,0x20(%rsp)
mov    %eax,%edi
call   10c0 <msb@plt>
lea    -0x1(%rax),%edx
mov    %rax,%rcx
mov    %rax,0x10(%rsp)
lea    0x6(%rax),%r12d
test   %edx,%edx
cmovns %edx,%r12d
test   %r14,%r14
je     15cb <main+0x3bb>
test   %rbx,%rbx
je     14c8 <main+0x2b8>
sar    $0x3,%r12d
mov    0x8(%r15),%rbp
lea    0xe78(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
mov    %r14,0x18(%rsp)
je     1477 <main+0x267>
lea    0xe5f(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    14c8 <main+0x2b8>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1483 <main+0x273>
xor    %r14d,%r14d
test   %r12d,%r12d
cmovg  %r12d,%r14d
add    $0x1,%r14d
cmp    $0x2,%r12d
mov    $0x1,%r15d
cmovge %r12d,%r15d
mov    0x2c88(%rip),%r12
jmp    1390 <main+0x180>
lea    0xe28(%rip),%rdi
lea    0x30(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    14b4 <main+0x2a4>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1483 <main+0x273>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1483 <main+0x273>
mov    0x18(%rsp),%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1483 <main+0x273>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
cmpl   $0xfffffffa,0x10(%rsp)
jl     13e5 <main+0x1d5>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
call   1130 <getc@plt>
mov    %al,0x8(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    13d0 <main+0x1c0>
mov    0x8(%rsp),%edi
mov    0x24(%rsp),%esi
mov    0x20(%rsp),%edx
call   10f0 <fmea@plt>
mov    %eax,0x8(%rsp)
cmpl   $0x9,0x10(%rsp)
jl     1380 <main+0x170>
xor    %r13d,%r13d
jmp    141d <main+0x20d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%r15
je     1380 <main+0x170>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1410 <main+0x200>
movzbl 0x8(%rsp,%r13,1),%eax
cmp    (%r12),%al
je     1410 <main+0x200>
movsbl %al,%edi
mov    0x18(%rsp),%rsi
call   1090 <putc@plt>
jmp    1410 <main+0x200>
lea    0x8(%rsp),%rdi
lea    0x2c(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1120 <generateKeys@plt>
movslq 0x8(%rsp),%rsi
mov    0x2c(%rsp),%edx
mov    0x28(%rsp),%ecx
lea    0xcd2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
jmp    14b4 <main+0x2a4>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
je     14e1 <main+0x2d1>
mov    0x18(%rsp),%r14
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    14c8 <main+0x2b8>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    14c8 <main+0x2b8>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb0(%rip),%rdi
call   1110 <perror@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    15d7 <main+0x3c7>
cmp    $0x2,%r12d
mov    $0x1,%r13d
cmovge %r12d,%r13d
xor    %eax,%eax
test   %r12d,%r12d
cmovle %eax,%r12d
lea    0x8(%rsp),%r15
mov    0x18(%rsp),%r14
jmp    1520 <main+0x310>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1483 <main+0x273>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1483 <main+0x273>
mov    0x18(%rsp),%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1483 <main+0x273>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
cmpl   $0x9,0x10(%rsp)
jl     1575 <main+0x365>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1130 <getc@plt>
mov    %al,0x8(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1560 <main+0x350>
mov    0x8(%rsp),%edi
mov    0x24(%rsp),%esi
mov    0x20(%rsp),%edx
call   10f0 <fmea@plt>
mov    %eax,0x8(%rsp)
cmpl   $0xfffffffa,0x10(%rsp)
jl     1510 <main+0x300>
movsbl %al,%edi
mov    %r14,%rsi
call   1090 <putc@plt>
cmpl   $0x9,0x10(%rsp)
jl     1510 <main+0x300>
xor    %ebp,%ebp
nopl   (%rax)
movsbl 0x9(%rsp,%rbp,1),%edi
mov    %r14,%rsi
call   1090 <putc@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    15b0 <main+0x3a0>
jmp    1510 <main+0x300>
lea    0xbad(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
je     14b4 <main+0x2a4>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    14b4 <main+0x2a4>

LLVM IR (-O0):
@__const.main.usage = [315 x i8] c"rsa by Jason Giancono\0AUSAGE: rsa <FLAG>\0AFLAGS:\09\09-g: generate keys\0A\09\09-d <input filename> <output filename> <key> <n modulo>: decrypt file using key and modulo and output to <output filename>\0A\09\09-e <input filename> <output filename> <key> <n modulo>: encrypt file using key and modulo and output to <output filename>\0A\00"
@.str = [3 x i8] c"-g\00"
@.str.1 = [55 x i8] c"\0AKeys:\09\09\09Public: \09%llu\0A\09\09\09Private: \09%llu\0A\09\09\09N: \09\09%llu\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"-e\00"
@.str.5 = [3 x i8] c"-d\00"
@EOF = global i8 0
@.str.6 = [18 x i8] c"An Error Occurred\00"
@.str.7 = [26 x i8] c"Wrong number of args \0A\0A%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [315 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca [8 x i8]
%17 = alloca i32
%18 = alloca i32*
%19 = alloca [8 x i8]
%20 = alloca i32
%21 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = bitcast [315 x i8]* %6 to i8*
%23 = call i32 @time(i32* null)
%24 = call i32 @srand(i32 %23)
store i32 0, i32* %7
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %41
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %27
%34 = call i32 @generateKeys(i32* %8, i32* %9, i32* %10)
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i8*
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %37, i32 %38, i32 %39)
br label %253
41: ; preds = %27, %2
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 6
br i1 %43, label %44, label %249
44: ; preds = %41
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %48, i32** %13
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %52, i32** %14
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 4
%55 = load i8*, i8** %54
%56 = call i32 @strtoll(i8* %55, i32* null, i32 10)
store i32 %56, i32* %11
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 5
%59 = load i8*, i8** %58
%60 = call i32 @strtoll(i8* %59, i32* null, i32 10)
store i32 %60, i32* %12
%61 = load i32, i32* %12
%62 = call i32 @msb(i32 %61)
%63 = sub nsw i32 %62, 1
%64 = sdiv i32 %63, 8
store i32 %64, i32* %15
%65 = load i32*, i32** %14
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %217
67: ; preds = %44
%68 = load i32*, i32** %13
%69 = icmp ne i32* %68, null
br i1 %69, label %70, label %215
70: ; preds = %67
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 @strcmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%75 = icmp ne i32 %74, 0
br i1 %75, label %134, label %76
76: ; preds = %70
br label %77
77: ; preds = %132, %76
%78 = load i32*, i32** %13
%79 = call i32 @feof(i32* %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %90, label %81
81: ; preds = %77
%82 = load i32*, i32** %13
%83 = call i64 @ferror(i32* %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %90, label %85
85: ; preds = %81
%86 = load i32*, i32** %14
%87 = call i64 @ferror(i32* %86)
%88 = icmp ne i64 %87, 0
%89 = xor i1 %88, true
br label %90
90: ; preds = %85, %81, %77
%91 = phi i1 [ false, %81 ], [ false, %77 ], [ %89, %85 ]
br i1 %91, label %92, label %133
92: ; preds = %90
%93 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%94 = call i32 @memset(i8* %93, i32 0, i32 8)
store i32 0, i32* %17
br label %95
95: ; preds = %105, %92
%96 = load i32, i32* %17
%97 = load i32, i32* %15
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %108
99: ; preds = %95
%100 = load i32*, i32** %13
%101 = call signext i8 @getc(i32* %100)
%102 = load i32, i32* %17
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 %103
store i8 %101, i8* %104
br label %105
105: ; preds = %99
%106 = load i32, i32* %17
%107 = add nsw i32 %106, 1
store i32 %107, i32* %17
br label %95
108: ; preds = %95
%109 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%110 = bitcast i8* %109 to i32*
store i32* %110, i32** %18
%111 = load i32*, i32** %18
%112 = load i32, i32* %111
%113 = load i32, i32* %11
%114 = load i32, i32* %12
%115 = call i32 @fmea(i32 %112, i32 %113, i32 %114)
%116 = load i32*, i32** %18
store i32 %115, i32* %116
store i32 0, i32* %17
br label %117
117: ; preds = %129, %108
%118 = load i32, i32* %17
%119 = load i32, i32* %15
%120 = add nsw i32 %119, 1
%121 = icmp slt i32 %118, %120
br i1 %121, label %122, label %132
122: ; preds = %117
%123 = load i32, i32* %17
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 %124
%126 = load i8, i8* %125
%127 = load i32*, i32** %14
%128 = call i32 @putc(i8 signext %126, i32* %127)
br label %129
129: ; preds = %122
%130 = load i32, i32* %17
%131 = add nsw i32 %130, 1
store i32 %131, i32* %17
br label %117
132: ; preds = %117
br label %77
133: ; preds = %90
br label %214
134: ; preds = %70
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 1
%137 = load i8*, i8** %136
%138 = call i32 @strcmp(i8* %137, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%139 = icmp ne i32 %138, 0
br i1 %139, label %212, label %140
140: ; preds = %134
br label %141
141: ; preds = %210, %140
%142 = load i32*, i32** %13
%143 = call i32 @feof(i32* %142)
%144 = icmp ne i32 %143, 0
br i1 %144, label %154, label %145
145: ; preds = %141
%146 = load i32*, i32** %13
%147 = call i64 @ferror(i32* %146)
%148 = icmp ne i64 %147, 0
br i1 %148, label %154, label %149
149: ; preds = %145
%150 = load i32*, i32** %14
%151 = call i64 @ferror(i32* %150)
%152 = icmp ne i64 %151, 0
%153 = xor i1 %152, true
br label %154
154: ; preds = %149, %145, %141
%155 = phi i1 [ false, %145 ], [ false, %141 ], [ %153, %149 ]
br i1 %155, label %156, label %211
156: ; preds = %154
%157 = getelementptr inbounds [8 x i8], [8 x i8]* %19, i64 0, i64 0
%158 = call i32 @memset(i8* %157, i32 0, i32 8)
store i32 0, i32* %20
br label %159
159: ; preds = %170, %156
%160 = load i32, i32* %20
%161 = load i32, i32* %15
%162 = add nsw i32 %161, 1
%163 = icmp slt i32 %160, %162
br i1 %163, label %164, label %173
164: ; preds = %159
%165 = load i32*, i32** %13
%166 = call signext i8 @getc(i32* %165)
%167 = load i32, i32* %20
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [8 x i8], [8 x i8]* %19, i64 0, i64 %168
store i8 %166, i8* %169
br label %170
170: ; preds = %164
%171 = load i32, i32* %20
%172 = add nsw i32 %171, 1
store i32 %172, i32* %20
br label %159
173: ; preds = %159
%174 = getelementptr inbounds [8 x i8], [8 x i8]* %19, i64 0, i64 0
%175 = bitcast i8* %174 to i32*
store i32* %175, i32** %21
%176 = load i32*, i32** %21
%177 = load i32, i32* %176
%178 = load i32, i32* %11
%179 = load i32, i32* %12
%180 = call i32 @fmea(i32 %177, i32 %178, i32 %179)
%181 = load i32*, i32** %21
store i32 %180, i32* %181
store i32 0, i32* %20
br label %182
182: ; preds = %207, %173
%183 = load i32, i32* %20
%184 = load i32, i32* %15
%185 = icmp slt i32 %183, %184
br i1 %185, label %186, label %210
186: ; preds = %182
%187 = load i32*, i32** %13
%188 = call i32 @feof(i32* %187)
%189 = icmp ne i32 %188, 0
br i1 %189, label %206, label %190
190: ; preds = %186
%191 = load i32, i32* %20
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds [8 x i8], [8 x i8]* %19, i64 0, i64 %192
%194 = load i8, i8* %193
%195 = sext i8 %194 to i32
%196 = load i8, i8* @EOF
%197 = sext i8 %196 to i32
%198 = icmp ne i32 %195, %197
br i1 %198, label %199, label %206
199: ; preds = %190
%200 = load i32, i32* %20
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds [8 x i8], [8 x i8]* %19, i64 0, i64 %201
%203 = load i8, i8* %202
%204 = load i32*, i32** %14
%205 = call i32 @putc(i8 signext %203, i32* %204)
br label %206
206: ; preds = %199, %190, %186
br label %207
207: ; preds = %206
%208 = load i32, i32* %20
%209 = add nsw i32 %208, 1
store i32 %209, i32* %20
br label %182
210: ; preds = %182
br label %141
211: ; preds = %154
br label %213
212: ; preds = %134
store i32 1, i32* %7
br label %213
213: ; preds = %212, %211
br label %214
214: ; preds = %213, %133
br label %216
215: ; preds = %67
store i32 1, i32* %7
br label %216
216: ; preds = %215, %214
br label %218
217: ; preds = %44
store i32 1, i32* %7
br label %218
218: ; preds = %217, %216
%219 = load i32, i32* %7
%220 = icmp ne i32 %219, 0
br i1 %220, label %229, label %221
221: ; preds = %218
%222 = load i32*, i32** %14
%223 = call i64 @ferror(i32* %222)
%224 = icmp ne i64 %223, 0
br i1 %224, label %229, label %225
225: ; preds = %221
%226 = load i32*, i32** %13
%227 = call i64 @ferror(i32* %226)
%228 = icmp ne i64 %227, 0
br i1 %228, label %229, label %243
229: ; preds = %225, %221, %218
store i32 1, i32* %7
%230 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%231 = load i32*, i32** %14
%232 = icmp ne i32* %231, null
br i1 %232, label %233, label %236
233: ; preds = %229
%234 = load i32*, i32** %14
%235 = call i32 @fclose(i32* %234)
br label %236
236: ; preds = %233, %229
%237 = load i32*, i32** %13
%238 = icmp ne i32* %237, null
br i1 %238, label %239, label %242
239: ; preds = %236
%240 = load i32*, i32** %13
%241 = call i32 @fclose(i32* %240)
br label %242
242: ; preds = %239, %236
br label %248
243: ; preds = %225
%244 = load i32*, i32** %14
%245 = call i32 @fclose(i32* %244)
%246 = load i32*, i32** %13
%247 = call i32 @fclose(i32* %246)
br label %248
248: ; preds = %243, %242
br label %252
249: ; preds = %41
%250 = getelementptr inbounds [315 x i8], [315 x i8]* %6, i64 0, i64 0
%251 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %250)
br label %252
252: ; preds = %249, %248
br label %253
253: ; preds = %252, %33
%254 = load i32, i32* %7
ret i32 %254
}

LLVM IR (-O2):
@__const.main.usage = [315 x i8] c"rsa by Jason Giancono\0AUSAGE: rsa <FLAG>\0AFLAGS:\09\09-g: generate keys\0A\09\09-d <input filename> <output filename> <key> <n modulo>: decrypt file using key and modulo and output to <output filename>\0A\09\09-e <input filename> <output filename> <key> <n modulo>: encrypt file using key and modulo and output to <output filename>\0A\00"
@.str = [3 x i8] c"-g\00"
@.str.1 = [55 x i8] c"\0AKeys:\09\09\09Public: \09%llu\0A\09\09\09Private: \09%llu\0A\09\09\09N: \09\09%llu\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"-e\00"
@.str.5 = [3 x i8] c"-d\00"
@EOF = global i8 0
@.str.6 = [18 x i8] c"An Error Occurred\00"
@.str.7 = [26 x i8] c"Wrong number of args \0A\0A%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [315 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8 x i8]
%8 = alloca [8 x i8]
%9 = getelementptr inbounds [315 x i8], [315 x i8]* %3, i64 0, i64 0
%10 = tail call i32 @time(i32* null)
%11 = tail call i32 @srand(i32 %10)
%12 = icmp eq i32 %0, 1
br i1 %12, label %166, label %13
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = bitcast i32* %4 to i8*
%20 = bitcast i32* %5 to i8*
%21 = bitcast i32* %6 to i8*
%22 = call i32 @generateKeys(i32* %4, i32* %5, i32* %6)
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i8*
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26, i32 %27)
br label %168
29: ; preds = %13
%30 = icmp eq i32 %0, 6
br i1 %30, label %31, label %166
31: ; preds = %29
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = getelementptr inbounds i8*, i8** %1, i64 4
%39 = load i8*, i8** %38
%40 = tail call i32 @strtoll(i8* nocapture %39, i32* null, i32 10)
%41 = getelementptr inbounds i8*, i8** %1, i64 5
%42 = load i8*, i8** %41
%43 = tail call i32 @strtoll(i8* nocapture %42, i32* null, i32 10)
%44 = tail call i32 @msb(i32 %43)
%45 = add nsw i32 %44, -1
%46 = sdiv i32 %45, 8
%47 = icmp eq i32* %37, null
br i1 %47, label %157, label %48
48: ; preds = %31
%49 = icmp eq i32* %34, null
br i1 %49, label %154, label %50
50: ; preds = %48
%51 = load i8*, i8** %14
%52 = tail call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %98
54: ; preds = %50
%55 = call i32 @feof(i32* %34)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %148
57: ; preds = %54
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%59 = icmp sgt i32 %44, 8
%60 = bitcast [8 x i8]* %7 to i32*
%61 = icmp slt i32 %44, -6
%62 = call i32 @llvm.smax.i32(i32 %46, i32 1)
%63 = call i32 @llvm.smax.i32(i32 %46, i32 0)
%64 = add nuw nsw i32 %63, 1
%65 = zext i32 %62 to i64
%66 = zext i32 %64 to i64
%67 = icmp slt i32 %44, 9
br label %68
68: ; preds = %57, %95
%69 = call i64 @ferror(i32* %34)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %148
71: ; preds = %68
%72 = call i64 @ferror(i32* %37)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %148
74: ; preds = %71
%75 = call i32 @memset(i8* %58, i32 0, i32 8)
br i1 %59, label %76, label %82
76: ; preds = %74, %76
%77 = phi i64 [ %80, %76 ], [ 0, %74 ]
%78 = call signext i8 @getc(i32* %34)
%79 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %77
store i8 %78, i8* %79
%80 = add nuw nsw i64 %77, 1
%81 = icmp eq i64 %80, %65
br i1 %81, label %82, label %76
82: ; preds = %76, %74
%83 = load i32, i32* %60
%84 = call i32 @fmea(i32 %83, i32 %40, i32 %43)
store i32 %84, i32* %60
br i1 %61, label %95, label %85
85: ; preds = %82
%86 = trunc i32 %84 to i8
%87 = call i32 @putc(i8 signext %86, i32* %37)
br i1 %67, label %95, label %88
88: ; preds = %85, %88
%89 = phi i64 [ %93, %88 ], [ 1, %85 ]
%90 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %89
%91 = load i8, i8* %90
%92 = call i32 @putc(i8 signext %91, i32* %37)
%93 = add nuw nsw i64 %89, 1
%94 = icmp eq i64 %93, %66
br i1 %94, label %95, label %88
95: ; preds = %88, %85, %82
%96 = call i32 @feof(i32* %34)
%97 = icmp eq i32 %96, 0
br i1 %97, label %68, label %148
98: ; preds = %50
%99 = tail call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %154
101: ; preds = %98
%102 = call i32 @feof(i32* %34)
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %148
104: ; preds = %101
%105 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%106 = icmp slt i32 %44, -6
%107 = bitcast [8 x i8]* %8 to i32*
%108 = icmp sgt i32 %44, 8
%109 = call i32 @llvm.smax.i32(i32 %46, i32 0)
%110 = add nuw nsw i32 %109, 1
%111 = call i32 @llvm.smax.i32(i32 %46, i32 1)
%112 = zext i32 %110 to i64
%113 = zext i32 %111 to i64
br label %114
114: ; preds = %104, %145
%115 = call i64 @ferror(i32* %34)
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %148
117: ; preds = %114
%118 = call i64 @ferror(i32* %37)
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %148
120: ; preds = %117
%121 = call i32 @memset(i8* %105, i32 0, i32 8)
br i1 %106, label %128, label %122
122: ; preds = %120, %122
%123 = phi i64 [ %126, %122 ], [ 0, %120 ]
%124 = call signext i8 @getc(i32* %34)
%125 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %123
store i8 %124, i8* %125
%126 = add nuw nsw i64 %123, 1
%127 = icmp eq i64 %126, %112
br i1 %127, label %128, label %122
128: ; preds = %122, %120
%129 = load i32, i32* %107
%130 = call i32 @fmea(i32 %129, i32 %40, i32 %43)
store i32 %130, i32* %107
br i1 %108, label %131, label %145
131: ; preds = %128, %142
%132 = phi i64 [ %143, %142 ], [ 0, %128 ]
%133 = call i32 @feof(i32* %34)
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %142
135: ; preds = %131
%136 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %132
%137 = load i8, i8* %136
%138 = load i8, i8* @EOF
%139 = icmp eq i8 %137, %138
br i1 %139, label %142, label %140
140: ; preds = %135
%141 = call i32 @putc(i8 signext %137, i32* %37)
br label %142
142: ; preds = %131, %135, %140
%143 = add nuw nsw i64 %132, 1
%144 = icmp eq i64 %143, %113
br i1 %144, label %145, label %131
145: ; preds = %142, %128
%146 = call i32 @feof(i32* %34)
%147 = icmp eq i32 %146, 0
br i1 %147, label %114, label %148
148: ; preds = %145, %114, %117, %71, %68, %95, %101, %54
%149 = call i64 @ferror(i32* %37)
%150 = icmp eq i64 %149, 0
br i1 %150, label %151, label %154
151: ; preds = %148
%152 = call i64 @ferror(i32* %34)
%153 = icmp eq i64 %152, 0
br i1 %153, label %163, label %154
154: ; preds = %148, %151, %48, %98
%155 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%156 = call i32 @fclose(i32* %37)
br label %159
157: ; preds = %31
%158 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %159
159: ; preds = %157, %154
%160 = icmp eq i32* %34, null
br i1 %160, label %168, label %161
161: ; preds = %159
%162 = call i32 @fclose(i32* %34)
br label %168
163: ; preds = %151
%164 = call i32 @fclose(i32* %37)
%165 = call i32 @fclose(i32* %34)
br label %168
166: ; preds = %2, %29
%167 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %9)
br label %168
168: ; preds = %163, %161, %159, %166, %18
%169 = phi i32 [ 0, %166 ], [ 0, %18 ], [ 1, %161 ], [ 1, %159 ], [ 0, %163 ]
ret i32 %169
}