#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 BASE64_LENGTH(size_t);
int /*<<< orphan*/ base64_encode(char const *, size_t, char *, size_t);
char *malloc(size_t);
size_t base64_encode_alloc(const char *in, size_t inlen, char **out) {
  size_t outlen = 1 + BASE64_LENGTH(inlen);
  if (inlen > outlen) {
    *out = NULL;
    return 0;
  }
  *out = malloc(outlen);
  if (!*out)
    return outlen;
  base64_encode(in, inlen, *out, outlen);
  return outlen - 1;
}


x86 assembly (clang, -O0):
<base64_encode_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <BASE64_LENGTH@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    117c <base64_encode_alloc+0x4c>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ce <base64_encode_alloc+0x9e>
mov    -0x28(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11aa <base64_encode_alloc+0x7a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <base64_encode_alloc+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <base64_encode@plt>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_encode_alloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <BASE64_LENGTH@plt>
add    $0x1,%eax
movslq %eax,%rbx
cmp    %r14,%rbx
jae    1160 <base64_encode_alloc+0x30>
movq   $0x0,(%r12)
xor    %ebx,%ebx
jmp    1186 <base64_encode_alloc+0x56>
mov    %rbx,%rdi
call   1030 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1186 <base64_encode_alloc+0x56>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1040 <base64_encode@plt>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @base64_encode_alloc(i8* %0, i64 %1, i8** %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
%9 = load i64, i64* %6
%10 = call i32 @BASE64_LENGTH(i64 %9)
%11 = add nsw i32 1, %10
%12 = sext i32 %11 to i64
store i64 %12, i64* %8
%13 = load i64, i64* %6
%14 = load i64, i64* %8
%15 = icmp ugt i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i8**, i8*** %7
store i8* null, i8** %17
store i64 0, i64* %4
br label %36
18: ; preds = %3
%19 = load i64, i64* %8
%20 = call i8* @malloc(i64 %19)
%21 = load i8**, i8*** %7
store i8* %20, i8** %21
%22 = load i8**, i8*** %7
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = load i64, i64* %8
store i64 %26, i64* %4
br label %36
27: ; preds = %18
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = load i8**, i8*** %7
%31 = load i8*, i8** %30
%32 = load i64, i64* %8
%33 = call i32 @base64_encode(i8* %28, i64 %29, i8* %31, i64 %32)
%34 = load i64, i64* %8
%35 = sub i64 %34, 1
store i64 %35, i64* %4
br label %36
36: ; preds = %27, %25, %16
%37 = load i64, i64* %4
ret i64 %37
}

LLVM IR (-O2):
define i64 @base64_encode_alloc(i8* %0, i64 %1, i8** nocapture writeonly %2) {
%4 = tail call i32 @BASE64_LENGTH(i64 %1)
%5 = add nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, %1
br i1 %7, label %8, label %9
8: ; preds = %3
store i8* null, i8** %2
br label %15
9: ; preds = %3
%10 = tail call i8* @malloc(i64 %6)
store i8* %10, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @base64_encode(i8* %0, i64 %1, i8* %10, i64 %6)
%14 = add nsw i64 %6, -1
br label %15
15: ; preds = %9, %12, %8
%16 = phi i64 [ 0, %8 ], [ %14, %12 ], [ %6, %9 ]
ret i64 %16
}