#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 */
unsigned int EOF;
int /*<<< orphan*/ SEEK_SET;
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
unsigned int strlen(char *);
int /*<<< orphan*/ strncpy(unsigned char *, char *, int);
main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: ./csdecrypt [key] [loop count] [file]\n");
    exit(0);
  }
  unsigned int i = 0;
  unsigned int j = 0;
  unsigned int temp = 0;
  unsigned int input = 0;
  unsigned int t = 0;
  unsigned int K = 0;
  unsigned int keyLength = strlen(argv[1]);
  unsigned char S[256];
  unsigned char key[256];
  unsigned char iv[256];
  unsigned int loopCount = atoi(argv[2]);
  if (strlen(argv[1]) == 0) {
    printf("Usage: ./csdecrypt [key] [loop count] [filename]\n");
    printf("You must enter a key.\n");
    exit(0);
  }
  strncpy(key, argv[1], 256);
  FILE *f;
  f = fopen(argv[3], "rb");
  fread(iv, 1, 10, f);
  fclose(f);
  unsigned int keyIVLength = keyLength + 10;
  unsigned char keyIV[keyIVLength];
  for (i = 0; i < keyLength; i++) {
    keyIV[i] = key[i];
  }
  for (i = keyLength; i < (keyIVLength); i++) {
    keyIV[i] = iv[i - keyLength];
  }
  i = 0;
  j = 0;
  temp = 0;
  for (i = 0; i < 256; i++) {
    S[i] = i;
  }
  unsigned int loopIter = 0;
  for (loopIter = 0; loopIter < loopCount; loopIter++) {
    for (i = 0; i < 256; i++) {
      j = (j + S[i] + keyIV[i % keyIVLength]) % 256;
      temp = S[i];
      S[i] = S[j];
      S[j] = temp;
    }
  }
  i = 0;
  j = 0;
  FILE *fg = fopen(argv[3], "rb");
  fseek(fg, 10, SEEK_SET);
  i = 0;
  j = 0;
  temp = 0;
  while ((input = fgetc(fg)) != EOF) {
    i = (i + 1) % 256;
    j = (j + S[i]) % 256;
    temp = S[i];
    S[i] = S[j];
    S[j] = temp;
    t = (S[i] + S[j]) % 256;
    K = S[t];
    printf("%c", (K ^ input));
  }
  fclose(fg);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x380,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <main+0x38>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x334(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jne    125e <main+0xbe>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x230(%rbp),%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x340(%rbp)
mov    -0x340(%rbp),%rcx
lea    -0x330(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1040 <fread@plt>
mov    -0x340(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x344(%rbp)
mov    -0x344(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x350(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x370(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x358(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    1331 <main+0x191>
mov    -0x370(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x230(%rbp,%rcx,1),%dl
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1300 <main+0x160>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x344(%rbp),%eax
jae    1370 <main+0x1d0>
mov    -0x370(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
mov    -0x330(%rbp,%rcx,1),%dl
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1337 <main+0x197>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jae    13b6 <main+0x216>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    138c <main+0x1ec>
movl   $0x0,-0x35c(%rbp)
movl   $0x0,-0x35c(%rbp)
mov    -0x35c(%rbp),%eax
cmp    -0x334(%rbp),%eax
jae    1486 <main+0x2e6>
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jae    146d <main+0x2cd>
mov    -0x370(%rbp),%rcx
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%edx
movzbl -0x130(%rbp,%rdx,1),%edx
ff
add    %edx,%eax
mov    %eax,-0x374(%rbp)
mov    -0x14(%rbp),%eax
xor    %edx,%edx
divl   -0x344(%rbp)
mov    -0x374(%rbp),%eax
mov    %edx,%edx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x130(%rbp,%rax,1),%cl
mov    -0x14(%rbp),%eax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13e3 <main+0x243>
jmp    1472 <main+0x2d2>
mov    -0x35c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x35c(%rbp)
jmp    13ca <main+0x22a>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xbd4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x368(%rbp)
mov    -0x368(%rbp),%rdi
mov    0x2b1b(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1090 <fseek@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x368(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2af4(%rip),%rcx
cmp    (%rcx),%eax
je     159d <main+0x3fd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
movzbl -0x130(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x130(%rbp,%rax,1),%cl
mov    -0x14(%rbp),%eax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    -0x18(%rbp),%ecx
movzbl -0x130(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
xor    -0x20(%rbp),%esi
lea    0xae9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14de <main+0x33e>
mov    -0x368(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x350(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
cmp    $0x1,%edi
jle    14b3 <main+0x2f3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <strlen@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%rdi
call   1080 <strlen@plt>
test   %eax,%eax
je     14bc <main+0x2fc>
mov    0x8(%rbx),%rsi
lea    -0x340(%rbp),%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    %rbx,-0x30(%rbp)
mov    0x18(%rbx),%rdi
lea    0xed3(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    -0x240(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1060 <fread@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rsp,-0x38(%rbp)
lea    0xa(%r12),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12d,%r13d
test   %r12d,%r12d
je     1290 <main+0xd0>
lea    -0x340(%rbp),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   10a0 <memcpy@plt>
cmp    $0xfffffff5,%r12d
ja     12bb <main+0xfb>
add    %rbx,%r13
lea    0x1(%r12),%eax
cmp    %eax,%r14d
cmova  %r14d,%eax
not    %r12d
add    %eax,%r12d
add    $0x1,%r12
lea    -0x240(%rbp),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
call   10a0 <memcpy@plt>
movaps 0xd3e(%rip),%xmm0
movaps %xmm0,-0x140(%rbp)
movaps 0xd40(%rip),%xmm0
movaps %xmm0,-0x130(%rbp)
movaps 0xd42(%rip),%xmm0
movaps %xmm0,-0x120(%rbp)
movaps 0xd44(%rip),%xmm0
movaps %xmm0,-0x110(%rbp)
movaps 0xd46(%rip),%xmm0
movaps %xmm0,-0x100(%rbp)
movaps 0xd48(%rip),%xmm0
movaps %xmm0,-0xf0(%rbp)
movaps 0xd4a(%rip),%xmm0
movaps %xmm0,-0xe0(%rbp)
movaps 0xd4c(%rip),%xmm0
movaps %xmm0,-0xd0(%rbp)
movaps 0xd4e(%rip),%xmm0
movaps %xmm0,-0xc0(%rbp)
movaps 0xd50(%rip),%xmm0
movaps %xmm0,-0xb0(%rbp)
movaps 0xd52(%rip),%xmm0
movaps %xmm0,-0xa0(%rbp)
movaps 0xd54(%rip),%xmm0
movaps %xmm0,-0x90(%rbp)
movaps 0xd56(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
movaps 0xd5b(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xd60(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xd65(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
test   %r15d,%r15d
je     13f7 <main+0x237>
xor    %r8d,%r8d
xor    %edi,%edi
nopl   0x0(%rax)
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x140(%rbp,%rcx,1),%esi
ff
add    %esi,%edi
mov    %ecx,%eax
xor    %edx,%edx
div    %r14d
movzbl (%rbx,%rdx,1),%eax
add    %edi,%eax
movzbl %al,%edi
movzbl -0x140(%rbp,%rdi,1),%eax
ff
mov    %al,-0x140(%rbp,%rcx,1)
mov    %sil,-0x140(%rbp,%rdi,1)
ff
add    $0x1,%rcx
cmp    $0x100,%rcx
jne    13b0 <main+0x1f0>
add    $0x1,%r8d
cmp    %r15d,%r8d
jne    13a0 <main+0x1e0>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xcfa(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    0x2bc3(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xa,%esi
call   10b0 <fseek@plt>
mov    %r15,%rdi
call   1090 <fgetc@plt>
mov    0x2bb5(%rip),%r14
cmp    (%r14),%eax
je     1496 <main+0x2d6>
xor    %ebx,%ebx
xor    %r12d,%r12d
nopl   (%rax)
add    $0x1,%ebx
movzbl %bl,%ebx
movzbl -0x140(%rbp,%rbx,1),%ecx
ff
add    %ecx,%r12d
movzbl %r12b,%r12d
movzbl -0x140(%rbp,%r12,1),%edx
ff ff
mov    %dl,-0x140(%rbp,%rbx,1)
mov    %cl,-0x140(%rbp,%r12,1)
ff
movzbl -0x140(%rbp,%rbx,1),%edx
ff
add    %ecx,%edx
movzbl %dl,%ecx
movzbl -0x140(%rbp,%rcx,1),%edi
ff
xor    %eax,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1090 <fgetc@plt>
cmp    (%r14),%eax
jne    1440 <main+0x280>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc90(%rip),%rdi
jmp    14cf <main+0x30f>
lea    0xc40(%rip),%rdi
call   1050 <puts@plt>
lea    0xc65(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"Usage: ./csdecrypt [key] [loop count] [file]\0A\00"
@.str.1 = [50 x i8] c"Usage: ./csdecrypt [key] [loop count] [filename]\0A\00"
@.str.2 = [23 x i8] c"You must enter a key.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@.str.4 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca [256 x i8]
%15 = alloca [256 x i8]
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i32
%22 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
store i32 %32, i32* %12
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %16
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %28
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @strncpy(i8* %47, i8* %50, i32 256)
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %55, i32** %17
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%57 = load i32*, i32** %17
%58 = call i32 @fread(i8* %56, i32 1, i32 10, i32* %57)
%59 = load i32*, i32** %17
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %12
%62 = add i32 %61, 10
store i32 %62, i32* %18
%63 = load i32, i32* %18
%64 = zext i32 %63 to i64
%65 = call i8* @llvm.stacksave()
store i8* %65, i8** %19
%66 = alloca i8, i64 %64
store i64 %64, i64* %20
store i32 0, i32* %6
br label %67
67: ; preds = %79, %46
%68 = load i32, i32* %6
%69 = load i32, i32* %12
%70 = icmp ult i32 %68, %69
br i1 %70, label %71, label %82
71: ; preds = %67
%72 = load i32, i32* %6
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = load i32, i32* %6
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %66, i64 %77
store i8 %75, i8* %78
br label %79
79: ; preds = %71
%80 = load i32, i32* %6
%81 = add i32 %80, 1
store i32 %81, i32* %6
br label %67
82: ; preds = %67
%83 = load i32, i32* %12
store i32 %83, i32* %6
br label %84
84: ; preds = %98, %82
%85 = load i32, i32* %6
%86 = load i32, i32* %18
%87 = icmp ult i32 %85, %86
br i1 %87, label %88, label %101
88: ; preds = %84
%89 = load i32, i32* %6
%90 = load i32, i32* %12
%91 = sub i32 %89, %90
%92 = zext i32 %91 to i64
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 %92
%94 = load i8, i8* %93
%95 = load i32, i32* %6
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %66, i64 %96
store i8 %94, i8* %97
br label %98
98: ; preds = %88
%99 = load i32, i32* %6
%100 = add i32 %99, 1
store i32 %100, i32* %6
br label %84
101: ; preds = %84
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %6
br label %102
102: ; preds = %111, %101
%103 = load i32, i32* %6
%104 = icmp ult i32 %103, 256
br i1 %104, label %105, label %114
105: ; preds = %102
%106 = load i32, i32* %6
%107 = trunc i32 %106 to i8
%108 = load i32, i32* %6
%109 = zext i32 %108 to i64
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %109
store i8 %107, i8* %110
br label %111
111: ; preds = %105
%112 = load i32, i32* %6
%113 = add i32 %112, 1
store i32 %113, i32* %6
br label %102
114: ; preds = %102
store i32 0, i32* %21
store i32 0, i32* %21
br label %115
115: ; preds = %161, %114
%116 = load i32, i32* %21
%117 = load i32, i32* %16
%118 = icmp ult i32 %116, %117
br i1 %118, label %119, label %164
119: ; preds = %115
store i32 0, i32* %6
br label %120
120: ; preds = %157, %119
%121 = load i32, i32* %6
%122 = icmp ult i32 %121, 256
br i1 %122, label %123, label %160
123: ; preds = %120
%124 = load i32, i32* %7
%125 = load i32, i32* %6
%126 = zext i32 %125 to i64
%127 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %126
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = add i32 %124, %129
%131 = load i32, i32* %6
%132 = load i32, i32* %18
%133 = urem i32 %131, %132
%134 = zext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %66, i64 %134
%136 = load i8, i8* %135
%137 = zext i8 %136 to i32
%138 = add i32 %130, %137
%139 = urem i32 %138, 256
store i32 %139, i32* %7
%140 = load i32, i32* %6
%141 = zext i32 %140 to i64
%142 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %141
%143 = load i8, i8* %142
%144 = zext i8 %143 to i32
store i32 %144, i32* %8
%145 = load i32, i32* %7
%146 = zext i32 %145 to i64
%147 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %146
%148 = load i8, i8* %147
%149 = load i32, i32* %6
%150 = zext i32 %149 to i64
%151 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %150
store i8 %148, i8* %151
%152 = load i32, i32* %8
%153 = trunc i32 %152 to i8
%154 = load i32, i32* %7
%155 = zext i32 %154 to i64
%156 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %155
store i8 %153, i8* %156
br label %157
157: ; preds = %123
%158 = load i32, i32* %6
%159 = add i32 %158, 1
store i32 %159, i32* %6
br label %120
160: ; preds = %120
br label %161
161: ; preds = %160
%162 = load i32, i32* %21
%163 = add i32 %162, 1
store i32 %163, i32* %21
br label %115
164: ; preds = %115
store i32 0, i32* %6
store i32 0, i32* %7
%165 = load i8**, i8*** %5
%166 = getelementptr inbounds i8*, i8** %165, i64 3
%167 = load i8*, i8** %166
%168 = call i32* @fopen(i8* %167, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %168, i32** %22
%169 = load i32*, i32** %22
%170 = load i32, i32* @SEEK_SET
%171 = call i32 @fseek(i32* %169, i32 10, i32 %170)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %172
172: ; preds = %177, %164
%173 = load i32*, i32** %22
%174 = call i32 @fgetc(i32* %173)
store i32 %174, i32* %9
%175 = load i32, i32* @EOF
%176 = icmp ne i32 %174, %175
br i1 %176, label %177, label %227
177: ; preds = %172
%178 = load i32, i32* %6
%179 = add i32 %178, 1
%180 = urem i32 %179, 256
store i32 %180, i32* %6
%181 = load i32, i32* %7
%182 = load i32, i32* %6
%183 = zext i32 %182 to i64
%184 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %183
%185 = load i8, i8* %184
%186 = zext i8 %185 to i32
%187 = add i32 %181, %186
%188 = urem i32 %187, 256
store i32 %188, i32* %7
%189 = load i32, i32* %6
%190 = zext i32 %189 to i64
%191 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %190
%192 = load i8, i8* %191
%193 = zext i8 %192 to i32
store i32 %193, i32* %8
%194 = load i32, i32* %7
%195 = zext i32 %194 to i64
%196 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %195
%197 = load i8, i8* %196
%198 = load i32, i32* %6
%199 = zext i32 %198 to i64
%200 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %199
store i8 %197, i8* %200
%201 = load i32, i32* %8
%202 = trunc i32 %201 to i8
%203 = load i32, i32* %7
%204 = zext i32 %203 to i64
%205 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %204
store i8 %202, i8* %205
%206 = load i32, i32* %6
%207 = zext i32 %206 to i64
%208 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %207
%209 = load i8, i8* %208
%210 = zext i8 %209 to i32
%211 = load i32, i32* %7
%212 = zext i32 %211 to i64
%213 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %212
%214 = load i8, i8* %213
%215 = zext i8 %214 to i32
%216 = add nsw i32 %210, %215
%217 = srem i32 %216, 256
store i32 %217, i32* %10
%218 = load i32, i32* %10
%219 = zext i32 %218 to i64
%220 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 %219
%221 = load i8, i8* %220
%222 = zext i8 %221 to i32
store i32 %222, i32* %11
%223 = load i32, i32* %11
%224 = load i32, i32* %9
%225 = xor i32 %223, %224
%226 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %225)
br label %172
227: ; preds = %172
%228 = load i32*, i32** %22
%229 = call i32 @fclose(i32* %228)
%230 = load i8*, i8** %19
%231 = load i32, i32* %3
ret i32 %231
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@str = [49 x i8] c"Usage: ./csdecrypt [key] [loop count] [filename]\00"
@str.5 = [22 x i8] c"You must enter a key.\00"
@str.6 = [45 x i8] c"Usage: ./csdecrypt [key] [loop count] [file]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = load i8*, i8** %13
%23 = tail call i32 @strlen(i8* %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %12
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %12
%30 = load i8*, i8** %13
%31 = call i32 @strncpy(i8* %17, i8* %30, i32 256)
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @fread(i8* %18, i32 1, i32 10, i32* %34)
%36 = call i32 @fclose(i32* %34)
%37 = add i32 %15, 10
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
%40 = alloca i8, i64 %38
%41 = icmp eq i32 %15, 0
br i1 %41, label %45, label %42
42: ; preds = %29
%43 = zext i32 %15 to i64
%44 = icmp ult i32 %15, -10
br i1 %44, label %45, label %54
45: ; preds = %29, %42
%46 = zext i32 %15 to i64
%47 = getelementptr i8, i8* %40, i64 %46
%48 = add nuw i32 %15, 1
%49 = call i32 @llvm.umax.i32(i32 %37, i32 %48)
%50 = xor i32 %15, -1
%51 = add i32 %49, %50
%52 = zext i32 %51 to i64
%53 = add nuw nsw i64 %52, 1
br label %54
54: ; preds = %45, %42
%55 = bitcast [256 x i8]* %3 to <16 x i8>*
store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, <16 x i8>* %55
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 16
%57 = bitcast i8* %56 to <16 x i8>*
store <16 x i8> <i8 16, i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31>, <16 x i8>* %57
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 32
%59 = bitcast i8* %58 to <16 x i8>*
store <16 x i8> <i8 32, i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47>, <16 x i8>* %59
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 48
%61 = bitcast i8* %60 to <16 x i8>*
store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63>, <16 x i8>* %61
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 64
%63 = bitcast i8* %62 to <16 x i8>*
store <16 x i8> <i8 64, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79>, <16 x i8>* %63
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 80
%65 = bitcast i8* %64 to <16 x i8>*
store <16 x i8> <i8 80, i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95>, <16 x i8>* %65
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 96
%67 = bitcast i8* %66 to <16 x i8>*
store <16 x i8> <i8 96, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111>, <16 x i8>* %67
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 112
%69 = bitcast i8* %68 to <16 x i8>*
store <16 x i8> <i8 112, i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127>, <16 x i8>* %69
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 128
%71 = bitcast i8* %70 to <16 x i8>*
store <16 x i8> <i8 -128, i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113>, <16 x i8>* %71
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 144
%73 = bitcast i8* %72 to <16 x i8>*
store <16 x i8> <i8 -112, i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97>, <16 x i8>* %73
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 160
%75 = bitcast i8* %74 to <16 x i8>*
store <16 x i8> <i8 -96, i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81>, <16 x i8>* %75
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 176
%77 = bitcast i8* %76 to <16 x i8>*
store <16 x i8> <i8 -80, i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65>, <16 x i8>* %77
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 192
%79 = bitcast i8* %78 to <16 x i8>*
store <16 x i8> <i8 -64, i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49>, <16 x i8>* %79
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 208
%81 = bitcast i8* %80 to <16 x i8>*
store <16 x i8> <i8 -48, i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33>, <16 x i8>* %81
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 224
%83 = bitcast i8* %82 to <16 x i8>*
store <16 x i8> <i8 -32, i8 -31, i8 -30, i8 -29, i8 -28, i8 -27, i8 -26, i8 -25, i8 -24, i8 -23, i8 -22, i8 -21, i8 -20, i8 -19, i8 -18, i8 -17>, <16 x i8>* %83
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 240
%85 = bitcast i8* %84 to <16 x i8>*
store <16 x i8> <i8 -16, i8 -15, i8 -14, i8 -13, i8 -12, i8 -11, i8 -10, i8 -9, i8 -8, i8 -7, i8 -6, i8 -5, i8 -4, i8 -3, i8 -2, i8 -1>, <16 x i8>* %85
%86 = icmp eq i32 %21, 0
br i1 %86, label %113, label %87
87: ; preds = %54, %110
%88 = phi i32 [ %111, %110 ], [ 0, %54 ]
%89 = phi i32 [ %104, %110 ], [ 0, %54 ]
br label %90
90: ; preds = %87, %90
%91 = phi i64 [ 0, %87 ], [ %108, %90 ]
%92 = phi i32 [ %89, %87 ], [ %104, %90 ]
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %91
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = add nuw nsw i32 %92, %95
%97 = trunc i64 %91 to i32
%98 = urem i32 %97, %37
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %40, i64 %99
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = add nsw i32 %96, %102
%104 = and i32 %103, 255
%105 = zext i32 %104 to i64
%106 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %105
%107 = load i8, i8* %106
store i8 %107, i8* %93
store i8 %94, i8* %106
%108 = add nuw nsw i64 %91, 1
%109 = icmp eq i64 %108, 256
br i1 %109, label %110, label %90
110: ; preds = %90
%111 = add nuw i32 %88, 1
%112 = icmp eq i32 %111, %21
br i1 %112, label %113, label %87
113: ; preds = %110, %54
%114 = load i8*, i8** %32
%115 = call i32* @fopen(i8* %114, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%116 = load i32, i32* @SEEK_SET
%117 = call i32 @fseek(i32* %115, i32 10, i32 %116)
%118 = call i32 @fgetc(i32* %115)
%119 = load i32, i32* @EOF
%120 = icmp eq i32 %118, %119
br i1 %120, label %149, label %121
121: ; preds = %113, %121
%122 = phi i32 [ %146, %121 ], [ %118, %113 ]
%123 = phi i32 [ %126, %121 ], [ 0, %113 ]
%124 = phi i32 [ %132, %121 ], [ 0, %113 ]
%125 = add nuw nsw i32 %123, 1
%126 = and i32 %125, 255
%127 = zext i32 %126 to i64
%128 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %127
%129 = load i8, i8* %128
%130 = zext i8 %129 to i32
%131 = add nuw nsw i32 %124, %130
%132 = and i32 %131, 255
%133 = zext i32 %132 to i64
%134 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %133
%135 = load i8, i8* %134
store i8 %135, i8* %128
store i8 %129, i8* %134
%136 = load i8, i8* %128
%137 = zext i8 %136 to i32
%138 = add nuw nsw i32 %137, %130
%139 = and i32 %138, 255
%140 = zext i32 %139 to i64
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %140
%142 = load i8, i8* %141
%143 = zext i8 %142 to i32
%144 = xor i32 %122, %143
%145 = call i32 @putchar(i32 %144)
%146 = call i32 @fgetc(i32* %115)
%147 = load i32, i32* @EOF
%148 = icmp eq i32 %146, %147
br i1 %148, label %149, label %121
149: ; preds = %121, %113
%150 = call i32 @fclose(i32* %115)
ret i32 0
}