#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void main(int argc, char *argv[]) {
  if (argc < 4) {
    printf("Usage: %s <source1> <source2> <destination>\n", argv[0]);
    return;
  }
  FILE *qcrypt_input1;
  FILE *qcrypt_input2;
  FILE *qcrypt_output;
  if ((qcrypt_input1 = fopen(argv[1], "r")) == NULL) {
    printf("couldn't open first source %s for writing\n", argv[1]);
    return;
  }
  if ((qcrypt_input2 = fopen(argv[2], "r")) == NULL) {
    printf("couldn't open second source %s for writing\n", argv[2]);
    return;
  }
  if ((qcrypt_output = fopen(argv[3], "w")) == NULL) {
    printf("couldn't  open destination %s for writing\n", argv[3]);
    return;
  }
  int c1, c2;
  char xored;
  while ((c1 = fgetc(qcrypt_input1)) != EOF &&
         (c2 = fgetc(qcrypt_input2)) != EOF) {
    xored = c1 ^ c2;
    fputc(xored, qcrypt_output);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    1171 <main+0x31>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ac <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1222 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <main+0x151>
jmp    1227 <main+0xe7>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
mov    0x2daa(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x32(%rbp)
je     1264 <main+0x124>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    1274 <main+0x134>
jmp    1291 <main+0x151>
mov    -0x2c(%rbp),%eax
xor    -0x30(%rbp),%eax
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1227 <main+0xe7>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x4,%edi
jge    115d <main+0x1d>
lea    0xea8(%rip),%rdi
jmp    121a <main+0xda>
mov    0x8(%rbx),%rdi
lea    0xec5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f5 <main+0xb5>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1202 <main+0xc2>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
lea    0xeea(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120f <main+0xcf>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e30(%rip),%r13
cmp    0x0(%r13),%eax
je     11eb <main+0xab>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%r13),%eax
je     11eb <main+0xab>
xor    %ebx,%eax
movsbl %al,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
jne    11c0 <main+0x80>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
add    $0x8,%rbx
lea    0xe2f(%rip),%rdi
jmp    121a <main+0xda>
add    $0x10,%rbx
lea    0xe4d(%rip),%rdi
jmp    121a <main+0xda>
add    $0x18,%rbx
lea    0xe6e(%rip),%rdi
mov    (%rbx),%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Usage: %s <source1> <source2> <destination>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"couldn't open first source %s for writing\0A\00"
@.str.3 = [44 x i8] c"couldn't open second source %s for writing\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [43 x i8] c"couldn't open destination %s for writing\0A\00"
@EOF = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 %0, i32* %3
store i8** %1, i8*** %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %72
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %5
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %72
29: ; preds = %18
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %72
40: ; preds = %29
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %44, i32** %7
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i8**, i8*** %4
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %49)
br label %72
51: ; preds = %40
br label %52
52: ; preds = %64, %51
%53 = load i32*, i32** %5
%54 = call i32 @fgetc(i32* %53)
store i32 %54, i32* %8
%55 = load i32, i32* @EOF
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i32*, i32** %6
%59 = call i32 @fgetc(i32* %58)
store i32 %59, i32* %9
%60 = load i32, i32* @EOF
%61 = icmp ne i32 %59, %60
br label %62
62: ; preds = %57, %52
%63 = phi i1 [ false, %52 ], [ %61, %57 ]
br i1 %63, label %64, label %72
64: ; preds = %62
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = xor i32 %65, %66
%68 = trunc i32 %67 to i8
store i8 %68, i8* %10
%69 = load i8, i8* %10
%70 = load i32*, i32** %7
%71 = call i32 @fputc(i8 signext %69, i32* %70)
br label %52
72: ; preds = %13, %24, %35, %46, %62
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"Usage: %s <source1> <source2> <destination>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"couldn't open first source %s for writing\0A\00"
@.str.3 = [44 x i8] c"couldn't open second source %s for writing\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [43 x i8] c"couldn't open destination %s for writing\0A\00"
@EOF = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %35, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %35, label %14
14: ; preds = %9
%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.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %35, label %19
19: ; preds = %14
%20 = tail call i32 @fgetc(i32* %7)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %40, label %23
23: ; preds = %19, %28
%24 = phi i32 [ %32, %28 ], [ %20, %19 ]
%25 = tail call i32 @fgetc(i32* %12)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %40, label %28
28: ; preds = %23
%29 = xor i32 %25, %24
%30 = trunc i32 %29 to i8
%31 = tail call i32 @fputc(i8 signext %30, i32* %17)
%32 = tail call i32 @fgetc(i32* %7)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %40, label %23
35: ; preds = %14, %9, %4, %2
%36 = phi i8** [ %1, %2 ], [ %5, %4 ], [ %10, %9 ], [ %15, %14 ]
%37 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), %14 ]
%38 = load i8*, i8** %36
%39 = tail call i32 @printf(i8* %37, i8* %38)
br label %40
40: ; preds = %23, %28, %35, %19
ret void
}