#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 */
unsigned char *Decrypt(unsigned char *, int, char *);
unsigned char *Encrypt(unsigned char *, int, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
char tolower(char);
int main(int iArgumentCount, char *pchArguments[]) {
  unsigned char *puchData = (unsigned char *)"Test string@";
  unsigned char *puchEncrypted = Encrypt(puchData, 73, "MONKEY BALLS");
  unsigned char *puchDecrypted =
      Decrypt(puchEncrypted, 73 + 32, "MONKEY BALLS");
  if (!puchDecrypted) {
    printf("It looks like that's either the wrong password, or the file is not "
           "encrypted with our encryption!\n");
    return 1;
  }
  if (iArgumentCount != 3 || (int)strlen(pchArguments[1]) != 2) {
    return 1;
  }
  char chType = tolower(pchArguments[1][1]);
  char *pchFileName = pchArguments[2];
  switch (chType) {
  case 'e':
    printf("You want to encrypt %s!\n", pchFileName);
    break;
  case 'd':
    printf("You want to decrypt %s!\n", pchFileName);
    break;
  default:
    printf("Unknown function -%c.", pchArguments[1][1]);
    break;
  }
  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)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x49,%esi
lea    0xe8c(%rip),%rdx
call   1050 <Encrypt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x69,%esi
lea    0xe73(%rip),%rdx
call   1070 <Decrypt@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <main+0x78>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0x139>
cmpl   $0x3,-0x8(%rbp)
jne    11e8 <main+0x98>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
je     11f4 <main+0xa4>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%edi
call   1060 <tolower@plt>
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
movsbl -0x29(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x64,%eax
je     1251 <main+0x101>
jmp    1229 <main+0xd9>
mov    -0x3c(%rbp),%eax
sub    $0x65,%eax
jne    1268 <main+0x118>
jmp    123a <main+0xea>
mov    -0x38(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1282 <main+0x132>
mov    -0x38(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe90(%rip),%rdi
lea    0xe96(%rip),%rbp
mov    $0x49,%esi
mov    %rbp,%rdx
call   1060 <Encrypt@plt>
mov    %rax,%rdi
mov    $0x69,%esi
mov    %rbp,%rdx
call   1080 <Decrypt@plt>
test   %rax,%rax
je     11d7 <main+0x77>
mov    $0x1,%ebp
cmp    $0x3,%ebx
jne    1214 <main+0xb4>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jne    1214 <main+0xb4>
movsbl 0x1(%rbx),%edi
call   1070 <tolower@plt>
mov    0x10(%r14),%rsi
movsbl %al,%eax
cmp    $0x64,%eax
je     11ea <main+0x8a>
cmp    $0x65,%eax
jne    11fc <main+0x9c>
lea    0xe45(%rip),%rdi
jmp    11f1 <main+0x91>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    1214 <main+0xb4>
lea    0xe42(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1214 <main+0xb4>
mov    0x8(%r14),%rax
movsbl 0x1(%rax),%esi
lea    0xe41(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Test string@\00"
@.str.1 = [13 x i8] c"MONKEY BALLS\00"
@.str.2 = [99 x i8] c"It looks like that's either the wrong password, or the file is not encrypted with our encryption!\0A\00"
@.str.3 = [25 x i8] c"You want to encrypt %s!\0A\00"
@.str.4 = [25 x i8] c"You want to decrypt %s!\0A\00"
@.str.5 = [22 x i8] c"Unknown function -%c.\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %6
%12 = call i8* @Encrypt(i8* %11, i32 73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = call i8* @Decrypt(i8* %13, i32 105, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %57
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 3
br i1 %21, label %29, label %22
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strlen(i8* %25)
%27 = trunc i64 %26 to i32
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %22, %19
store i32 1, i32* %3
br label %57
30: ; preds = %22
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = call signext i8 @tolower(i8 signext %35)
store i8 %36, i8* %9
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %10
%40 = load i8, i8* %9
%41 = sext i8 %40 to i32
switch i32 %41, label %48 [
i32 101, label %42
i32 100, label %45
]
42: ; preds = %30
%43 = load i8*, i8** %10
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %56
45: ; preds = %30
%46 = load i8*, i8** %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %56
48: ; preds = %30
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %48, %45, %42
store i32 0, i32* %3
br label %57
57: ; preds = %56, %29, %17
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [13 x i8] c"Test string@\00"
@.str.1 = [13 x i8] c"MONKEY BALLS\00"
@.str.3 = [25 x i8] c"You want to encrypt %s!\0A\00"
@.str.4 = [25 x i8] c"You want to decrypt %s!\0A\00"
@.str.5 = [22 x i8] c"Unknown function -%c.\00"
@str = [98 x i8] c"It looks like that's either the wrong password, or the file is not encrypted with our encryption!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @Encrypt(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i8* @Decrypt(i8* %3, i32 105, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str, i64 0, i64 0))
br label %33
8: ; preds = %2
%9 = icmp eq i32 %0, 3
br i1 %9, label %10, label %33
10: ; preds = %8
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = trunc i64 %13 to i32
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %33
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = load i8, i8* %17
%19 = tail call signext i8 @tolower(i8 signext %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = sext i8 %19 to i32
switch i32 %22, label %27 [
i32 101, label %23
i32 100, label %25
]
23: ; preds = %16
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %33
25: ; preds = %16
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %33
27: ; preds = %16
%28 = load i8*, i8** %11
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %23, %25, %27, %8, %10, %6
%34 = phi i32 [ 1, %6 ], [ 1, %10 ], [ 1, %8 ], [ 0, %27 ], [ 0, %25 ], [ 0, %23 ]
ret i32 %34
}