#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*/ b64_decode(char *, char *, size_t);
int b64_get_ascii_wc(size_t);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ load_file(char *, char **, size_t *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, unsigned char *, size_t);
int /*<<< orphan*/ xor_decode(unsigned char *, unsigned char *, size_t,
                              unsigned char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  unsigned char *encdata, *decdata;
  size_t b64encdatalen, encdatalen;
  if (argc < 3)
    return 0x1;
  if (!load_file(argv[1], (char **)&encdata, &b64encdatalen)) {
    free(encdata);
    return 0x2;
  }
  encdatalen = 1 + b64_get_ascii_wc(b64encdatalen);
  decdata = malloc(encdatalen * sizeof(*encdata));
  if (NULL == decdata) {
    free(encdata);
    return 0x2;
  }
  memset(decdata, 0, encdatalen * sizeof(*encdata));
  b64_decode((char *)decdata, (char *)encdata, b64encdatalen);
  memcpy(encdata, decdata, (encdatalen - 1) * sizeof(*encdata));
  encdata[encdatalen] = '\0';
  memset(decdata, 0, encdatalen * sizeof(*encdata));
  xor_decode(decdata, encdata, encdatalen, (unsigned char *)argv[2],
             strlen(argv[2]));
  write(1, decdata, encdatalen);
  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)
cmpl   $0x3,-0x8(%rbp)
jge    11cc <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1301 <main+0x161>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10c0 <load_file@plt>
cmp    $0x0,%eax
jne    11ff <main+0x5f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1301 <main+0x161>
mov    -0x28(%rbp),%rdi
call   1090 <b64_get_ascii_wc@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x0,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1243 <main+0xa3>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1301 <main+0x161>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
shl    $0x0,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <b64_decode@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
sub    $0x1,%rdx
shl    $0x0,%rdx
call   10a0 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
shl    $0x0,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %eax,%r8d
call   1080 <xor_decode@plt>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
call   1040 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%ebp
cmp    $0x3,%edi
jl     1280 <main+0xe0>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   10c0 <load_file@plt>
test   %eax,%eax
je     1272 <main+0xd2>
mov    0x8(%rsp),%rdi
call   1090 <b64_get_ascii_wc@plt>
movslq %eax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1272 <main+0xd2>
mov    %rax,%r15
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1070 <memset@plt>
mov    (%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
call   1050 <b64_decode@plt>
mov    (%rsp),%rdi
lea    -0x1(%rbx),%rdx
mov    %r15,%rsi
call   10a0 <memcpy@plt>
mov    (%rsp),%rax
movb   $0x0,(%rax,%rbx,1)
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1070 <memset@plt>
mov    (%rsp),%r12
mov    0x10(%r14),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
call   1080 <xor_decode@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
jmp    1280 <main+0xe0>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %71
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @load_file(i8* %16, i8** %6, i64* %8)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
store i32 2, i32* %3
br label %71
22: ; preds = %13
%23 = load i64, i64* %8
%24 = call i32 @b64_get_ascii_wc(i64 %23)
%25 = add nsw i32 1, %24
%26 = sext i32 %25 to i64
store i64 %26, i64* %9
%27 = load i64, i64* %9
%28 = mul i64 %27, 1
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp eq i8* null, %30
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
store i32 2, i32* %3
br label %71
35: ; preds = %22
%36 = load i8*, i8** %7
%37 = load i64, i64* %9
%38 = mul i64 %37, 1
%39 = call i32 @memset(i8* %36, i32 0, i64 %38)
%40 = load i8*, i8** %7
%41 = load i8*, i8** %6
%42 = load i64, i64* %8
%43 = call i32 @b64_decode(i8* %40, i8* %41, i64 %42)
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = load i64, i64* %9
%47 = sub i64 %46, 1
%48 = mul i64 %47, 1
%49 = call i32 @memcpy(i8* %44, i8* %45, i64 %48)
%50 = load i8*, i8** %6
%51 = load i64, i64* %9
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %7
%54 = load i64, i64* %9
%55 = mul i64 %54, 1
%56 = call i32 @memset(i8* %53, i32 0, i64 %55)
%57 = load i8*, i8** %7
%58 = load i8*, i8** %6
%59 = load i64, i64* %9
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @xor_decode(i8* %57, i8* %58, i64 %59, i8* %62, i32 %66)
%68 = load i8*, i8** %7
%69 = load i64, i64* %9
%70 = call i32 @write(i32 1, i8* %68, i64 %69)
store i32 0, i32* %3
br label %71
71: ; preds = %35, %32, %19, %12
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %43, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @load_file(i8* %10, i8** %3, i64* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @free(i8* %14)
br label %43
16: ; preds = %8
%17 = load i64, i64* %4
%18 = call i32 @b64_get_ascii_wc(i64 %17)
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = call i8* @malloc(i64 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
br label %43
26: ; preds = %16
%27 = call i32 @memset(i8* %21, i32 0, i64 %20)
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = call i32 @b64_decode(i8* %21, i8* %28, i64 %29)
%31 = load i8*, i8** %3
%32 = add nsw i64 %20, -1
%33 = call i32 @memcpy(i8* %31, i8* %21, i64 %32)
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 %20
store i8 0, i8* %35
%36 = call i32 @memset(i8* %21, i32 0, i64 %20)
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @xor_decode(i8* %21, i8* %37, i64 %20, i8* %39, i32 %40)
%42 = call i32 @write(i32 1, i8* %21, i64 %20)
br label %43
43: ; preds = %2, %26, %23, %13
%44 = phi i32 [ 2, %23 ], [ 0, %26 ], [ 2, %13 ], [ 1, %2 ]
ret i32 %44
}