#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*/ FILE;

/* Variables and functions */
int atoi(char *);
char decrypt(char, int, int);
char encrypt(char, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char usage[] =
      "affine by Jason Giancono\nUSAGE: affine <FLAG> <input filename> <output "
      "filename> <key a> <key b>\nFLAGS:\t\t-d: decrypt\n\t\t-e: encrypt\n";
  if (argc != 6)
    printf("%s", usage);
  else {
    int error, a, b;
    FILE *output, *input;
    char temp;
    a = atoi(argv[4]);
    b = atoi(argv[5]);
    error = 0;
    input = fopen(argv[2], "r");
    if ((input != 0) && ((output = fopen(argv[3], "w")) != 0)) {
      if (!strcmp(argv[1], "-e")) {
        printf("\n-----\nEncoding\n-----\n");
        while ((feof(input) == 0) && (ferror(input) == 0) &&
               (ferror(output) == 0)) {
          temp = fgetc(input);
          temp = (((temp > 65) && (temp < 91)) || ((temp > 96) && (temp < 123)))
                     ? encrypt(temp, a, b)
                     : temp;
          if (feof(input) == 0) {
            fputc(temp, output);
          }
        }
      } else if (!strcmp(argv[1], "-d")) {
        printf("\n-----\nDecoding\n-----\n");
        while ((feof(input) == 0) && (ferror(input) == 0) &&
               (ferror(output) == 0)) {
          temp = fgetc(input);
          temp = (((temp > 65) && (temp < 91)) || ((temp > 96) && (temp < 123)))
                     ? (decrypt(temp, a, b))
                     : temp;
          if (feof(input) == 0)
            fputc(temp, output);
        }
      } else
        printf("%s", usage);
      printf("\n-----\nDone\n-----\n");
    } else {
      error = 1;
      printf("%s", usage);
    }
    if ((error == 1) || (ferror(input) != 0) || (ferror(output) != 0))
      perror("A read/write error occurred");
    if (output != 0)
      fclose(output);
    if (input != 0)
      fclose(input);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x84,%edx
call   10c0 <memcpy@plt>
cmpl   $0x6,-0x8(%rbp)
je     1225 <main+0x55>
lea    -0xa0(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    162f <main+0x45f>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0xac(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe23(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
je     1592 <main+0x3c2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdfc(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmp    $0x0,%rax
je     1592 <main+0x3c2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1404 <main+0x234>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc0(%rbp),%rdi
call   10b0 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xc2(%rbp)
jne    1329 <main+0x159>
mov    -0xc0(%rbp),%rdi
call   1040 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xc2(%rbp)
jne    1329 <main+0x159>
mov    -0xb8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
test   $0x1,%al
jne    133c <main+0x16c>
jmp    13ff <main+0x22f>
mov    -0xc0(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %al,-0xc1(%rbp)
movsbl -0xc1(%rbp),%eax
cmp    $0x41,%eax
jle    136e <main+0x19e>
movsbl -0xc1(%rbp),%eax
cmp    $0x5b,%eax
jl     138e <main+0x1be>
movsbl -0xc1(%rbp),%eax
cmp    $0x60,%eax
jle    13b6 <main+0x1e6>
movsbl -0xc1(%rbp),%eax
cmp    $0x7b,%eax
jge    13b6 <main+0x1e6>
mov    -0xc1(%rbp),%al
mov    -0xa8(%rbp),%esi
mov    -0xac(%rbp),%edx
movsbl %al,%edi
call   1070 <encrypt@plt>
movsbl %al,%eax
mov    %eax,-0xc8(%rbp)
jmp    13c3 <main+0x1f3>
movsbl -0xc1(%rbp),%eax
mov    %eax,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
mov    %al,-0xc1(%rbp)
mov    -0xc0(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%rax
jne    13fa <main+0x22a>
mov    -0xc1(%rbp),%al
mov    -0xb8(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
jmp    12ce <main+0xfe>
jmp    157f <main+0x3af>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc92(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1565 <main+0x395>
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc0(%rbp),%rdi
call   10b0 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xc9(%rbp)
jne    148a <main+0x2ba>
mov    -0xc0(%rbp),%rdi
call   1040 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xc9(%rbp)
jne    148a <main+0x2ba>
mov    -0xb8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0xc9(%rbp)
mov    -0xc9(%rbp),%al
test   $0x1,%al
jne    149d <main+0x2cd>
jmp    1560 <main+0x390>
mov    -0xc0(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %al,-0xc1(%rbp)
movsbl -0xc1(%rbp),%eax
cmp    $0x41,%eax
jle    14cf <main+0x2ff>
movsbl -0xc1(%rbp),%eax
cmp    $0x5b,%eax
jl     14ef <main+0x31f>
movsbl -0xc1(%rbp),%eax
cmp    $0x60,%eax
jle    1517 <main+0x347>
movsbl -0xc1(%rbp),%eax
cmp    $0x7b,%eax
jge    1517 <main+0x347>
mov    -0xc1(%rbp),%al
mov    -0xa8(%rbp),%esi
mov    -0xac(%rbp),%edx
movsbl %al,%edi
call   1030 <decrypt@plt>
movsbl %al,%eax
mov    %eax,-0xd0(%rbp)
jmp    1524 <main+0x354>
movsbl -0xc1(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    -0xd0(%rbp),%eax
mov    %al,-0xc1(%rbp)
mov    -0xc0(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%rax
jne    155b <main+0x38b>
mov    -0xc1(%rbp),%al
mov    -0xb8(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
jmp    142f <main+0x25f>
jmp    157a <main+0x3aa>
lea    -0xa0(%rbp),%rsi
lea    0xb11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    157f <main+0x3af>
lea    0xb39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15b1 <main+0x3e1>
movl   $0x1,-0xa4(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xada(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0xa4(%rbp)
je     15ea <main+0x41a>
mov    -0xc0(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
jne    15ea <main+0x41a>
mov    -0xb8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     15f6 <main+0x426>
lea    0xae1(%rip),%rdi
call   10e0 <perror@plt>
cmpq   $0x0,-0xb8(%rbp)
je     1610 <main+0x440>
mov    -0xb8(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0xc0(%rbp)
je     162a <main+0x45a>
mov    -0xc0(%rbp),%rdi
call   1050 <fclose@plt>
jmp    162f <main+0x45f>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe05(%rip),%rsi
mov    %rsp,%rdi
mov    $0x84,%edx
call   10d0 <memcpy@plt>
cmp    $0x6,%ebx
jne    12ee <main+0x10e>
mov    0x20(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r15d
mov    0x28(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1417 <main+0x237>
mov    0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1417 <main+0x237>
mov    %rax,%r14
mov    0x8(%rbp),%rbp
lea    0xe1f(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1311 <main+0x131>
lea    0xe0b(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1394 <main+0x1b4>
lea    0xdea(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    142b <main+0x24b>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    142b <main+0x24b>
test   %r14,%r14
je     12df <main+0xff>
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %rbx,%rbx
je     12ff <main+0x11f>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    12ff <main+0x11f>
lea    0xd8f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd95(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
mov    %eax,%ebp
lea    -0x42(%rbp),%eax
cmp    $0x19,%al
jb     1368 <main+0x188>
lea    -0x61(%rbp),%eax
cmp    $0x19,%al
ja     1379 <main+0x199>
movsbl %bpl,%edi
mov    %r15d,%esi
mov    %r12d,%edx
call   1080 <encrypt@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    131d <main+0x13d>
movsbl %bpl,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
jmp    131d <main+0x13d>
lea    0xd3a(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    12a4 <main+0xc4>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
mov    %eax,%ebp
lea    -0x42(%rbp),%eax
cmp    $0x19,%al
jb     13eb <main+0x20b>
lea    -0x61(%rbp),%eax
cmp    $0x19,%al
ja     13fc <main+0x21c>
movsbl %bpl,%edi
mov    %r15d,%esi
mov    %r12d,%edx
call   1030 <decrypt@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    13a0 <main+0x1c0>
movsbl %bpl,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
jmp    13a0 <main+0x1c0>
lea    0xc66(%rip),%rdi
xor    %r14d,%r14d
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc5f(%rip),%rdi
call   10f0 <perror@plt>
test   %r14,%r14
jne    12d7 <main+0xf7>
jmp    12df <main+0xff>

LLVM IR (-O0):
@__const.main.usage = [132 x i8] c"affine by Jason Giancono\0AUSAGE: affine <FLAG> <input filename> <output filename> <key a> <key b>\0AFLAGS:\09\09-d: decrypt\0A\09\09-e: encrypt\0A\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"-e\00"
@.str.4 = [23 x i8] c"\0A-----\0AEncoding\0A-----\0A\00"
@.str.5 = [3 x i8] c"-d\00"
@.str.6 = [23 x i8] c"\0A-----\0ADecoding\0A-----\0A\00"
@.str.7 = [19 x i8] c"\0A-----\0ADone\0A-----\0A\00"
@.str.8 = [28 x i8] c"A read/write error occurred\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [132 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [132 x i8]* %6 to i8*
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 6
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %197
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 4
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 5
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
store i32 0, i32* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %11
%32 = load i32*, i32** %11
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %168
34: ; preds = %19
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %10
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %168
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %101, label %46
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %99, %46
%49 = load i32*, i32** %11
%50 = call i64 @feof(i32* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %48
%53 = load i32*, i32** %11
%54 = call i64 @ferror(i32* %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32*, i32** %10
%58 = call i64 @ferror(i32* %57)
%59 = icmp eq i64 %58, 0
br label %60
60: ; preds = %56, %52, %48
%61 = phi i1 [ false, %52 ], [ false, %48 ], [ %59, %56 ]
br i1 %61, label %62, label %100
62: ; preds = %60
%63 = load i32*, i32** %11
%64 = call signext i8 @fgetc(i32* %63)
store i8 %64, i8* %12
%65 = load i8, i8* %12
%66 = sext i8 %65 to i32
%67 = icmp sgt i32 %66, 65
br i1 %67, label %68, label %72
68: ; preds = %62
%69 = load i8, i8* %12
%70 = sext i8 %69 to i32
%71 = icmp slt i32 %70, 91
br i1 %71, label %80, label %72
72: ; preds = %68, %62
%73 = load i8, i8* %12
%74 = sext i8 %73 to i32
%75 = icmp sgt i32 %74, 96
br i1 %75, label %76, label %86
76: ; preds = %72
%77 = load i8, i8* %12
%78 = sext i8 %77 to i32
%79 = icmp slt i32 %78, 123
br i1 %79, label %80, label %86
80: ; preds = %76, %68
%81 = load i8, i8* %12
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = call signext i8 @encrypt(i8 signext %81, i32 %82, i32 %83)
%85 = sext i8 %84 to i32
br label %89
86: ; preds = %76, %72
%87 = load i8, i8* %12
%88 = sext i8 %87 to i32
br label %89
89: ; preds = %86, %80
%90 = phi i32 [ %85, %80 ], [ %88, %86 ]
%91 = trunc i32 %90 to i8
store i8 %91, i8* %12
%92 = load i32*, i32** %11
%93 = call i64 @feof(i32* %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %89
%96 = load i8, i8* %12
%97 = load i32*, i32** %10
%98 = call i32 @fputc(i8 signext %96, i32* %97)
br label %99
99: ; preds = %95, %89
br label %48
100: ; preds = %60
br label %166
101: ; preds = %40
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 1
%104 = load i8*, i8** %103
%105 = call i32 @strcmp(i8* %104, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%106 = icmp ne i32 %105, 0
br i1 %106, label %162, label %107
107: ; preds = %101
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %109
109: ; preds = %160, %107
%110 = load i32*, i32** %11
%111 = call i64 @feof(i32* %110)
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %121
113: ; preds = %109
%114 = load i32*, i32** %11
%115 = call i64 @ferror(i32* %114)
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %121
117: ; preds = %113
%118 = load i32*, i32** %10
%119 = call i64 @ferror(i32* %118)
%120 = icmp eq i64 %119, 0
br label %121
121: ; preds = %117, %113, %109
%122 = phi i1 [ false, %113 ], [ false, %109 ], [ %120, %117 ]
br i1 %122, label %123, label %161
123: ; preds = %121
%124 = load i32*, i32** %11
%125 = call signext i8 @fgetc(i32* %124)
store i8 %125, i8* %12
%126 = load i8, i8* %12
%127 = sext i8 %126 to i32
%128 = icmp sgt i32 %127, 65
br i1 %128, label %129, label %133
129: ; preds = %123
%130 = load i8, i8* %12
%131 = sext i8 %130 to i32
%132 = icmp slt i32 %131, 91
br i1 %132, label %141, label %133
133: ; preds = %129, %123
%134 = load i8, i8* %12
%135 = sext i8 %134 to i32
%136 = icmp sgt i32 %135, 96
br i1 %136, label %137, label %147
137: ; preds = %133
%138 = load i8, i8* %12
%139 = sext i8 %138 to i32
%140 = icmp slt i32 %139, 123
br i1 %140, label %141, label %147
141: ; preds = %137, %129
%142 = load i8, i8* %12
%143 = load i32, i32* %8
%144 = load i32, i32* %9
%145 = call signext i8 @decrypt(i8 signext %142, i32 %143, i32 %144)
%146 = sext i8 %145 to i32
br label %150
147: ; preds = %137, %133
%148 = load i8, i8* %12
%149 = sext i8 %148 to i32
br label %150
150: ; preds = %147, %141
%151 = phi i32 [ %146, %141 ], [ %149, %147 ]
%152 = trunc i32 %151 to i8
store i8 %152, i8* %12
%153 = load i32*, i32** %11
%154 = call i64 @feof(i32* %153)
%155 = icmp eq i64 %154, 0
br i1 %155, label %156, label %160
156: ; preds = %150
%157 = load i8, i8* %12
%158 = load i32*, i32** %10
%159 = call i32 @fputc(i8 signext %157, i32* %158)
br label %160
160: ; preds = %156, %150
br label %109
161: ; preds = %121
br label %165
162: ; preds = %101
%163 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %163)
br label %165
165: ; preds = %162, %161
br label %166
166: ; preds = %165, %100
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %171
168: ; preds = %34, %19
store i32 1, i32* %7
%169 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %169)
br label %171
171: ; preds = %168, %166
%172 = load i32, i32* %7
%173 = icmp eq i32 %172, 1
br i1 %173, label %182, label %174
174: ; preds = %171
%175 = load i32*, i32** %11
%176 = call i64 @ferror(i32* %175)
%177 = icmp ne i64 %176, 0
br i1 %177, label %182, label %178
178: ; preds = %174
%179 = load i32*, i32** %10
%180 = call i64 @ferror(i32* %179)
%181 = icmp ne i64 %180, 0
br i1 %181, label %182, label %184
182: ; preds = %178, %174, %171
%183 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %184
184: ; preds = %182, %178
%185 = load i32*, i32** %10
%186 = icmp ne i32* %185, null
br i1 %186, label %187, label %190
187: ; preds = %184
%188 = load i32*, i32** %10
%189 = call i32 @fclose(i32* %188)
br label %190
190: ; preds = %187, %184
%191 = load i32*, i32** %11
%192 = icmp ne i32* %191, null
br i1 %192, label %193, label %196
193: ; preds = %190
%194 = load i32*, i32** %11
%195 = call i32 @fclose(i32* %194)
br label %196
196: ; preds = %193, %190
br label %197
197: ; preds = %196, %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.usage = [132 x i8] c"affine by Jason Giancono\0AUSAGE: affine <FLAG> <input filename> <output filename> <key a> <key b>\0AFLAGS:\09\09-d: decrypt\0A\09\09-e: encrypt\0A\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"-e\00"
@.str.5 = [3 x i8] c"-d\00"
@.str.8 = [28 x i8] c"A read/write error occurred\00"
@str = [22 x i8] c"\0A-----\0AEncoding\0A-----\00"
@str.9 = [18 x i8] c"\0A-----\0ADone\0A-----\00"
@str.10 = [22 x i8] c"\0A-----\0ADecoding\0A-----\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [132 x i8]
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 6
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %110
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 4
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 5
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %90, label %19
19: ; preds = %8
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %90, label %24
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @strcmp(i8* dereferenceable(1) %26, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %57
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%31 = tail call i64 @feof(i32* %17)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %92
33: ; preds = %29, %54
%34 = tail call i64 @ferror(i32* %17)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %92
36: ; preds = %33
%37 = tail call i64 @ferror(i32* %22)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %92
39: ; preds = %36
%40 = tail call signext i8 @fgetc(i32* %17)
%41 = add i8 %40, -66
%42 = icmp ult i8 %41, 25
%43 = add i8 %40, -97
%44 = icmp ult i8 %43, 26
%45 = or i1 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = tail call signext i8 @encrypt(i8 signext %40, i32 %11, i32 %14)
br label %48
48: ; preds = %39, %46
%49 = phi i8 [ %47, %46 ], [ %40, %39 ]
%50 = tail call i64 @feof(i32* %17)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = tail call i32 @fputc(i8 signext %49, i32* %22)
br label %54
54: ; preds = %52, %48
%55 = tail call i64 @feof(i32* %17)
%56 = icmp eq i64 %55, 0
br i1 %56, label %33, label %92
57: ; preds = %24
%58 = tail call i32 @strcmp(i8* dereferenceable(1) %26, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %88
60: ; preds = %57
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%62 = tail call i64 @feof(i32* %17)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %92
64: ; preds = %60, %85
%65 = tail call i64 @ferror(i32* %17)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %92
67: ; preds = %64
%68 = tail call i64 @ferror(i32* %22)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %92
70: ; preds = %67
%71 = tail call signext i8 @fgetc(i32* %17)
%72 = add i8 %71, -66
%73 = icmp ult i8 %72, 25
%74 = add i8 %71, -97
%75 = icmp ult i8 %74, 26
%76 = or i1 %73, %75
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = tail call signext i8 @decrypt(i8 signext %71, i32 %11, i32 %14)
br label %79
79: ; preds = %70, %77
%80 = phi i8 [ %78, %77 ], [ %71, %70 ]
%81 = tail call i64 @feof(i32* %17)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = tail call i32 @fputc(i8 signext %80, i32* %22)
br label %85
85: ; preds = %83, %79
%86 = tail call i64 @feof(i32* %17)
%87 = icmp eq i64 %86, 0
br i1 %87, label %64, label %92
88: ; preds = %57
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %92
90: ; preds = %8, %19
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %99
92: ; preds = %67, %64, %85, %54, %33, %36, %60, %29, %88
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0))
%94 = call i64 @ferror(i32* %17)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %92
%97 = call i64 @ferror(i32* %22)
%98 = icmp eq i64 %97, 0
br i1 %98, label %102, label %99
99: ; preds = %90, %96, %92
%100 = phi i32* [ null, %90 ], [ %22, %96 ], [ %22, %92 ]
%101 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %102
102: ; preds = %99, %96
%103 = phi i32* [ %100, %99 ], [ %22, %96 ]
%104 = icmp eq i32* %103, null
br i1 %104, label %107, label %105
105: ; preds = %102
%106 = call i32 @fclose(i32* %103)
br label %107
107: ; preds = %105, %102
br i1 %18, label %110, label %108
108: ; preds = %107
%109 = call i32 @fclose(i32* %17)
br label %110
110: ; preds = %107, %108, %6
ret i32 0
}