#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(void *);
void *malloc(size_t);
size_t ybase64_encode(void const *, size_t const, void *, size_t);
void *ybase64_encode_alloc(const void *from, const size_t from_len,
                           size_t *to_len) {
  void *to = NULL;
  if (from && from_len > 0 && to_len) {
    size_t size = ybase64_encode(from, from_len, NULL, 0);
    to = malloc(size);
    if (to) {
      size_t sz = ybase64_encode(from, from_len, to, size);
      if (sz == size) {
        *to_len = size;
      } else {
        free(to);
        to = NULL;
      }
    }
  }
  return to;
}


x86 assembly (clang, -O0):
<ybase64_encode_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ef <ybase64_encode_alloc+0xbf>
cmpq   $0x0,-0x10(%rbp)
jbe    11ef <ybase64_encode_alloc+0xbf>
cmpq   $0x0,-0x18(%rbp)
je     11ef <ybase64_encode_alloc+0xbf>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <ybase64_encode@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ea <ybase64_encode_alloc+0xba>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <ybase64_encode@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11d4 <ybase64_encode_alloc+0xa4>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11e5 <ybase64_encode_alloc+0xb5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    11ea <ybase64_encode_alloc+0xba>
jmp    11ef <ybase64_encode_alloc+0xbf>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ybase64_encode_alloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     11a1 <ybase64_encode_alloc+0x71>
mov    %rsi,%r12
test   %rsi,%rsi
je     11a1 <ybase64_encode_alloc+0x71>
mov    %rdx,%r14
test   %rdx,%rdx
je     11a1 <ybase64_encode_alloc+0x71>
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ybase64_encode@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11a1 <ybase64_encode_alloc+0x71>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r13,%rcx
call   1050 <ybase64_encode@plt>
cmp    %r13,%rax
jne    1196 <ybase64_encode_alloc+0x66>
mov    %r13,(%r14)
mov    %rbp,%r15
jmp    11a1 <ybase64_encode_alloc+0x71>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ybase64_encode_alloc(i8* %0, i64 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64* %2, i64** %6
store i8* null, i8** %7
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %43
12: ; preds = %3
%13 = load i64, i64* %5
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %12
%16 = load i64*, i64** %6
%17 = icmp ne i64* %16, null
br i1 %17, label %18, label %43
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = call i64 @ybase64_encode(i8* %19, i64 %20, i8* null, i64 0)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %42
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = load i8*, i8** %7
%30 = load i64, i64* %8
%31 = call i64 @ybase64_encode(i8* %27, i64 %28, i8* %29, i64 %30)
store i64 %31, i64* %9
%32 = load i64, i64* %9
%33 = load i64, i64* %8
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = load i64, i64* %8
%37 = load i64*, i64** %6
store i64 %36, i64* %37
br label %41
38: ; preds = %26
%39 = load i8*, i8** %7
%40 = call i32 @free(i8* %39)
store i8* null, i8** %7
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41, %18
br label %43
43: ; preds = %42, %15, %12, %3
%44 = load i8*, i8** %7
ret i8* %44
}

LLVM IR (-O2):
define i8* @ybase64_encode_alloc(i8* %0, i64 %1, i64* writeonly %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
%7 = icmp ne i64* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %3
%10 = tail call i64 @ybase64_encode(i8* %0, i64 %1, i8* null, i64 0)
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = tail call i64 @ybase64_encode(i8* %0, i64 %1, i8* %11, i64 %10)
%15 = icmp eq i64 %14, %10
br i1 %15, label %16, label %17
16: ; preds = %13
store i64 %10, i64* %2
br label %19
17: ; preds = %13
%18 = tail call i32 @free(i8* %11)
br label %19
19: ; preds = %9, %17, %16, %3
%20 = phi i8* [ null, %3 ], [ null, %9 ], [ %11, %16 ], [ null, %17 ]
ret i8* %20
}