#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 */

/* Variables and functions */
int /*<<< orphan*/ get_filepointers(char *, char *, unsigned char *, int);
int /*<<< orphan*/ get_filepointers_read(char *, char *, unsigned char *, int);
int /*<<< orphan*/ get_passphrase(unsigned char *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *remove_file_ending(char *);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, char *argv[]) {
  unsigned char *passphrase;
  char *filename;
  char *encrypted_filename;
  int encswitch = 0;
  int i = 0;
  passphrase = malloc(30 * sizeof(char));
  for (i = 0; i < 30; i++) {
    passphrase[i] = '\0';
  }
  filename = malloc(50 * sizeof(char));
  encrypted_filename = malloc(60 * sizeof(char));
  if (argc == 2) {
    get_passphrase(passphrase);
    printf("Your passphrase is %s\n", passphrase);
    filename = argv[1];
    strcat(encrypted_filename, filename);
    strcat(encrypted_filename, ".encrypted");
    get_filepointers(filename, encrypted_filename, passphrase, encswitch);
    return 0;
  } else if (argc == 3) {
    get_passphrase(passphrase);
    printf("Your passphrase is %s\n", passphrase);
    encrypted_filename = argv[2];
    filename = remove_file_ending(encrypted_filename);
    encswitch = 1;
    get_filepointers(encrypted_filename, filename, passphrase, encswitch);
    return 0;
  } else if (argc == 4) {
    filename = argv[2];
    encrypted_filename = argv[3];
    encswitch = 2;
    get_filepointers_read(filename, encrypted_filename, passphrase, encswitch);
    return 0;
  } else {
    printf("Invalid command line arguments supplied\n");
    printf("Valid: filename (to encrypt)\n");
    printf("Valid: -d filename (to decrypt)\n");
    printf("Valid: -hack filename enc-filename (to hack passphrase)\n");
    return 1;
  }
}


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)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x1e,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x1e,-0x30(%rbp)
jge    11cd <main+0x5d>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a9 <main+0x39>
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1257 <main+0xe7>
mov    -0x18(%rbp),%rdi
call   1060 <get_passphrase@plt>
mov    -0x18(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <get_filepointers@plt>
movl   $0x0,-0x4(%rbp)
jmp    1344 <main+0x1d4>
cmpl   $0x3,-0x8(%rbp)
jne    12bc <main+0x14c>
mov    -0x18(%rbp),%rdi
call   1060 <get_passphrase@plt>
mov    -0x18(%rbp),%rsi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <remove_file_ending@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <get_filepointers@plt>
movl   $0x0,-0x4(%rbp)
jmp    1344 <main+0x1d4>
cmpl   $0x4,-0x8(%rbp)
jne    1305 <main+0x195>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <get_filepointers_read@plt>
movl   $0x0,-0x4(%rbp)
jmp    1344 <main+0x1d4>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1e,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movups %xmm0,0xe(%rax)
mov    $0x3c,%edi
call   1080 <malloc@plt>
cmp    $0x4,%ebp
je     1213 <main+0x93>
cmp    $0x3,%ebp
je     122d <main+0xad>
cmp    $0x2,%ebp
jne    126a <main+0xea>
mov    %rax,%r12
mov    %rbx,%rdi
call   1070 <get_passphrase@plt>
lea    0xe2d(%rip),%rdi
xor    %r15d,%r15d
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r14),%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <strcat@plt>
lea    0xe21(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <get_filepointers@plt>
jmp    12a0 <main+0x120>
mov    0x10(%r14),%rdi
mov    0x18(%r14),%rsi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1030 <get_filepointers_read@plt>
xor    %r15d,%r15d
jmp    12a0 <main+0x120>
mov    %rbx,%rdi
call   1070 <get_passphrase@plt>
lea    0xdc4(%rip),%rdi
xor    %r15d,%r15d
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r14),%rbp
mov    %rbp,%rdi
call   1090 <remove_file_ending@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1050 <get_filepointers@plt>
jmp    12a0 <main+0x120>
lea    0xdb1(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
lea    0xdde(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Your passphrase is %s\0A\00"
@.str.1 = [11 x i8] c".encrypted\00"
@.str.2 = [41 x i8] c"Invalid command line arguments supplied\0A\00"
@.str.3 = [30 x i8] c"Valid: filename (to encrypt)\0A\00"
@.str.4 = [33 x i8] c"Valid: -d filename (to decrypt)\0A\00"
@.str.5 = [57 x i8] c"Valid: -hack filename enc-filename (to hack passphrase)\0A\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 i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i8* @malloc(i32 30)
store i8* %11, i8** %6
store i32 0, i32* %10
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 30
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
br label %12
23: ; preds = %12
%24 = call i8* @malloc(i32 50)
store i8* %24, i8** %7
%25 = call i8* @malloc(i32 60)
store i8* %25, i8** %8
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %46
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = call i32 @get_passphrase(i8* %29)
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %7
%36 = load i8*, i8** %8
%37 = load i8*, i8** %7
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8*, i8** %8
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8*, i8** %7
%42 = load i8*, i8** %8
%43 = load i8*, i8** %6
%44 = load i32, i32* %9
%45 = call i32 @get_filepointers(i8* %41, i8* %42, i8* %43, i32 %44)
store i32 0, i32* %3
br label %84
46: ; preds = %23
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %64
49: ; preds = %46
%50 = load i8*, i8** %6
%51 = call i32 @get_passphrase(i8* %50)
%52 = load i8*, i8** %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %52)
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
store i8* %56, i8** %8
%57 = load i8*, i8** %8
%58 = call i8* @remove_file_ending(i8* %57)
store i8* %58, i8** %7
store i32 1, i32* %9
%59 = load i8*, i8** %8
%60 = load i8*, i8** %7
%61 = load i8*, i8** %6
%62 = load i32, i32* %9
%63 = call i32 @get_filepointers(i8* %59, i8* %60, i8* %61, i32 %62)
store i32 0, i32* %3
br label %84
64: ; preds = %46
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 4
br i1 %66, label %67, label %79
67: ; preds = %64
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 2
%70 = load i8*, i8** %69
store i8* %70, i8** %7
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 3
%73 = load i8*, i8** %72
store i8* %73, i8** %8
store i32 2, i32* %9
%74 = load i8*, i8** %7
%75 = load i8*, i8** %8
%76 = load i8*, i8** %6
%77 = load i32, i32* %9
%78 = call i32 @get_filepointers_read(i8* %74, i8* %75, i8* %76, i32 %77)
store i32 0, i32* %3
br label %84
79: ; preds = %64
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %84
84: ; preds = %79, %67, %49, %28
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [23 x i8] c"Your passphrase is %s\0A\00"
@.str.1 = [11 x i8] c".encrypted\00"
@str = [40 x i8] c"Invalid command line arguments supplied\00"
@str.6 = [29 x i8] c"Valid: filename (to encrypt)\00"
@str.7 = [32 x i8] c"Valid: -d filename (to decrypt)\00"
@str.8 = [56 x i8] c"Valid: -hack filename enc-filename (to hack passphrase)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%4 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
switch i32 %0, label %26 [
i32 2, label %5
i32 3, label %13
i32 4, label %20
]
5: ; preds = %2
%6 = tail call i32 @get_passphrase(i8* %3)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcat(i8* %4, i8* %9)
%11 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @get_filepointers(i8* %9, i8* %4, i8* %3, i32 0)
br label %31
13: ; preds = %2
%14 = tail call i32 @get_passphrase(i8* %3)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %3)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i8* @remove_file_ending(i8* %17)
%19 = tail call i32 @get_filepointers(i8* %17, i8* %18, i8* %3, i32 1)
br label %31
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @get_filepointers_read(i8* %22, i8* %24, i8* %3, i32 2)
br label %31
26: ; preds = %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.8, i64 0, i64 0))
br label %31
31: ; preds = %26, %20, %13, %5
%32 = phi i32 [ 0, %5 ], [ 0, %13 ], [ 0, %20 ], [ 1, %26 ]
ret i32 %32
}