#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("USAGE: %s INPUT OUTPUT\n", argv[0]);
    return 0;
  }
  FILE *input = fopen(argv[1], "rb");
  FILE *output = fopen(argv[2], "wb");
  if (!input || !output) {
    printf("Error\n");
    return 0;
  }
  char k[] = "CENSORED";
  char c, p, t = 0;
  int i = 0;
  while ((p = fgetc(input)) != EOF) {
    c = (p + (k[i % strlen(k)] ^ t) + i * i) & 0xff;
    t = p;
    i++;
    fputc(c, output);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <main+0x14d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe63(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <main+0x87>
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <main+0xa1>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <main+0x14d>
mov    0xe2d(%rip),%rax
mov    %rax,-0x29(%rbp)
mov    0xe2b(%rip),%al
mov    %al,-0x21(%rbp)
movb   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x2b(%rbp)
movsbl %al,%eax
mov    0x2dc2(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1296 <main+0x146>
movsbl -0x2b(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x29(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cltd
idiv   %ecx
mov    -0x34(%rbp),%eax
movslq %edx,%rcx
movsbl -0x29(%rbp,%rcx,1),%ecx
movsbl -0x2c(%rbp),%edx
xor    %edx,%ecx
add    %ecx,%eax
mov    -0x30(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    %ecx,%eax
and    $0xff,%eax
mov    %al,-0x2a(%rbp)
mov    -0x2b(%rbp),%al
mov    %al,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2a(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1210 <main+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1222 <main+0xc2>
mov    0x8(%rbx),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
test   %r14,%r14
je     1235 <main+0xd5>
mov    %rax,%r13
test   %rax,%rax
je     1235 <main+0xd5>
movabs $0x4445524f534e4543,%rax
52 45 44
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e13(%rip),%r15
cmp    (%r15),%al
je     1241 <main+0xe1>
xor    %ebp,%ebp
xor    %r12d,%r12d
nop
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
xor    0x8(%rsp,%rdx,1),%r12b
mov    %ebp,%eax
imul   %ebp,%eax
add    %bl,%al
add    %r12b,%al
add    $0x1,%ebp
movsbl %al,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %ebx,%r12d
cmp    (%r15),%al
jne    11e0 <main+0x80>
jmp    1241 <main+0xe1>
mov    (%rbx),%rsi
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1241 <main+0xe1>
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"USAGE: %s INPUT OUTPUT\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [7 x i8] c"Error\0A\00"
@__const.main.k = [9 x i8] c"CENSORED\00"
@EOF = global i8 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 [9 x i8]
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 0, i32* %3
br label %73
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %6
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = load i32*, i32** %7
%33 = icmp ne i32* %32, null
br i1 %33, label %36, label %34
34: ; preds = %31, %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %73
36: ; preds = %31
%37 = bitcast [9 x i8]* %8 to i8*
store i8 0, i8* %11
store i32 0, i32* %12
br label %38
38: ; preds = %45, %36
%39 = load i32*, i32** %6
%40 = call signext i8 @fgetc(i32* %39)
store i8 %40, i8* %10
%41 = sext i8 %40 to i32
%42 = load i8, i8* @EOF
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %72
45: ; preds = %38
%46 = load i8, i8* %10
%47 = sext i8 %46 to i32
%48 = load i32, i32* %12
%49 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = srem i32 %48, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = load i8, i8* %11
%57 = sext i8 %56 to i32
%58 = xor i32 %55, %57
%59 = add nsw i32 %47, %58
%60 = load i32, i32* %12
%61 = load i32, i32* %12
%62 = mul nsw i32 %60, %61
%63 = add nsw i32 %59, %62
%64 = and i32 %63, 255
%65 = trunc i32 %64 to i8
store i8 %65, i8* %9
%66 = load i8, i8* %10
store i8 %66, i8* %11
%67 = load i32, i32* %12
%68 = add nsw i32 %67, 1
store i32 %68, i32* %12
%69 = load i8, i8* %9
%70 = load i32*, i32** %7
%71 = call i32 @fputc(i8 signext %69, i32* %70)
br label %38
72: ; preds = %38
store i32 0, i32* %3
br label %73
73: ; preds = %72, %34, %15
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [24 x i8] c"USAGE: %s INPUT OUTPUT\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@__const.main.k = [9 x i8] c"CENSORED\00"
@EOF = global i8 0
@str = [6 x i8] c"Error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [9 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %45
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp ne i32* %11, null
%16 = icmp ne i32* %14, null
%17 = and i1 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %8
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %45
20: ; preds = %8
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%22 = call signext i8 @fgetc(i32* %11)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %44, label %25
25: ; preds = %20, %25
%26 = phi i8 [ %41, %25 ], [ %22, %20 ]
%27 = phi i32 [ %39, %25 ], [ 0, %20 ]
%28 = phi i8 [ %26, %25 ], [ 0, %20 ]
%29 = call i32 @strlen(i8* %21)
%30 = srem i32 %27, %29
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = xor i8 %33, %28
%35 = mul nsw i32 %27, %27
%36 = trunc i32 %35 to i8
%37 = add i8 %26, %36
%38 = add i8 %37, %34
%39 = add nuw nsw i32 %27, 1
%40 = call i32 @fputc(i8 signext %38, i32* %14)
%41 = call signext i8 @fgetc(i32* %11)
%42 = load i8, i8* @EOF
%43 = icmp eq i8 %41, %42
br i1 %43, label %44, label %25
44: ; preds = %25, %20
br label %45
45: ; preds = %18, %44, %5
ret i32 0
}