#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_encode(char *, int, unsigned char *, int);
int base64_encsize(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
char *base64_enc_malloc(unsigned char *src, int slen) {
  int size;
  char *buffer;
  size = base64_encsize(slen) + 1;
  buffer = (char *)malloc(size);
  if (buffer == NULL) {
    return NULL;
  }
  size = base64_encode(buffer, size, src, slen);
  if (size == -1) {
    free(buffer);
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<base64_enc_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <base64_encsize@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1181 <base64_enc_malloc+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11bf <base64_enc_malloc+0x7f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <base64_encode@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11b7 <base64_enc_malloc+0x77>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11bf <base64_enc_malloc+0x7f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_enc_malloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%edi
call   1040 <base64_encsize@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1185 <base64_enc_malloc+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <base64_encode@plt>
cmp    $0xffffffff,%eax
jne    1187 <base64_enc_malloc+0x47>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @base64_enc_malloc(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 = call i32 @base64_encsize(i32 %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %30
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = load i32, i32* %6
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = call i32 @base64_encode(i8* %18, i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
store i8* null, i8** %3
br label %30
28: ; preds = %17
%29 = load i8*, i8** %7
store i8* %29, i8** %3
br label %30
30: ; preds = %28, %25, %16
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @base64_enc_malloc(i8* %0, i32 %1) {
%3 = tail call i32 @base64_encsize(i32 %1)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @base64_encode(i8* %6, i32 %4, i8* %0, i32 %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
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
}