#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int main(int argc, char **argv) {
  FILE *outputFile;
  outputFile = fopen(argv[3], "w");
  FILE *inputFile;
  inputFile = fopen(argv[1], "r");
  FILE *keyFile;
  keyFile = fopen(argv[2], "r");
  struct stat st;
  stat(argv[1], &st);
  int inputSize = st.st_size;
  struct stat st2;
  stat(argv[2], &st2);
  int keySize = st2.st_size;
  char message[inputSize];
  if (inputSize != keySize) {
    puts("Sorry, the key needs to be the same size as the file you want to "
         "encrypt.");
    return 1;
  }
  for (int i = 0; i < inputSize; i++) {
    message[i] = fgetc(inputFile) ^ fgetc(keyFile);
  }
  for (int i = 0; i < inputSize; i++) {
    fputc(message[i], outputFile);
  }
  fclose(outputFile);
  fclose(inputFile);
  fclose(keyFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe62(%rip),%rsi
mov    %rsi,-0x70(%rbp)
call   1080 <fopen@plt>
mov    -0x70(%rbp),%rsi
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
je     1241 <main+0xe1>
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    12f2 <main+0x192>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1291 <main+0x131>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    -0x74(%rbp),%ecx
mov    %al,%dl
mov    -0x68(%rbp),%rax
movsbl %dl,%edx
xor    %edx,%ecx
mov    %cl,%dl
movslq -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1248 <main+0xe8>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12c9 <main+0x169>
mov    -0x68(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <main+0x138>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x48(%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    $0x38,%rsp
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0xe70(%rip),%r12
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    0x10(%rbx),%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    0x8(%rbx),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x38(%rbp),%r13d
mov    0x10(%rbx),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    %rsp,%r12
mov    %rsp,%r14
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r13,%rax
mov    %r14,%rsp
cmp    -0x30(%rbp),%eax
jne    1277 <main+0x117>
test   %eax,%eax
jle    1259 <main+0xf9>
mov    %r12,-0x50(%rbp)
mov    %r15,-0x58(%rbp)
xor    %r15d,%r15d
mov    -0x40(%rbp),%r12
nop
mov    %r12,%rdi
mov    %rax,%r13
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    -0x48(%rbp),%rdi
call   1050 <fgetc@plt>
xor    %bl,%al
mov    %al,(%r14,%r15,1)
mov    %r13,%rax
add    $0x1,%r15
cmp    %r15,%r13
jne    1200 <main+0xa0>
test   %eax,%eax
mov    -0x58(%rbp),%r15
mov    -0x50(%rbp),%r12
jle    1259 <main+0xf9>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
mov    %r13,%rax
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1240 <main+0xe0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1288 <main+0x128>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [74 x i8] c"Sorry, the key needs to be the same size as the file you want to encrypt.\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 %struct.stat
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 3
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @stat(i8* %32, %struct.stat* %9)
%34 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%35 = load i32, i32* %34
store i32 %35, i32* %10
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @stat(i8* %38, %struct.stat* %11)
%40 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%41 = load i32, i32* %40
store i32 %41, i32* %12
%42 = load i32, i32* %10
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %13
%45 = alloca i8, i64 %43
store i64 %43, i64* %14
%46 = load i32, i32* %10
%47 = load i32, i32* %12
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %2
%50 = call i32 @puts(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %15
br label %93
51: ; preds = %2
store i32 0, i32* %16
br label %52
52: ; preds = %68, %51
%53 = load i32, i32* %16
%54 = load i32, i32* %10
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %71
56: ; preds = %52
%57 = load i32*, i32** %7
%58 = call signext i8 @fgetc(i32* %57)
%59 = sext i8 %58 to i32
%60 = load i32*, i32** %8
%61 = call signext i8 @fgetc(i32* %60)
%62 = sext i8 %61 to i32
%63 = xor i32 %59, %62
%64 = trunc i32 %63 to i8
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %45, i64 %66
store i8 %64, i8* %67
br label %68
68: ; preds = %56
%69 = load i32, i32* %16
%70 = add nsw i32 %69, 1
store i32 %70, i32* %16
br label %52
71: ; preds = %52
store i32 0, i32* %17
br label %72
72: ; preds = %83, %71
%73 = load i32, i32* %17
%74 = load i32, i32* %10
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %86
76: ; preds = %72
%77 = load i32, i32* %17
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %45, i64 %78
%80 = load i8, i8* %79
%81 = load i32*, i32** %6
%82 = call i32 @fputc(i8 signext %80, i32* %81)
br label %83
83: ; preds = %76
%84 = load i32, i32* %17
%85 = add nsw i32 %84, 1
store i32 %85, i32* %17
br label %72
86: ; preds = %72
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
%89 = load i32*, i32** %7
%90 = call i32 @fclose(i32* %89)
%91 = load i32*, i32** %8
%92 = call i32 @fclose(i32* %91)
store i32 0, i32* %3
store i32 1, i32* %15
br label %93
93: ; preds = %86, %49
%94 = load i8*, i8** %13
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [74 x i8] c"Sorry, the key needs to be the same size as the file you want to encrypt.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = bitcast %struct.stat* %3 to i8*
%15 = load i8*, i8** %8
%16 = call i32 @stat(i8* %15, %struct.stat* %3)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = bitcast %struct.stat* %4 to i8*
%20 = load i8*, i8** %11
%21 = call i32 @stat(i8* %20, %struct.stat* %4)
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = zext i32 %18 to i64
%25 = tail call i8* @llvm.stacksave()
%26 = alloca i8, i64 %24
%27 = icmp eq i32 %18, %23
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = icmp sgt i32 %18, 0
br i1 %29, label %33, label %41
30: ; preds = %2
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
br label %52
32: ; preds = %33
br i1 %29, label %45, label %41
33: ; preds = %28, %33
%34 = phi i64 [ %39, %33 ], [ 0, %28 ]
%35 = tail call signext i8 @fgetc(i32* %10)
%36 = tail call signext i8 @fgetc(i32* %13)
%37 = xor i8 %36, %35
%38 = getelementptr inbounds i8, i8* %26, i64 %34
store i8 %37, i8* %38
%39 = add nuw nsw i64 %34, 1
%40 = icmp eq i64 %39, %24
br i1 %40, label %32, label %33
41: ; preds = %45, %28, %32
%42 = tail call i32 @fclose(i32* %7)
%43 = tail call i32 @fclose(i32* %10)
%44 = tail call i32 @fclose(i32* %13)
br label %52
45: ; preds = %32, %45
%46 = phi i64 [ %50, %45 ], [ 0, %32 ]
%47 = getelementptr inbounds i8, i8* %26, i64 %46
%48 = load i8, i8* %47
%49 = tail call i32 @fputc(i8 signext %48, i32* %7)
%50 = add nuw nsw i64 %46, 1
%51 = icmp eq i64 %50, %24
br i1 %51, label %41, label %45
52: ; preds = %41, %30
%53 = phi i32 [ 1, %30 ], [ 0, %41 ]
tail call void @llvm.stackrestore(i8* %25)
ret i32 %53
}