#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: %s <source> <destination>\n", argv[0]);
    return;
  }
  FILE *qcrypt_input;
  FILE *qcrypt_output;
  if ((qcrypt_input = fopen(argv[1], "r")) == NULL) {
    printf("couldn't open %s for writing\n", argv[1]);
    return;
  }
  if ((qcrypt_output = fopen(argv[2], "w")) == NULL) {
    printf("couldn't  open %s for writing\n", argv[2]);
  }
  uint8_t offset = 7;
  int c;
  while ((c = fgetc(qcrypt_input)) != EOF) {
    fputc(c ^ offset++, qcrypt_output);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    1171 <main+0x31>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
jmp    1222 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea2(%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    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    1222 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e2 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
movl   $0x7,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
je     1222 <main+0xe2>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11e9 <main+0xa9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x3,%edi
jge    115b <main+0x1b>
lea    0xeaa(%rip),%rdi
jmp    11f2 <main+0xb2>
mov    0x8(%r15),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e7 <main+0xa7>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xec4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119b <main+0x5b>
mov    0x10(%r15),%rsi
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e3e(%rip),%r15
cmp    (%r15),%eax
je     11dc <main+0x9c>
mov    $0x7,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%eax
add    $0x1,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    11c0 <main+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x8,%r15
lea    0xe32(%rip),%rdi
mov    (%r15),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Usage: %s <source> <destination>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"couldn't open %s for writing\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"couldn't open %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
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %51
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %5
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %51
27: ; preds = %16
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %33, %27
store i32 7, i32* %7
br label %39
39: ; preds = %44, %38
%40 = load i32*, i32** %5
%41 = call i32 @fgetc(i32* %40)
store i32 %41, i32* %8
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i32, i32* %8
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
%48 = xor i32 %45, %46
%49 = load i32*, i32** %6
%50 = call i32 @fputc(i32 %48, i32* %49)
br label %39
51: ; preds = %11, %22, %39
ret void
}

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