#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fi, *fo;
  char *cp = argv[1];
  int c;
  if (argc != 3) {
    printf("Usage: %s [key] [input-file]\n", argv[0]);
    return -1;
  }
  fi = fopen(argv[2], "rb");
  if (*cp == '\0' || fi == NULL) {
    fclose(fi);
    return -1;
  }
  fo = fopen("output.log", "wb");
  if (fo == NULL) {
    fclose(fo);
    return -1;
  }
  while ((c = fgetc(fi)) != EOF) {
    if (*cp == '\0')
      cp = argv[1];
    c ^= *(cp++);
    fputc(c, fo);
  }
  fclose(fo);
  fclose(fi);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ce <main+0x7e>
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <main+0x93>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <main+0x148>
lea    0xe37(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121a <main+0xca>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <main+0x148>
jmp    121f <main+0xcf>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%eax
je     127f <main+0x12f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1256 <main+0x106>
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),%eax
xor    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
jmp    121f <main+0xcf>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x3,%edi
jne    11f1 <main+0xa1>
mov    0x8(%r14),%rbx
mov    0x10(%r14),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     1202 <main+0xb2>
cmpb   $0x0,(%rbx)
je     1202 <main+0xb2>
lea    0xe90(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121b <main+0xcb>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    0x2e34(%rip),%r13
jmp    11db <main+0x8b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
movsbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1207 <main+0xb7>
movzbl (%rbx),%ecx
test   %cl,%cl
jne    11c0 <main+0x70>
mov    0x8(%r14),%rbx
movzbl (%rbx),%ecx
jmp    11c0 <main+0x70>
mov    (%r14),%rsi
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
jmp    1222 <main+0xd2>
mov    %r12,%rdi
jmp    121d <main+0xcd>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1227 <main+0xd7>
xor    %edi,%edi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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