#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 ENOMEM;
char *pppoat_alloc(size_t);
int /*<<< orphan*/ pppoat_base64_enc(void const *, size_t, char *, size_t);
size_t pppoat_base64_enc_len(void const *, size_t);
int pppoat_base64_enc_new(const void *buf, size_t len, char **result) {
  size_t rlen = pppoat_base64_enc_len(buf, len);
  int rc;
  *result = pppoat_alloc(rlen + 1);
  rc = *result == NULL ? -ENOMEM : 0;
  if (rc == 0) {
    pppoat_base64_enc(buf, len, *result, rlen);
    (*result)[rlen] = '\0';
  }
  return rc;
}


x86 assembly (clang, -O0):
<pppoat_base64_enc_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <pppoat_base64_enc_len@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <pppoat_alloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118d <pppoat_base64_enc_new+0x5d>
xor    %eax,%eax
mov    0x2e5d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <pppoat_base64_enc_new+0x67>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <pppoat_base64_enc_new+0x67>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11ce <pppoat_base64_enc_new+0x9e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <pppoat_base64_enc@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pppoat_base64_enc_new>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <pppoat_base64_enc_len@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1040 <pppoat_alloc@plt>
mov    %rax,(%r14)
mov    0x2e84(%rip),%rcx
xor    %edx,%edx
xor    %ebp,%ebp
sub    (%rcx),%ebp
test   %rax,%rax
cmovne %edx,%ebp
test   %ebp,%ebp
jne    1184 <pppoat_base64_enc_new+0x54>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <pppoat_base64_enc@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
define i32 @pppoat_base64_enc_new(i8* %0, i64 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8** %2, i8*** %6
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = call i64 @pppoat_base64_enc_len(i8* %9, i64 %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = add i64 %12, 1
%14 = call i8* @pppoat_alloc(i64 %13)
%15 = load i8**, i8*** %6
store i8* %14, i8** %15
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* @ENOMEM
%21 = sub nsw i32 0, %20
br label %23
22: ; preds = %3
br label %23
23: ; preds = %22, %19
%24 = phi i32 [ %21, %19 ], [ 0, %22 ]
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i64, i64* %5
%30 = load i8**, i8*** %6
%31 = load i8*, i8** %30
%32 = load i64, i64* %7
%33 = call i32 @pppoat_base64_enc(i8* %28, i64 %29, i8* %31, i64 %32)
%34 = load i8**, i8*** %6
%35 = load i8*, i8** %34
%36 = load i64, i64* %7
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %27, %23
%39 = load i32, i32* %8
ret i32 %39
}

LLVM IR (-O2):
@ENOMEM = global i32 0
define i32 @pppoat_base64_enc_new(i8* %0, i64 %1, i8** nocapture %2) {
%4 = tail call i64 @pppoat_base64_enc_len(i8* %0, i64 %1)
%5 = add i64 %4, 1
%6 = tail call i8* @pppoat_alloc(i64 %5)
store i8* %6, i8** %2
%7 = icmp eq i8* %6, null
%8 = load i32, i32* @ENOMEM
%9 = sub nsw i32 0, %8
%10 = select i1 %7, i32 %9, i32 0
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = tail call i32 @pppoat_base64_enc(i8* %0, i64 %1, i8* %6, i64 %4)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 %4
store i8 0, i8* %15
br label %16
16: ; preds = %12, %3
ret i32 %10
}