#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*/ free(unsigned char *);
unsigned char *malloc(int);
int raw_base64_decode(unsigned char const *, unsigned char *, int);
unsigned char *xar_from_base64(const unsigned char *input, int len) {
  int err;
  unsigned char *output;
  output = malloc(3 * (len / 4 + 1));
  if (!output)
    return NULL;
  err = raw_base64_decode(input, output, len);
  if (err) {
    free(output);
    return NULL;
  }
  return output;
}


x86 assembly (clang, -O0):
<xar_from_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   $0x3,%eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <xar_from_base64+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11ac <xar_from_base64+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <raw_base64_decode@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a4 <xar_from_base64+0x74>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ac <xar_from_base64+0x7c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xar_from_base64>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r15
lea    0x3(%rbx),%eax
test   %esi,%esi
cmovns %esi,%eax
sar    $0x2,%eax
lea    (%rax,%rax,2),%edi
add    $0x3,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1171 <xar_from_base64+0x41>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <raw_base64_decode@plt>
test   %eax,%eax
je     1174 <xar_from_base64+0x44>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @xar_from_base64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = sdiv i32 %8, 4
%10 = add nsw i32 %9, 1
%11 = mul nsw i32 3, %10
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i8* null, i8** %3
br label %28
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %7
%19 = load i32, i32* %5
%20 = call i32 @raw_base64_decode(i8* %17, i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i8*, i8** %7
%25 = call i32 @free(i8* %24)
store i8* null, i8** %3
br label %28
26: ; preds = %16
%27 = load i8*, i8** %7
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %23, %15
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @xar_from_base64(i8* %0, i32 %1) {
%3 = sdiv i32 %1, 4
%4 = mul nsw i32 %3, 3
%5 = add nsw i32 %4, 3
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @raw_base64_decode(i8* %0, i8* %6, i32 %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @free(i8* %6)
br label %13
13: ; preds = %8, %2, %11
%14 = phi i8* [ null, %11 ], [ null, %2 ], [ %6, %8 ]
ret i8* %14
}