#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*/ decodeblock(unsigned char *, char *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
char *strchr(char *, int);
int strlen(char *);
char *base64_decode(char *b64src) {
  char *clrdst = (char *)malloc(((strlen(b64src) - 1) / 3) * 4 + 4 + 50);
  char b64[] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  int c, phase, i;
  unsigned char in[4];
  char *p;
  clrdst[0] = '\0';
  phase = 0;
  i = 0;
  while (b64src[i]) {
    c = (int)b64src[i];
    if (c == '=') {
      decodeblock(in, clrdst);
      break;
    }
    p = strchr(b64, c);
    if (p) {
      in[phase] = p - b64;
      phase = (phase + 1) % 4;
      if (phase == 0) {
        decodeblock(in, clrdst);
        in[0] = in[1] = in[2] = in[3] = 0;
      }
    }
    i++;
  }
  clrdst = (char *)realloc(clrdst, strlen(clrdst) + 1);
  return clrdst;
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
shl    $0x2,%edi
add    $0x4,%edi
add    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x41,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x6c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1279 <base64_decode+0x119>
mov    -0x8(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x3d,-0x64(%rbp)
jne    11fe <base64_decode+0x9e>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <decodeblock@plt>
jmp    1279 <base64_decode+0x119>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     126b <base64_decode+0x10b>
mov    -0x78(%rbp),%rax
lea    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %al,%cl
movslq -0x68(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jne    1266 <base64_decode+0x106>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <decodeblock@plt>
movb   $0x0,-0x6d(%rbp)
movb   $0x0,-0x6e(%rbp)
movb   $0x0,-0x6f(%rbp)
movb   $0x0,-0x70(%rbp)
jmp    126b <base64_decode+0x10b>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11c1 <base64_decode+0x61>
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    0x36(,%rax,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe49(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
movb   $0x0,(%rax)
xor    %ebp,%ebp
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    11e4 <base64_decode+0x94>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
movsbl (%rbx),%esi
test   %esi,%esi
je     123e <base64_decode+0xee>
cmp    $0x3d,%sil
je     1231 <base64_decode+0xe1>
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11e0 <base64_decode+0x90>
sub    %r15d,%eax
movslq %ebp,%rcx
mov    %al,0xc(%rsp,%rcx,1)
lea    0x1(%rcx),%ebp
add    $0x4,%ecx
test   %ebp,%ebp
cmovns %ebp,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%ebp
jne    11e0 <base64_decode+0x90>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <decodeblock@plt>
movl   $0x0,0xc(%rsp)
xor    %ebp,%ebp
jmp    11e0 <base64_decode+0x90>
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1060 <decodeblock@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r14,%rdi
call   1070 <realloc@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.base64_decode.b64 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define i8* @base64_decode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [65 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = sdiv i32 %12, 3
%14 = mul nsw i32 %13, 4
%15 = add nsw i32 %14, 4
%16 = add nsw i32 %15, 50
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %3
%19 = bitcast [65 x i8]* %4 to i8*
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
store i32 0, i32* %6
store i32 0, i32* %7
br label %22
22: ; preds = %72, %1
%23 = load i8*, i8** %2
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %75
29: ; preds = %22
%30 = load i8*, i8** %2
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
store i32 %35, i32* %5
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 61
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%40 = load i8*, i8** %3
%41 = call i32 @decodeblock(i8* %39, i8* %40)
br label %75
42: ; preds = %29
%43 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* %5
%45 = call i8* @strchr(i8* %43, i32 %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %72
48: ; preds = %42
%49 = load i8*, i8** %9
%50 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i8
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 %56
store i8 %54, i8* %57
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
%60 = srem i32 %59, 4
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %71
63: ; preds = %48
%64 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%65 = load i8*, i8** %3
%66 = call i32 @decodeblock(i8* %64, i8* %65)
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 0, i8* %67
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 0, i8* %68
%69 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 0, i8* %69
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 0, i8* %70
br label %71
71: ; preds = %63, %48
br label %72
72: ; preds = %71, %42
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %22
75: ; preds = %38, %22
%76 = load i8*, i8** %3
%77 = load i8*, i8** %3
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %78, 1
%80 = call i64 @realloc(i8* %76, i32 %79)
%81 = inttoptr i64 %80 to i8*
store i8* %81, i8** %3
%82 = load i8*, i8** %3
ret i8* %82
}

LLVM IR (-O2):
@__const.base64_decode.b64 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define i8* @base64_decode(i8* %0) {
%2 = alloca [65 x i8]
%3 = alloca i32
%4 = bitcast i32* %3 to [4 x i8]*
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sdiv i32 %6, 3
%8 = shl nsw i32 %7, 2
%9 = add nsw i32 %8, 54
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%13 = bitcast i32* %3 to i8*
store i8 0, i8* %11
%14 = ptrtoint [65 x i8]* %2 to i64
br label %15
15: ; preds = %37, %1
%16 = phi i64 [ %39, %37 ], [ 0, %1 ]
%17 = phi i32 [ %38, %37 ], [ 0, %1 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
switch i8 %19, label %22 [
i8 0, label %40
i8 61, label %20
]
20: ; preds = %15
%21 = call i32 @decodeblock(i8* %13, i8* %11)
br label %40
22: ; preds = %15
%23 = sext i8 %19 to i32
%24 = call i8* @strchr(i8* %12, i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %37, label %26
26: ; preds = %22
%27 = ptrtoint i8* %24 to i64
%28 = sub i64 %27, %14
%29 = trunc i64 %28 to i8
%30 = sext i32 %17 to i64
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 %30
store i8 %29, i8* %31
%32 = add nsw i32 %17, 1
%33 = srem i32 %32, 4
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @decodeblock(i8* %13, i8* %11)
store i32 0, i32* %3
br label %37
37: ; preds = %26, %35, %22
%38 = phi i32 [ 0, %35 ], [ %33, %26 ], [ %17, %22 ]
%39 = add nuw i64 %16, 1
br label %15
40: ; preds = %15, %20
%41 = call i32 @strlen(i8* %11)
%42 = add nsw i32 %41, 1
%43 = call i64 @realloc(i8* %11, i32 %42)
%44 = inttoptr i64 %43 to i8*
ret i8* %44
}