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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ _IOFBF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           int);
int main(int argc, char *argv[]) {
  FILE *f1 = fopen(argv[1], "rb"), *f2 = fopen(argv[2], "wb");
  char buf1[8096], buf2[8096];
  unsigned char k;
  int c, i;
  setvbuf(f1, buf1, _IOFBF, sizeof(buf1));
  setvbuf(f2, buf2, _IOFBF, sizeof(buf2));
  for (k = 0xC7, i = 0;;) {
    if ((c = fgetc(f1)) == EOF)
      break;
    fputc(((unsigned char)c) ^ k, f2);
    k = (k + 3 * (i % 133)) & 0xFF;
    i++;
  }
  fclose(f2);
  fclose(f1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3f70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1fc0(%rbp),%rsi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    $0x1fa0,%ecx
call   1060 <setvbuf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x3f60(%rbp),%rsi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    $0x1fa0,%ecx
call   1060 <setvbuf@plt>
movb   $0xc7,-0x3f61(%rbp)
movl   $0x0,-0x3f6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x3f68(%rbp)
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
jne    1209 <main+0xb9>
jmp    126c <main+0x11c>
mov    -0x3f68(%rbp),%eax
movzbl %al,%eax
movzbl -0x3f61(%rbp),%ecx
xor    %ecx,%eax
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
movzbl -0x3f61(%rbp),%eax
mov    %eax,-0x3f70(%rbp)
mov    -0x3f6c(%rbp),%eax
mov    $0x85,%ecx
cltd
idiv   %ecx
mov    -0x3f70(%rbp),%eax
imul   $0x3,%edx,%ecx
add    %ecx,%eax
and    $0xff,%eax
mov    %al,-0x3f61(%rbp)
mov    -0x3f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f6c(%rbp)
jmp    11e6 <main+0x96>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x3f70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f58,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    0x10(%rbx),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x2e47(%rip),%r14
mov    (%r14),%edx
lea    0x1fb0(%rsp),%rsi
mov    %r13,%rdi
mov    $0x1fa0,%ecx
call   1060 <setvbuf@plt>
mov    (%r14),%edx
lea    0x10(%rsp),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x1fa0,%ecx
call   1060 <setvbuf@plt>
mov    %r13,%rdi
call   1040 <fgetc@plt>
mov    0x2e16(%rip),%r14
cmp    (%r14),%eax
je     1235 <main+0xe5>
mov    $0xc7,%ebx
xor    %r12d,%r12d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%ecx
mov    $0xf6603d99,%edx
imul   %rdx,%rcx
shr    $0x27,%rcx
imul   $0x18f,%ecx,%ecx
mov    %r12d,%ebp
sub    %ecx,%ebp
xor    %ebx,%eax
movzbl %al,%edi
mov    0x8(%rsp),%rsi
call   1050 <fputc@plt>
add    %ebx,%ebp
movzbl %bpl,%ebx
add    $0x1,%r15d
mov    %r13,%rdi
call   1040 <fgetc@plt>
add    $0x3,%r12d
cmp    (%r14),%eax
jne    11f0 <main+0xa0>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x3f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@_IOFBF = global i32 0
@EOF = 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 [8096 x i8]
%9 = alloca [8096 x i8]
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %6
%22 = getelementptr inbounds [8096 x i8], [8096 x i8]* %8, i64 0, i64 0
%23 = load i32, i32* @_IOFBF
%24 = call i32 @setvbuf(i32* %21, i8* %22, i32 %23, i32 8096)
%25 = load i32*, i32** %7
%26 = getelementptr inbounds [8096 x i8], [8096 x i8]* %9, i64 0, i64 0
%27 = load i32, i32* @_IOFBF
%28 = call i32 @setvbuf(i32* %25, i8* %26, i32 %27, i32 8096)
store i8 -57, i8* %10
store i32 0, i32* %12
br label %29
29: ; preds = %35, %2
%30 = load i32*, i32** %6
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %11
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %29
br label %55
35: ; preds = %29
%36 = load i32, i32* %11
%37 = trunc i32 %36 to i8
%38 = zext i8 %37 to i32
%39 = load i8, i8* %10
%40 = zext i8 %39 to i32
%41 = xor i32 %38, %40
%42 = trunc i32 %41 to i8
%43 = load i32*, i32** %7
%44 = call i32 @fputc(i8 zeroext %42, i32* %43)
%45 = load i8, i8* %10
%46 = zext i8 %45 to i32
%47 = load i32, i32* %12
%48 = srem i32 %47, 133
%49 = mul nsw i32 3, %48
%50 = add nsw i32 %46, %49
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i8
store i8 %52, i8* %10
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %29
55: ; preds = %34
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@_IOFBF = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8096 x i8]
%4 = alloca [8096 x i8]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [8096 x i8], [8096 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [8096 x i8], [8096 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @_IOFBF
%14 = call i32 @setvbuf(i32* %7, i8* %11, i32 %13, i32 8096)
%15 = load i32, i32* @_IOFBF
%16 = call i32 @setvbuf(i32* %10, i8* %12, i32 %15, i32 8096)
%17 = call i32 @fgetc(i32* %7)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %35, label %20
20: ; preds = %2, %20
%21 = phi i32 [ %32, %20 ], [ %17, %2 ]
%22 = phi i32 [ %31, %20 ], [ 0, %2 ]
%23 = phi i32 [ %30, %20 ], [ 199, %2 ]
%24 = xor i32 %21, %23
%25 = trunc i32 %24 to i8
%26 = call i32 @fputc(i8 zeroext %25, i32* %10)
%27 = urem i32 %22, 133
%28 = mul nuw nsw i32 %27, 3
%29 = add nuw nsw i32 %28, %23
%30 = and i32 %29, 255
%31 = add nuw nsw i32 %22, 1
%32 = call i32 @fgetc(i32* %7)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %20
35: ; preds = %20, %2
%36 = call i32 @fclose(i32* %10)
%37 = call i32 @fclose(i32* %7)
ret i32 0
}