#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*/ char4toX(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *b64decode(const char *raw) {
  ;
  int raw_len = strlen(raw);
  ;
  char *buffer = (char *)malloc(raw_len / 4 * 3 + 1);
  memset(buffer, 0x0, raw_len / 4 * 3 + 1);
  char ch4[4];
  for (int idx = 0, raw_idx = 0; raw_idx < raw_len; idx += 3, raw_idx += 4) {
    memset(ch4, 0x0, 4);
    strncpy(ch4, raw + raw_idx, 4);
    char4toX(buffer + idx, ch4);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<b64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120c <b64decode+0xbc>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <char4toX@plt>
mov    -0x20(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <b64decode+0x5c>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b64decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0x3(%r12),%eax
test   %r12d,%r12d
cmovns %r12d,%eax
sar    $0x2,%eax
lea    (%rax,%rax,2),%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
test   %r12d,%r12d
jle    11d8 <b64decode+0x88>
xor    %ebp,%ebp
lea    0x4(%rsp),%r13
mov    %r15,%rbx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    (%r14,%rbp,1),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <char4toX@plt>
add    $0x4,%rbp
add    $0x3,%rbx
cmp    %ebp,%r12d
jg     11a0 <b64decode+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @b64decode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [4 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 4
%12 = mul nsw i32 %11, 3
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = sdiv i32 %17, 4
%19 = mul nsw i32 %18, 3
%20 = add nsw i32 %19, 1
%21 = call i32 @memset(i8* %16, i32 0, i32 %20)
store i32 0, i32* %6
store i32 0, i32* %7
br label %22
22: ; preds = %41, %1
%23 = load i32, i32* %7
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 4)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%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 = call i32 @strncpy(i8* %29, i8* %33, i32 4)
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%40 = call i32 @char4toX(i8* %38, i8* %39)
br label %41
41: ; preds = %26
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 3
store i32 %43, i32* %6
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 4
store i32 %45, i32* %7
br label %22
46: ; preds = %22
%47 = load i8*, i8** %4
ret i8* %47
}

LLVM IR (-O2):
define i8* @b64decode(i8* %0) {
%2 = alloca [4 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = sdiv i32 %3, 4
%5 = mul nsw i32 %4, 3
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @memset(i8* %8, i32 0, i32 %6)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%11 = icmp sgt i32 %3, 0
br i1 %11, label %13, label %12
12: ; preds = %13, %1
ret i8* %8
13: ; preds = %1, %13
%14 = phi i64 [ %21, %13 ], [ 0, %1 ]
%15 = phi i64 [ %22, %13 ], [ 0, %1 ]
%16 = call i32 @memset(i8* %10, i32 0, i32 4)
%17 = getelementptr inbounds i8, i8* %0, i64 %15
%18 = call i32 @strncpy(i8* %10, i8* %17, i32 4)
%19 = getelementptr inbounds i8, i8* %8, i64 %14
%20 = call i32 @char4toX(i8* %19, i8* %10)
%21 = add nuw i64 %14, 3
%22 = add nuw i64 %15, 4
%23 = trunc i64 %22 to i32
%24 = icmp sgt i32 %3, %23
br i1 %24, label %13, label %12
}