#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 */
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char const *, size_t);
int ceil(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fmemopen(void *, int, char *);
scalar_t__ malloc(int);
char *wksxmpp_b64encode(const char *data, size_t dlen, char **encdata) {
  BIO *bio, *b64;
  FILE *stream;
  int encSize = 4 * ceil((double)dlen / 3);
  *encdata = (char *)malloc(encSize + 1);
  stream = fmemopen((void *)*encdata, encSize + 1, "w");
  b64 = BIO_new(BIO_f_base64());
  bio = BIO_new_fp(stream, BIO_NOCLOSE);
  bio = BIO_push(b64, bio);
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio, data, dlen);
  BIO_flush(bio);
  BIO_free_all(bio);
  fclose(stream);
  return *encdata;
}


x86 assembly (clang, -O0):
<wksxmpp_b64encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movaps 0xe35(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe34(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdfd(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <ceil@plt>
shl    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x34(%rbp),%esi
add    $0x1,%esi
lea    0xdf5(%rip),%rdx
call   1040 <fmemopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
call   1090 <BIO_set_flags@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10d0 <BIO_write@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <BIO_flush@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <BIO_free_all@plt>
mov    -0x30(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wksxmpp_b64encode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
movq   %rsi,%xmm1
punpckldq 0xe21(%rip),%xmm1
subpd  0xe29(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  0xe25(%rip),%xmm0
call   1050 <ceil@plt>
lea    0x1(,%rax,4),%ebx
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r14)
lea    0xe10(%rip),%rdx
mov    %rax,%rdi
mov    %ebx,%esi
call   1040 <fmemopen@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1080 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1030 <BIO_new_fp@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10d0 <BIO_write@plt>
mov    %rbx,%rdi
call   10e0 <BIO_flush@plt>
mov    %rbx,%rdi
call   10c0 <BIO_free_all@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    (%r14),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @wksxmpp_b64encode(i8* %0, i64 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8** %2, i8*** %6
%11 = load i64, i64* %5
%12 = uitofp i64 %11 to double
%13 = fdiv double %12, 3.000000e+00
%14 = call i32 @ceil(double %13)
%15 = mul nsw i32 4, %14
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = add nsw i32 %16, 1
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = load i8**, i8*** %6
store i8* %19, i8** %20
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
%25 = call i32* @fmemopen(i8* %22, i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %9
%26 = call i32 (...) @BIO_f_base64()
%27 = call i32* @BIO_new(i32 %26)
store i32* %27, i32** %8
%28 = load i32*, i32** %9
%29 = load i32, i32* @BIO_NOCLOSE
%30 = call i32* @BIO_new_fp(i32* %28, i32 %29)
store i32* %30, i32** %7
%31 = load i32*, i32** %8
%32 = load i32*, i32** %7
%33 = call i32* @BIO_push(i32* %31, i32* %32)
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%36 = call i32 @BIO_set_flags(i32* %34, i32 %35)
%37 = load i32*, i32** %7
%38 = load i8*, i8** %4
%39 = load i64, i64* %5
%40 = call i32 @BIO_write(i32* %37, i8* %38, i64 %39)
%41 = load i32*, i32** %7
%42 = call i32 @BIO_flush(i32* %41)
%43 = load i32*, i32** %7
%44 = call i32 @BIO_free_all(i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
%47 = load i8**, i8*** %6
%48 = load i8*, i8** %47
ret i8* %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @wksxmpp_b64encode(i8* %0, i64 %1, i8** nocapture %2) {
%4 = uitofp i64 %1 to double
%5 = fdiv double %4, 3.000000e+00
%6 = tail call i32 @ceil(double %5)
%7 = shl nsw i32 %6, 2
%8 = or i32 %7, 1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %2
%11 = tail call i32* @fmemopen(i8* %10, i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (...) @BIO_f_base64()
%13 = tail call i32* @BIO_new(i32 %12)
%14 = load i32, i32* @BIO_NOCLOSE
%15 = tail call i32* @BIO_new_fp(i32* %11, i32 %14)
%16 = tail call i32* @BIO_push(i32* %13, i32* %15)
%17 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%18 = tail call i32 @BIO_set_flags(i32* %16, i32 %17)
%19 = tail call i32 @BIO_write(i32* %16, i8* %0, i64 %1)
%20 = tail call i32 @BIO_flush(i32* %16)
%21 = tail call i32 @BIO_free_all(i32* %16)
%22 = tail call i32 @fclose(i32* %11)
%23 = load i8*, i8** %2
ret i8* %23
}