#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 EXIT_FAILURE;
int EXIT_SUCCESS;
unsigned int RAND_MAX;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
unsigned int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int c, r;
  FILE *inputFile, *outputFile;
  if (argc < 3 || argc > 4 || (inputFile = fopen(argv[1], "rb")) == NULL ||
      (outputFile = fopen(argv[2], "wb")) == NULL) {
    fputs("crypt parameters: inputFile outputFile [key]\n", stderr);
    return EXIT_FAILURE;
  }
  if (argc == 4)
    srand(atoi(argv[3]));
  while ((c = getc(inputFile)) != EOF) {
    do {
      r = rand() / ((RAND_MAX + 1U) / 256);
    } while (r >= 256);
    putc(c ^ r, outputFile);
  }
  return EXIT_SUCCESS;
}


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   $0x3,-0x8(%rbp)
jl     11de <main+0x6e>
cmpl   $0x4,-0x8(%rbp)
jg     11de <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11de <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe38(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1204 <main+0x94>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <main+0x121>
cmpl   $0x4,-0x8(%rbp)
jne    1222 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1040 <srand@plt>
jmp    1227 <main+0xb7>
mov    -0x20(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dae(%rip),%rcx
cmp    (%rcx),%eax
je     1285 <main+0x115>
jmp    1247 <main+0xd7>
mov    $0x0,%al
call   1090 <rand@plt>
mov    0x2d8b(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
shr    $0x8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    1247 <main+0xd7>
mov    -0x14(%rbp),%edi
xor    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <putc@plt>
jmp    1227 <main+0xb7>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
lea    -0x5(%rbp),%eax
cmp    $0xfffffffe,%eax
jb     1238 <main+0xc8>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xc8>
mov    %rax,%r13
mov    0x10(%r15),%rdi
lea    0xe50(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xc8>
mov    %rax,%r14
cmp    $0x4,%ebp
jne    11d9 <main+0x69>
mov    0x18(%r15),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    %r13,%rdi
call   1080 <getc@plt>
mov    0x2e00(%rip),%r12
mov    0x2dd1(%rip),%r15
cmp    (%r12),%eax
je     1254 <main+0xe4>
mov    %eax,%ebp
mov    0x2de2(%rip),%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
mov    (%rbx),%ecx
add    $0x1,%ecx
shr    $0x8,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0xff,%eax
jg     1200 <main+0x90>
xor    %ebp,%eax
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %r13,%rdi
call   1080 <getc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1200 <main+0x90>
jmp    1254 <main+0xe4>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    0xdbe(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2d74(%rip),%r15
mov    (%r15),%eax
add    $0x8,%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"
@.str.2 = [46 x i8] c"crypt parameters: inputFile outputFile [key]\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@RAND_MAX = global i32 0
@EXIT_SUCCESS = 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 i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %27, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 4
br i1 %14, label %27, label %15
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %9
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %21, %15, %12, %2
%28 = load i32, i32* @stderr
%29 = call i32 @fputs(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %64
31: ; preds = %21
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = call i32 @srand(i32 %38)
br label %40
40: ; preds = %34, %31
br label %41
41: ; preds = %56, %40
%42 = load i32*, i32** %8
%43 = call i32 @getc(i32* %42)
store i32 %43, i32* %6
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %62
46: ; preds = %41
br label %47
47: ; preds = %53, %46
%48 = call i32 (...) @rand()
%49 = load i32, i32* @RAND_MAX
%50 = add i32 %49, 1
%51 = udiv i32 %50, 256
%52 = udiv i32 %48, %51
store i32 %52, i32* %7
br label %53
53: ; preds = %47
%54 = load i32, i32* %7
%55 = icmp sge i32 %54, 256
br i1 %55, label %47, label %56
56: ; preds = %53
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = xor i32 %57, %58
%60 = load i32*, i32** %9
%61 = call i32 @putc(i32 %59, i32* %60)
br label %41
62: ; preds = %41
%63 = load i32, i32* @EXIT_SUCCESS
store i32 %63, i32* %3
br label %64
64: ; preds = %62, %27
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [46 x i8] c"crypt parameters: inputFile outputFile [key]\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@RAND_MAX = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -2
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10, %5, %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %44
18: ; preds = %10
%19 = icmp eq i32 %0, 4
br i1 %19, label %20, label %25
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = tail call i32 @srand(i32 %23)
br label %25
25: ; preds = %20, %18
%26 = tail call i32 @getc(i32* %8)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %44, label %29
29: ; preds = %25, %38
%30 = phi i32 [ %41, %38 ], [ %26, %25 ]
br label %31
31: ; preds = %29, %31
%32 = tail call i32 (...) @rand()
%33 = load i32, i32* @RAND_MAX
%34 = add i32 %33, 1
%35 = lshr i32 %34, 8
%36 = udiv i32 %32, %35
%37 = icmp sgt i32 %36, 255
br i1 %37, label %31, label %38
38: ; preds = %31
%39 = xor i32 %36, %30
%40 = tail call i32 @putc(i32 %39, i32* %13)
%41 = tail call i32 @getc(i32* %8)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %29
44: ; preds = %38, %25, %15
%45 = phi i32* [ @EXIT_FAILURE, %15 ], [ @EXIT_SUCCESS, %25 ], [ @EXIT_SUCCESS, %38 ]
%46 = load i32, i32* %45
ret i32 %46
}