#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*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  if (argc == 4) {
    FILE *source = fopen(argv[1], "rb");
    FILE *dest = fopen(argv[2], "wb");
    FILE *key = fopen(argv[3], "rb");
    unsigned char buffk[1], buffs[2];
    if (source == NULL || key == NULL) {
      printf("Could not open one of the files\n Usage: %s <source> "
             "<destinatio> <key>",
             argv[0]);
      return 0;
    }
    while (fread(buffk, 1, 1, key) != 0) {
      fread(buffs, 1, 1, source);
      buffs[0] ^= buffk[0];
      fwrite(buffs, 1, 1, dest);
    }
    return 0;
  }
  printf("Usage: %s <source> <destinatio> <key>", argv[0]);
  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)
jne    1246 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11be <main+0x7e>
cmpq   $0x0,-0x28(%rbp)
jne    11dd <main+0x9d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1260 <main+0x120>
jmp    11e2 <main+0xa2>
lea    -0x29(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     123a <main+0xfa>
lea    -0x2b(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x29(%rbp),%ecx
movzbl -0x2b(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x2b(%rbp)
lea    -0x2b(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
jmp    11e2 <main+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    1260 <main+0x120>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd3(%rip),%rdi
call   1040 <printf@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
sub    $0x10,%rsp
mov    %rsi,%r12
cmp    $0x4,%edi
jne    1219 <main+0xd9>
mov    0x8(%r12),%rdi
lea    0xe9b(%rip),%rbx
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    0x10(%r12),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x18(%r12),%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
test   %r15,%r15
je     1226 <main+0xe6>
mov    %rax,%rbx
test   %rax,%rax
je     1226 <main+0xe6>
lea    0xd(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1236 <main+0xf6>
lea    0xe(%rsp),%r12
lea    0xd(%rsp),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
movzbl 0xe(%rsp),%eax
xor    0xd(%rsp),%al
mov    %al,0xe(%rsp)
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11d0 <main+0x90>
jmp    1236 <main+0xf6>
mov    (%r12),%rsi
lea    0xe03(%rip),%rdi
jmp    1231 <main+0xf1>
mov    (%r12),%rsi
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [71 x i8] c"Could not open one of the files\0A Usage: %s <source> <destinatio> <key>\00"
@.str.3 = [38 x i8] c"Usage: %s <source> <destinatio> <key>\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 i32*
%9 = alloca [1 x i8]
%10 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %58
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %13
%29 = load i32*, i32** %8
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %28, %13
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 0, i32* %3
br label %63
36: ; preds = %28
br label %37
37: ; preds = %42, %36
%38 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%39 = load i32*, i32** %8
%40 = call i64 @fread(i8* %38, i32 1, i32 1, i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %37
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i64 @fread(i8* %43, i32 1, i32 1, i32* %44)
%46 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = xor i32 %51, %48
%53 = trunc i32 %52 to i8
store i8 %53, i8* %49
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%55 = load i32*, i32** %7
%56 = call i32 @fwrite(i8* %54, i32 1, i32 1, i32* %55)
br label %37
57: ; preds = %37
store i32 0, i32* %3
br label %63
58: ; preds = %2
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %61)
store i32 0, i32* %3
br label %63
63: ; preds = %58, %57, %31
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [71 x i8] c"Could not open one of the files\0A Usage: %s <source> <destinatio> <key>\00"
@.str.3 = [38 x i8] c"Usage: %s <source> <destinatio> <key>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1 x i8]
%4 = alloca [2 x i8]
%5 = icmp eq i32 %0, 4
br i1 %5, label %6, label %37
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%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 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%18 = icmp eq i32* %9, null
%19 = icmp eq i32* %15, null
%20 = or i1 %18, %19
br i1 %20, label %24, label %21
21: ; preds = %6
%22 = call i64 @fread(i8* %16, i32 1, i32 1, i32* %15)
%23 = icmp eq i64 %22, 0
br i1 %23, label %36, label %27
24: ; preds = %6
%25 = load i8*, i8** %1
%26 = tail call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %36
27: ; preds = %21, %27
%28 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %9)
%29 = load i8, i8* %16
%30 = load i8, i8* %17
%31 = xor i8 %30, %29
store i8 %31, i8* %17
%32 = sext i8 %31 to i32
%33 = tail call i32 @fputc(i32 %32, i32* %12)
%34 = call i64 @fread(i8* %16, i32 1, i32 1, i32* %15)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %27
36: ; preds = %27, %21, %24
br label %40
37: ; preds = %2
%38 = load i8*, i8** %1
%39 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %36
ret i32 0
}