#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *inputPrompt(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ streamDecoder(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ streamEncoder(char *, int /*<<< orphan*/ *, char *);
int main(int argc, char *argv[]) {
  char *secretFile, *ballastImage, *packageImage, *outputFile;
  if (argc == 1) {
    secretFile = inputPrompt((char *)"The secret file:  ");
    ballastImage = inputPrompt((char *)"The ballsast PNG: ");
    packageImage = inputPrompt((char *)"Save package as:  ");
    outputFile = inputPrompt((char *)"Save output as:   ");
  } else if (argc == 5) {
    secretFile = argv[1];
    ballastImage = argv[2];
    packageImage = argv[3];
    outputFile = argv[4];
  } else {
    printf(
        "Incorrect usage:\n      ./run (to input the filenames manually)\n     "
        " ./run [secret (in)] [ballast (in)] [package (out)] [decode (out)]\n");
    exit(1);
  }
  FILE *secretStream = fopen(secretFile, "r");
  FILE *outSecretStream = fopen(outputFile, "w+");
  streamEncoder(ballastImage, secretStream, packageImage);
  fclose(secretStream);
  streamDecoder(packageImage, outSecretStream);
  fclose(outSecretStream);
  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   $0x1,-0x8(%rbp)
jne    11d5 <main+0x65>
lea    0xe69(%rip),%rdi
call   1040 <inputPrompt@plt>
mov    %rax,-0x18(%rbp)
lea    0xe6c(%rip),%rdi
call   1040 <inputPrompt@plt>
mov    %rax,-0x20(%rbp)
lea    0xe6f(%rip),%rdi
call   1040 <inputPrompt@plt>
mov    %rax,-0x28(%rbp)
lea    0xe72(%rip),%rdi
call   1040 <inputPrompt@plt>
mov    %rax,-0x30(%rbp)
jmp    122f <main+0xbf>
cmpl   $0x5,-0x8(%rbp)
jne    1214 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    122a <main+0xba>
lea    0xe31(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    122f <main+0xbf>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <streamEncoder@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <streamDecoder@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x5,%edi
je     11c5 <main+0x55>
cmp    $0x1,%edi
jne    122e <main+0xbe>
lea    0xe72(%rip),%rdi
call   1050 <inputPrompt@plt>
mov    %rax,%r15
lea    0xe76(%rip),%rdi
call   1050 <inputPrompt@plt>
mov    %rax,%r14
lea    0xe7a(%rip),%rdi
call   1050 <inputPrompt@plt>
mov    %rax,%r13
lea    0xe7e(%rip),%rdi
call   1050 <inputPrompt@plt>
mov    %rax,%r12
jmp    11d5 <main+0x65>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%r14
mov    0x18(%rsi),%r13
mov    0x20(%rsi),%r12
lea    0xe70(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe60(%rip),%rsi
mov    %r12,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1070 <streamEncoder@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <streamDecoder@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"The secret file: \00"
@.str.1 = [19 x i8] c"The ballsast PNG: \00"
@.str.2 = [19 x i8] c"Save package as: \00"
@.str.3 = [19 x i8] c"Save output as: \00"
@.str.4 = [136 x i8] c"Incorrect usage:\0A ./run (to input the filenames manually)\0A ./run [secret (in)] [ballast (in)] [package (out)] [decode (out)]\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %6
%16 = call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %7
%17 = call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %8
%18 = call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8* %18, i8** %9
br label %39
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 5
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
store i8* %34, i8** %9
br label %38
35: ; preds = %19
%36 = call i32 @printf(i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %22
br label %39
39: ; preds = %38, %14
%40 = load i8*, i8** %6
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %41, i32** %10
%42 = load i8*, i8** %9
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %43, i32** %11
%44 = load i8*, i8** %7
%45 = load i32*, i32** %10
%46 = load i8*, i8** %8
%47 = call i32 @streamEncoder(i8* %44, i32* %45, i8* %46)
%48 = load i32*, i32** %10
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %8
%51 = load i32*, i32** %11
%52 = call i32 @streamDecoder(i8* %50, i32* %51)
%53 = load i32*, i32** %11
%54 = call i32 @fclose(i32* %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"The secret file: \00"
@.str.1 = [19 x i8] c"The ballsast PNG: \00"
@.str.2 = [19 x i8] c"Save package as: \00"
@.str.3 = [19 x i8] c"Save output as: \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"w+\00"
@str = [135 x i8] c"Incorrect usage:\0A ./run (to input the filenames manually)\0A ./run [secret (in)] [ballast (in)] [package (out)] [decode (out)]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %17 [
i32 1, label %3
i32 5, label %8
]
3: ; preds = %2
%4 = tail call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i8* @inputPrompt(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %20
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 4
%16 = load i8*, i8** %15
br label %20
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([135 x i8], [135 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %8, %3
%21 = phi i8* [ %6, %3 ], [ %14, %8 ]
%22 = phi i8* [ %7, %3 ], [ %16, %8 ]
%23 = phi i8* [ %5, %3 ], [ %12, %8 ]
%24 = phi i8* [ %4, %3 ], [ %10, %8 ]
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = tail call i32 @streamEncoder(i8* %23, i32* %25, i8* %21)
%28 = tail call i32 @fclose(i32* %25)
%29 = tail call i32 @streamDecoder(i8* %21, i32* %26)
%30 = tail call i32 @fclose(i32* %26)
ret i32 0
}