#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 uint32_t;

/* Variables and functions */
unsigned char *b64dec(int *, unsigned char *);
unsigned char *ecb(int, unsigned char *, unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ open_file(char *, int *, unsigned char **);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  if (!argv[1]) {
    puts("Usage: ./a.out <filename>");
    exit(1);
  }
  unsigned char *buf, *decdata, *plaintext;
  uint32_t inlen;
  if (open_file(argv[1], &inlen, (unsigned char **)&buf)) {
    puts("error loading file content");
    return 1;
  }
  unsigned char key[] = "YELLOW SUBMARINE";
  decdata = b64dec(&inlen, buf);
  puts("ok");
  free(buf);
  plaintext = ecb(inlen, decdata, key);
  for (int i = 0; i < inlen; i++) {
    printf("%c", plaintext[i]);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11ab <main+0x3b>
lea    0xe64(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <open_file@plt>
cmp    $0x0,%rax
je     11e2 <main+0x72>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1287 <main+0x117>
mov    0xe57(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe54(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe52(%rip),%al
mov    %al,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdi
call   1050 <b64dec@plt>
mov    %rax,-0x20(%rbp)
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1080 <ecb@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1274 <main+0x104>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
lea    0xddb(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1070 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1242 <main+0xd2>
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1251 <main+0xd1>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <open_file@plt>
test   %rax,%rax
je     11c0 <main+0x40>
lea    0xe69(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1247 <main+0xc7>
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
mov    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdi
call   1060 <b64dec@plt>
mov    %rax,%rbx
lea    0xe4b(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
call   1090 <ecb@plt>
cmpl   $0x0,0x4(%rsp)
jle    123b <main+0xbb>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe1b(%rip),%r14
nopl   (%rax)
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1080 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xa0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xda8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [27 x i8] c"error loading file content\00"
@__const.main.key = [17 x i8] c"YELLOW SUBMARINE\00"
@.str.2 = [3 x i8] c"ok\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [1 x i8] zeroinitializer
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 [17 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @open_file(i8* %22, i32* %9, i8** %6)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %54
27: ; preds = %19
%28 = bitcast [17 x i8]* %10 to i8*
%29 = load i8*, i8** %6
%30 = call i8* @b64dec(i32* %9, i8* %29)
store i8* %30, i8** %7
%31 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %9
%35 = load i8*, i8** %7
%36 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%37 = call i8* @ecb(i32 %34, i8* %35, i8* %36)
store i8* %37, i8** %8
store i32 0, i32* %11
br label %38
38: ; preds = %49, %27
%39 = load i32, i32* %11
%40 = load i32, i32* %9
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i8*, i8** %8
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %38
52: ; preds = %38
%53 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %54
54: ; preds = %52, %25
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [27 x i8] c"error loading file content\00"
@__const.main.key = [17 x i8] c"YELLOW SUBMARINE\00"
@.str.2 = [3 x i8] c"ok\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = bitcast i8** %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = call i64 @open_file(i8* %7, i32* %4, i8** %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %41
19: ; preds = %12
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i8* @b64dec(i32* %4, i8* %21)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* %4
%27 = call i8* @ecb(i32 %26, i8* %22, i8* %20)
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %32, %19
%31 = call i32 @putchar(i32 10)
br label %41
32: ; preds = %19, %32
%33 = phi i64 [ %37, %32 ], [ 0, %19 ]
%34 = getelementptr inbounds i8, i8* %27, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %35)
%37 = add nuw nsw i64 %33, 1
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %32, label %30
41: ; preds = %30, %17
%42 = phi i32 [ 1, %17 ], [ 0, %30 ]
ret i32 %42
}