#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*/ _explicit_bzero(char *, size_t);
int b64_ntop(unsigned char *, size_t, char *, size_t);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int encode_base64(const char *src, size_t src_len, char **dst,
                  size_t *dst_len) {
  int sz;
  *dst = NULL;
  if ((*dst = (char *)malloc(src_len * 2 + 1)) == NULL)
    return 0;
  if ((sz = b64_ntop((unsigned char *)src, src_len, *dst, src_len * 2)) <= 0) {
    _explicit_bzero(*dst, src_len * 2);
    free(*dst);
    *dst = NULL;
    return 0;
  }
  (*dst)[sz] = 0;
  *dst_len = (size_t)sz;
  return 1;
}


x86 assembly (clang, -O0):
<encode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
shl    $0x1,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1191 <encode_base64+0x51>
movl   $0x0,-0x4(%rbp)
jmp    1211 <encode_base64+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
call   1060 <b64_ntop@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jg     11f0 <encode_base64+0xb0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x1,%rsi
call   1040 <_explicit_bzero@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1211 <encode_base64+0xd1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x2c(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r13
movq   $0x0,(%rdx)
lea    (%rsi,%rsi,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
xor    %r15d,%r15d
test   %rax,%rax
je     11bc <encode_base64+0x7c>
mov    %rbp,%r12
add    %rbp,%r12
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
mov    %r12,%rcx
call   1060 <b64_ntop@plt>
mov    (%rbx),%rdi
test   %eax,%eax
jle    11a5 <encode_base64+0x65>
mov    %eax,%eax
movb   $0x0,(%rdi,%rax,1)
mov    %rax,(%r14)
mov    $0x1,%r15d
jmp    11bc <encode_base64+0x7c>
mov    %r12,%rsi
call   1040 <_explicit_bzero@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @encode_base64(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%11 = load i8**, i8*** %8
store i8* null, i8** %11
%12 = load i64, i64* %7
%13 = mul i64 %12, 2
%14 = add i64 %13, 1
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = load i8**, i8*** %8
store i8* %16, i8** %17
%18 = icmp eq i8* %16, null
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 0, i32* %5
br label %48
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i8**, i8*** %8
%24 = load i8*, i8** %23
%25 = load i64, i64* %7
%26 = mul i64 %25, 2
%27 = call i32 @b64_ntop(i8* %21, i64 %22, i8* %24, i64 %26)
store i32 %27, i32* %10
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %20
%30 = load i8**, i8*** %8
%31 = load i8*, i8** %30
%32 = load i64, i64* %7
%33 = mul i64 %32, 2
%34 = call i32 @_explicit_bzero(i8* %31, i64 %33)
%35 = load i8**, i8*** %8
%36 = load i8*, i8** %35
%37 = call i32 @free(i8* %36)
%38 = load i8**, i8*** %8
store i8* null, i8** %38
store i32 0, i32* %5
br label %48
39: ; preds = %20
%40 = load i8**, i8*** %8
%41 = load i8*, i8** %40
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = load i64*, i64** %9
store i64 %46, i64* %47
store i32 1, i32* %5
br label %48
48: ; preds = %39, %29, %19
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @encode_base64(i8* %0, i64 %1, i8** nocapture %2, i64* nocapture writeonly %3) {
store i8* null, i8** %2
%5 = shl i64 %1, 1
%6 = or i64 %5, 1
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = icmp eq i64 %7, 0
br i1 %9, label %21, label %10
10: ; preds = %4
%11 = tail call i32 @b64_ntop(i8* %0, i64 %1, i8* %8, i64 %5)
%12 = icmp slt i32 %11, 1
%13 = load i8*, i8** %2
br i1 %12, label %14, label %18
14: ; preds = %10
%15 = tail call i32 @_explicit_bzero(i8* %13, i64 %5)
%16 = load i8*, i8** %2
%17 = tail call i32 @free(i8* %16)
store i8* null, i8** %2
br label %21
18: ; preds = %10
%19 = zext i32 %11 to i64
%20 = getelementptr inbounds i8, i8* %13, i64 %19
store i8 0, i8* %20
store i64 %19, i64* %3
br label %21
21: ; preds = %4, %18, %14
%22 = phi i32 [ 0, %14 ], [ 1, %18 ], [ 0, %4 ]
ret i32 %22
}