#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 *break_repeated_xor(int, 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, *lalala;
  uint32_t inlen, *bests;
  if (open_file(argv[1], &inlen, (unsigned char **)&buf)) {
    puts("error loading file content");
    return 1;
  }
  decdata = b64dec(&inlen, buf);
  free(buf);
  lalala = break_repeated_xor(inlen, decdata);
  for (int i = 0; i < inlen; i++)
    printf("%c", lalala[i]);
  puts("");
  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)
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    1258 <main+0xe8>
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdi
call   1050 <b64dec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <break_repeated_xor@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1245 <main+0xd5>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
lea    0xe07(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1070 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1213 <main+0xa3>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1231 <main+0xb1>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <open_file@plt>
test   %rax,%rax
je     11bd <main+0x3d>
lea    0xe69(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1227 <main+0xa7>
mov    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdi
call   1060 <b64dec@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1090 <break_repeated_xor@plt>
cmpl   $0x0,0x4(%rsp)
jle    121b <main+0x9b>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe3d(%rip),%r14
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1080 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1200 <main+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc8(%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"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [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 i32*
%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 %51
27: ; preds = %19
%28 = load i8*, i8** %6
%29 = call i8* @b64dec(i32* %9, i8* %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = load i32, i32* %9
%33 = load i8*, i8** %7
%34 = call i8* @break_repeated_xor(i32 %32, i8* %33)
store i8* %34, i8** %8
store i32 0, i32* %11
br label %35
35: ; preds = %46, %27
%36 = load i32, i32* %11
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i8*, i8** %8
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %35
49: ; preds = %35
%50 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %25
%52 = load i32, i32* %3
ret i32 %52
}

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