#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *fi, *fo;
  char *kp;
  char c;
  if (argc < 4 || !*argv[1]) {
    fprintf(stderr, "%s <key> <infile> <outfile>\n", argv[0]);
    return 1;
  }
  kp = argv[1];
  if (!(fi = fopen(argv[2], "rb"))) {
    perror("fopen(input)");
    return 1;
  }
  if (!(fo = fopen(argv[3], "wb"))) {
    perror("fopen(ouput)");
    return 1;
  }
  for (;;) {
    c = getc(fi);
    if (feof(fi)) {
      break;
    }
    if (!*kp) {
      kp = argv[1];
    }
    c ^= *(kp++);
    fputc(c, fo);
  }
  fclose(fi);
  fclose(fo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11a1 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmpb   $0x0,(%rax)
jne    11c9 <main+0x59>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe39(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120f <main+0x9f>
lea    0xe22(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1249 <main+0xd9>
lea    0xdf8(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
jmp    124e <main+0xde>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1272 <main+0x102>
jmp    12ba <main+0x14a>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    128b <main+0x11b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%ecx
movsbl -0x29(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    124e <main+0xde>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x4,%edi
jl     1209 <main+0x99>
mov    0x8(%r14),%rbx
cmpb   $0x0,(%rbx)
je     1209 <main+0x99>
mov    0x10(%r14),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xd3>
mov    %rax,%r12
mov    0x18(%r14),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     124c <main+0xdc>
mov    %rax,%r15
jmp    11e2 <main+0x72>
nopl   0x0(%rax,%rax,1)
xor    %bpl,%al
add    $0x1,%rbx
movsbl %al,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
mov    %r12,%rdi
call   1090 <getc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1228 <main+0xb8>
movzbl (%rbx),%eax
test   %al,%al
jne    11d0 <main+0x60>
mov    0x8(%r14),%rbx
movzbl (%rbx),%eax
jmp    11d0 <main+0x60>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xde4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    123a <main+0xca>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd6(%rip),%rdi
jmp    1253 <main+0xe3>
lea    0xddd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    123a <main+0xca>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"%s <key> <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fopen(input)\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [13 x i8] c"fopen(ouput)\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 i8*
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %12, %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %76
24: ; preds = %12
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %8
%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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %35, label %33
33: ; preds = %24
%34 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %76
35: ; preds = %24
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %43, label %41
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %76
43: ; preds = %35
br label %44
44: ; preds = %59, %43
%45 = load i32*, i32** %6
%46 = call signext i8 @getc(i32* %45)
store i8 %46, i8* %9
%47 = load i32*, i32** %6
%48 = call i64 @feof(i32* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
br label %71
51: ; preds = %44
%52 = load i8*, i8** %8
%53 = load i8, i8* %52
%54 = icmp ne i8 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
store i8* %58, i8** %8
br label %59
59: ; preds = %55, %51
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %8
%62 = load i8, i8* %60
%63 = sext i8 %62 to i32
%64 = load i8, i8* %9
%65 = sext i8 %64 to i32
%66 = xor i32 %65, %63
%67 = trunc i32 %66 to i8
store i8 %67, i8* %9
%68 = load i8, i8* %9
%69 = load i32*, i32** %7
%70 = call i32 @fputc(i8 signext %68, i32* %69)
br label %44
71: ; preds = %50
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %71, %41, %33, %18
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"%s <key> <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fopen(input)\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [13 x i8] c"fopen(ouput)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4, %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %51
13: ; preds = %4
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %51
20: ; preds = %13
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = tail call signext i8 @getc(i32* %16)
%27 = tail call i64 @feof(i32* %16)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %48
29: ; preds = %20
%30 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %51
31: ; preds = %25, %39
%32 = phi i8 [ %45, %39 ], [ %26, %25 ]
%33 = phi i8* [ %42, %39 ], [ %6, %25 ]
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
br label %39
39: ; preds = %36, %31
%40 = phi i8 [ %34, %31 ], [ %38, %36 ]
%41 = phi i8* [ %33, %31 ], [ %37, %36 ]
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = xor i8 %40, %32
%44 = tail call i32 @fputc(i8 signext %43, i32* %23)
%45 = tail call signext i8 @getc(i32* %16)
%46 = tail call i64 @feof(i32* %16)
%47 = icmp eq i64 %46, 0
br i1 %47, label %31, label %48
48: ; preds = %39, %25
%49 = tail call i32 @fclose(i32* %16)
%50 = tail call i32 @fclose(i32* %23)
br label %51
51: ; preds = %48, %29, %18, %9
%52 = phi i32 [ 1, %9 ], [ 0, %48 ], [ 1, %29 ], [ 1, %18 ]
ret i32 %52
}