#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 /*<<< orphan*/ exit(int);
void *fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: explode <infile>");
    printf("\nOutput will be sent to stdout");
    printf("\nTo use stdin as the infile, use - as the infile");
    exit(1);
  }
  FILE *input = stdin;
  if (argv[1][0] != '-') {
    input = fopen(argv[1], "rb");
    if (input == 0) {
      printf("Could not open provided infile\n");
      exit(1);
    }
  }
  FILE *rand = fopen("/dev/urandom", "rb");
  while (1) {
    int in = fgetc(input);
    if (in == EOF) {
      exit(0);
    }
    char key_char = fgetc(rand);
    char result_char = in ^ key_char;
    fputc(key_char, stdout);
    fputc(result_char, stdout);
  }
}


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   $0x2,-0x8(%rbp)
jge    119e <main+0x4e>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11fe <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <main+0xa9>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11fe <main+0xae>
lea    0xe86(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%eax
jne    123a <main+0xea>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x25(%rbp)
mov    -0x24(%rbp),%eax
movsbl -0x25(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x26(%rbp)
mov    -0x25(%rbp),%al
mov    0x2d74(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x26(%rbp),%al
mov    0x2d60(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1215 <main+0xc5>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     119c <main+0x3c>
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11b1 <main+0x51>
mov    0x2e3c(%rip),%rax
mov    (%rax),%r14
jmp    11db <main+0x7b>
lea    0xeb0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11db <main+0x7b>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe89(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
mov    0x2ddd(%rip),%r12
cmp    %ebx,(%r12)
je     1243 <main+0xe3>
mov    0x2dc0(%rip),%r13
mov    %r15,%rdi
call   1050 <fgetc@plt>
xor    %eax,%ebx
mov    0x0(%r13),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    0x0(%r13),%esi
movsbl %bl,%edi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
cmp    %ebx,(%r12)
jne    1210 <main+0xb0>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: explode <infile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@.str.2 = [49 x i8] c"\0ATo use stdin as the infile, use - as the infile\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [32 x i8] c"Could not open provided infile\0A\00"
@.str.5 = [13 x i8] c"/dev/urandom\00"
@EOF = global i32 0
@stdout = 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 i8
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32*, i32** @stdin
store i32* %19, i32** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 45
br i1 %26, label %27, label %38
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
br label %38
38: ; preds = %37, %18
%39 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %7
br label %40
40: ; preds = %38, %49
%41 = load i32*, i32** %6
%42 = call i8* @fgetc(i32* %41)
%43 = ptrtoint i8* %42 to i32
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %40
%50 = load i32*, i32** %7
%51 = call i8* @fgetc(i32* %50)
%52 = ptrtoint i8* %51 to i8
store i8 %52, i8* %9
%53 = load i32, i32* %8
%54 = load i8, i8* %9
%55 = sext i8 %54 to i32
%56 = xor i32 %53, %55
%57 = trunc i32 %56 to i8
store i8 %57, i8* %10
%58 = load i8, i8* %9
%59 = load i32, i32* @stdout
%60 = call i32 @fputc(i8 signext %58, i32 %59)
%61 = load i8, i8* %10
%62 = load i32, i32* @stdout
%63 = call i32 @fputc(i8 signext %61, i32 %62)
br label %40
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: explode <infile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@.str.2 = [49 x i8] c"\0ATo use stdin as the infile, use - as the infile\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.5 = [13 x i8] c"/dev/urandom\00"
@EOF = global i32 0
@stdout = global i32 0
@str = [31 x i8] c"Could not open provided infile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32*, i32** @stdin
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 45
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15, %9
%22 = phi i32* [ %16, %15 ], [ %10, %9 ]
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = tail call i8* @fgetc(i32* %22)
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %27, %26
br i1 %28, label %29, label %31
29: ; preds = %31, %21
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %21, %31
%32 = phi i64 [ %43, %31 ], [ %25, %21 ]
%33 = tail call i8* @fgetc(i32* %23)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i8
%36 = xor i64 %32, %34
%37 = trunc i64 %36 to i8
%38 = load i32, i32* @stdout
%39 = tail call i32 @fputc(i8 signext %35, i32 %38)
%40 = load i32, i32* @stdout
%41 = tail call i32 @fputc(i8 signext %37, i32 %40)
%42 = tail call i8* @fgetc(i32* %22)
%43 = ptrtoint i8* %42 to i64
%44 = trunc i64 %43 to i32
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %45, %44
br i1 %46, label %29, label %31
}