#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 EBADF;
int EINVAL;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ myxor(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  FILE *input;
  FILE *output;
  int ret = 0;
  ;
  if (argc != 2 && argc != 4) {
    fprintf(stderr, "Usage: %s [input_file] [output_file] <key>\n", argv[0]);
    return -EINVAL;
  }
  input = (argc > 2) ? fopen(argv[2], "r") : stdin;
  output = (argc > 2) ? fopen(argv[3], "w") : stdout;
  if (!(input && output)) {
    errno = EBADF;
    ret = -errno;
    perror(NULL);
  } else
    myxor(input, output, argv[1]);
  fclose(input);
  fclose(output);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b0 <main+0x60>
cmpl   $0x4,-0x8(%rbp)
je     11b0 <main+0x60>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    0x2e22(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    129b <main+0x14b>
cmpl   $0x2,-0x8(%rbp)
jle    11d7 <main+0x87>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    11e5 <main+0x95>
mov    0x2e0a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1214 <main+0xc4>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
jmp    1222 <main+0xd2>
mov    0x2da5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1240 <main+0xf0>
cmpq   $0x0,-0x20(%rbp)
jne    126e <main+0x11e>
mov    0x2d71(%rip),%rax
mov    (%rax),%ecx
mov    0x2d80(%rip),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    0x2d75(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
jmp    1283 <main+0x133>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
call   1040 <myxor@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x2,%edi
je     1164 <main+0x14>
cmp    $0x4,%edi
jne    1191 <main+0x41>
cmp    $0x3,%edi
jb     11b6 <main+0x66>
mov    0x10(%r15),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x18(%r15),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
jmp    11ca <main+0x7a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e18(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    11f5 <main+0xa5>
mov    0x2e2b(%rip),%rax
mov    (%rax),%r14
mov    0x2df9(%rip),%rax
mov    (%rax),%rbx
test   %r14,%r14
je     1202 <main+0xb2>
test   %rbx,%rbx
je     1202 <main+0xb2>
mov    0x8(%r15),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <myxor@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%ebp
mov    0x2dbe(%rip),%rax
mov    %ebp,(%rax)
neg    %ebp
xor    %edi,%edi
call   1070 <perror@plt>
jmp    11e5 <main+0x95>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: %s [input_file] [output_file] <key>\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32* null
@EBADF = global i32 0
@errno = 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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
store i32 %21, i32* %3
br label %68
22: ; preds = %11, %2
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %22
%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))
br label %32
30: ; preds = %22
%31 = load i32*, i32** @stdin
br label %32
32: ; preds = %30, %25
%33 = phi i32* [ %29, %25 ], [ %31, %30 ]
store i32* %33, i32** %6
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %43
41: ; preds = %32
%42 = load i32*, i32** @stdout
br label %43
43: ; preds = %41, %36
%44 = phi i32* [ %40, %36 ], [ %42, %41 ]
store i32* %44, i32** %7
%45 = load i32*, i32** %6
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32*, i32** %7
%49 = icmp ne i32* %48, null
br i1 %49, label %55, label %50
50: ; preds = %47, %43
%51 = load i32, i32* @EBADF
store i32 %51, i32* @errno
%52 = load i32, i32* @errno
%53 = sub nsw i32 0, %52
store i32 %53, i32* %8
%54 = call i32 @perror(i32* null)
br label %62
55: ; preds = %47
%56 = load i32*, i32** %6
%57 = load i32*, i32** %7
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i32 @myxor(i32* %56, i32* %57, i8* %60)
br label %62
62: ; preds = %55, %50
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %7
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %8
store i32 %67, i32* %3
br label %68
68: ; preds = %62, %14
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: %s [input_file] [output_file] <key>\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32* null
@EBADF = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %3 [
i32 4, label %9
i32 2, label %9
]
3: ; preds = %2
%4 = load i32, i32* @stderr
%5 = load i8*, i8** %1
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
br label %39
9: ; preds = %2, %2
%10 = icmp ugt i32 %0, 2
br i1 %10, label %11, label %18
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
18: ; preds = %9
%19 = load i32*, i32** @stdin
%20 = load i32*, i32** @stdout
br label %21
21: ; preds = %18, %11
%22 = phi i32* [ %14, %11 ], [ %19, %18 ]
%23 = phi i32* [ %17, %11 ], [ %20, %18 ]
%24 = icmp ne i32* %22, null
%25 = icmp ne i32* %23, null
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = load i32, i32* @EBADF
store i32 %28, i32* @errno
%29 = sub nsw i32 0, %28
%30 = tail call i32 @perror(i32* null)
br label %35
31: ; preds = %21
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = tail call i32 @myxor(i32* %22, i32* %23, i8* %33)
br label %35
35: ; preds = %31, %27
%36 = phi i32 [ 0, %31 ], [ %29, %27 ]
%37 = tail call i32 @fclose(i32* %22)
%38 = tail call i32 @fclose(i32* %23)
br label %39
39: ; preds = %35, %3
%40 = phi i32 [ %8, %3 ], [ %36, %35 ]
ret i32 %40
}