#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: xor <infile> <keyfile>");
    printf("\nOutput will be sent to stdout");
    printf("\nTo use stdin as the infile, use - as the infile");
    printf("\nTo use stdin as the keyfile, use - as the keyfile");
    printf("\nIf - is used for both the infile and keyfile, the output will be "
           "the xor of all adjacent bytes from stdin\n");
    exit(1);
  }
  FILE *input = stdin;
  if (argv[1][0] != '-') {
    input = fopen(argv[1], "rb");
    if (input == 0) {
      printf("Could not open provided infile\n");
      exit(1);
    }
  }
  FILE *keyfile = stdin;
  if (argv[2][0] != '-') {
    keyfile = fopen(argv[2], "rb");
    if (keyfile == 0) {
      printf("Could not open provided keyfile\n");
      exit(1);
    }
  }
  while (1) {
    int in = fgetc(input);
    if (in == EOF) {
      exit(0);
    }
    int key = fgetc(keyfile);
    if (key == EOF) {
      if (argv[2][0] != '-') {
        fclose(keyfile);
        keyfile = fopen(argv[2], "rb");
        key = fgetc(keyfile);
        if (key == EOF) {
          exit(1);
        }
      } else {
        exit(1);
      }
    }
    char enc = in ^ key;
    fputc(enc, stdout);
  }
}


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   $0x3,-0x8(%rbp)
jge    11c6 <main+0x66>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1226 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf16(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0xc1>
lea    0xefe(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1226 <main+0xc6>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1286 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xeb6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1281 <main+0x121>
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1286 <main+0x126>
jmp    128b <main+0x12b>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%eax
jne    12b0 <main+0x150>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2d1a(%rip),%rcx
cmp    (%rcx),%eax
jne    133f <main+0x1df>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1330 <main+0x1d0>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe13(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2cc7(%rip),%rcx
cmp    (%rcx),%eax
jne    132b <main+0x1cb>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    133a <main+0x1da>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    133f <main+0x1df>
mov    -0x24(%rbp),%eax
xor    -0x28(%rbp),%eax
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    0x2c7e(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    128b <main+0x12b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11b9 <main+0x49>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1050 <printf@plt>
lea    0xec3(%rip),%rdi
call   1050 <printf@plt>
lea    0xf2c(%rip),%rdi
jmp    1218 <main+0xa8>
mov    %rsi,%r14
mov    0x2e25(%rip),%rbx
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11d4 <main+0x64>
mov    (%rbx),%rbx
mov    %rbx,%r15
jmp    11f4 <main+0x84>
lea    0xec6(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11ee <main+0x7e>
lea    0xed8(%rip),%rdi
jmp    1218 <main+0xa8>
mov    %rax,%r15
mov    (%rbx),%rbx
mov    0x10(%r14),%rdi
cmpb   $0x2d,(%rdi)
je     1227 <main+0xb7>
lea    0xe9d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <main+0xb7>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2daa(%rip),%r13
cmp    0x0(%r13),%eax
jne    1243 <main+0xd3>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %eax,%ebp
mov    0x2d84(%rip),%r12
jmp    126e <main+0xfe>
xchg   %ax,%ax
xor    %ebp,%eax
mov    (%r12),%esi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     123c <main+0xcc>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    1250 <main+0xe0>
mov    0x10(%r14),%rax
cmpb   $0x2d,(%rax)
je     12ae <main+0x13e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xe09(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    1250 <main+0xe0>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: xor <infile> <keyfile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@.str.2 = [49 x i8] c"\0ATo use stdin as the infile, use - as the infile\00"
@.str.3 = [51 x i8] c"\0ATo use stdin as the keyfile, use - as the keyfile\00"
@.str.4 = [108 x i8] c"\0AIf - is used for both the infile and keyfile, the output will be the xor of all adjacent bytes from stdin\0A\00"
@stdin = global i32* null
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [32 x i8] c"Could not open provided infile\0A\00"
@.str.7 = [33 x i8] c"Could not open provided keyfile\0A\00"
@EOF = global i32 0
@stdout = 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
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32*, i32** @stdin
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 45
br i1 %28, label %29, label %40
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
br label %40
40: ; preds = %39, %20
%41 = load i32*, i32** @stdin
store i32* %41, i32** %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 45
br i1 %48, label %49, label %60
49: ; preds = %40
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %53, i32** %7
%54 = load i32*, i32** %7
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %49
br label %60
60: ; preds = %59, %40
br label %61
61: ; preds = %60, %101
%62 = load i32*, i32** %6
%63 = call i32 @fgetc(i32* %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = load i32, i32* @EOF
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %61
%70 = load i32*, i32** %7
%71 = call i32 @fgetc(i32* %70)
store i32 %71, i32* %9
%72 = load i32, i32* %9
%73 = load i32, i32* @EOF
%74 = icmp eq i32 %72, %73
br i1 %74, label %75, label %101
75: ; preds = %69
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = getelementptr inbounds i8, i8* %78, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %81, 45
br i1 %82, label %83, label %98
83: ; preds = %75
%84 = load i32*, i32** %7
%85 = call i32 @fclose(i32* %84)
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 2
%88 = load i8*, i8** %87
%89 = call i32* @fopen(i8* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %89, i32** %7
%90 = load i32*, i32** %7
%91 = call i32 @fgetc(i32* %90)
store i32 %91, i32* %9
%92 = load i32, i32* %9
%93 = load i32, i32* @EOF
%94 = icmp eq i32 %92, %93
br i1 %94, label %95, label %97
95: ; preds = %83
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %83
br label %100
98: ; preds = %75
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %97
br label %101
101: ; preds = %100, %69
%102 = load i32, i32* %8
%103 = load i32, i32* %9
%104 = xor i32 %102, %103
%105 = trunc i32 %104 to i8
store i8 %105, i8* %10
%106 = load i8, i8* %10
%107 = load i32, i32* @stdout
%108 = call i32 @fputc(i8 signext %106, i32 %107)
br label %61
}

LLVM IR (-O2):
@.str = [30 x i8] c"Usage: xor <infile> <keyfile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@.str.2 = [49 x i8] c"\0ATo use stdin as the infile, use - as the infile\00"
@.str.3 = [51 x i8] c"\0ATo use stdin as the keyfile, use - as the keyfile\00"
@stdin = global i32* null
@.str.5 = [3 x i8] c"rb\00"
@EOF = global i32 0
@stdout = global i32 0
@str = [32 x i8] c"Could not open provided keyfile\00"
@str.8 = [31 x i8] c"Could not open provided infile\00"
@str.9 = [107 x i8] c"\0AIf - is used for both the infile and keyfile, the output will be the xor of all adjacent bytes from stdin\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([107 x i8], [107 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32*, i32** @stdin
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %25, label %17
17: ; preds = %11
%18 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = load i32*, i32** @stdin
br label %25
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %20, %11
%26 = phi i32* [ %21, %20 ], [ %12, %11 ]
%27 = phi i32* [ %18, %20 ], [ %12, %11 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 45
br i1 %31, label %38, label %32
32: ; preds = %25
%33 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %32, %25
%39 = phi i32* [ %33, %32 ], [ %26, %25 ]
%40 = tail call i32 @fgetc(i32* %27)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %66, %38
%44 = tail call i32 @exit(i32 0)
unreachable
45: ; preds = %38, %66
%46 = phi i32 [ %73, %66 ], [ %40, %38 ]
%47 = phi i32* [ %67, %66 ], [ %39, %38 ]
%48 = tail call i32 @fgetc(i32* %47)
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %66
51: ; preds = %45
%52 = load i8*, i8** %28
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 45
br i1 %54, label %64, label %55
55: ; preds = %51
%56 = tail call i32 @fclose(i32* %47)
%57 = load i8*, i8** %28
%58 = tail call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%59 = tail call i32 @fgetc(i32* %58)
%60 = load i32, i32* @EOF
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = tail call i32 @exit(i32 1)
unreachable
64: ; preds = %51
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %55, %45
%67 = phi i32* [ %58, %55 ], [ %47, %45 ]
%68 = phi i32 [ %59, %55 ], [ %48, %45 ]
%69 = xor i32 %68, %46
%70 = trunc i32 %69 to i8
%71 = load i32, i32* @stdout
%72 = tail call i32 @fputc(i8 signext %70, i32 %71)
%73 = tail call i32 @fgetc(i32* %27)
%74 = load i32, i32* @EOF
%75 = icmp eq i32 %73, %74
br i1 %75, label %43, label %45
}