#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef int /*<<< orphan*/ SHA256_CTX;
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_mem_ptr(int /*<<< orphan*/ *, TYPE_1__ **);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, unsigned char *,
                                 unsigned int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
char *data_to_sha256_base64_encoded(unsigned char *string, unsigned int size) {
  unsigned char hash[SHA256_DIGEST_LENGTH];
  SHA256_CTX sha256;
  SHA256_Init(&sha256);
  SHA256_Update(&sha256, string, size);
  SHA256_Final(hash, &sha256);
  BIO *bmem, *b64;
  BUF_MEM *bptr;
  b64 = BIO_new(BIO_f_base64());
  bmem = BIO_new(BIO_s_mem());
  b64 = BIO_push(b64, bmem);
  BIO_write(b64, hash, 32);
  BIO_flush(b64);
  BIO_get_mem_ptr(b64, &bptr);
  char *buff = (char *)malloc(bptr->length);
  memcpy(buff, bptr->data, bptr->length - 1);
  buff[bptr->length - 1] = 0;
  BIO_free_all(b64);
  return buff;
}


x86 assembly (clang, -O0):
<data_to_sha256_base64_encoded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1050 <SHA256_Init@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x24(%rbp),%rdi
call   10a0 <SHA256_Update@plt>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1090 <SHA256_Final@plt>
mov    $0x0,%al
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10e0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x50(%rbp),%rsi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x20,%edx
call   10d0 <BIO_write@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <BIO_flush@plt>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10c0 <BIO_get_mem_ptr@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1060 <memcpy@plt>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
call   10b0 <BIO_free_all@plt>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_to_sha256_base64_encoded>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x2c(%rbp),%r12
mov    %r12,%rdi
call   1050 <SHA256_Init@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10a0 <SHA256_Update@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <SHA256_Final@plt>
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   10e0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   10d0 <BIO_write@plt>
mov    %r14,%rdi
call   10f0 <BIO_flush@plt>
lea    -0x28(%rbp),%rsi
mov    %r14,%rdi
call   10c0 <BIO_get_mem_ptr@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
add    $0xffffffff,%edx
mov    %rbx,%rdi
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq (%rax),%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r14,%rdi
call   10b0 <BIO_free_all@plt>
mov    %rbx,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @data_to_sha256_base64_encoded(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.TYPE_3__*
%11 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i8, i64 %13
store i64 %13, i64* %6
%16 = call i32 @SHA256_Init(i32* %7)
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = call i32 @SHA256_Update(i32* %7, i8* %17, i32 %18)
%20 = call i32 @SHA256_Final(i8* %15, i32* %7)
%21 = call i32 (...) @BIO_f_base64()
%22 = call i32* @BIO_new(i32 %21)
store i32* %22, i32** %9
%23 = call i32 (...) @BIO_s_mem()
%24 = call i32* @BIO_new(i32 %23)
store i32* %24, i32** %8
%25 = load i32*, i32** %9
%26 = load i32*, i32** %8
%27 = call i32* @BIO_push(i32* %25, i32* %26)
store i32* %27, i32** %9
%28 = load i32*, i32** %9
%29 = call i32 @BIO_write(i32* %28, i8* %15, i32 32)
%30 = load i32*, i32** %9
%31 = call i32 @BIO_flush(i32* %30)
%32 = load i32*, i32** %9
%33 = call i32 @BIO_get_mem_ptr(i32* %32, %struct.TYPE_3__** %10)
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %11
%39 = load i8*, i8** %11
%40 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = sub nsw i32 %45, 1
%47 = call i32 @memcpy(i8* %39, i32 %42, i32 %46)
%48 = load i8*, i8** %11
%49 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %48, i64 %53
store i8 0, i8* %54
%55 = load i32*, i32** %9
%56 = call i32 @BIO_free_all(i32* %55)
%57 = load i8*, i8** %11
%58 = load i8*, i8** %5
ret i8* %57
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @data_to_sha256_base64_encoded(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_3__*
%5 = load i32, i32* @SHA256_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast i32* %3 to i8*
%9 = call i32 @SHA256_Init(i32* %3)
%10 = call i32 @SHA256_Update(i32* %3, i8* %0, i32 %1)
%11 = call i32 @SHA256_Final(i8* %7, i32* %3)
%12 = bitcast %struct.TYPE_3__** %4 to i8*
%13 = call i32 (...) @BIO_f_base64()
%14 = call i32* @BIO_new(i32 %13)
%15 = call i32 (...) @BIO_s_mem()
%16 = call i32* @BIO_new(i32 %15)
%17 = call i32* @BIO_push(i32* %14, i32* %16)
%18 = call i32 @BIO_write(i32* %17, i8* %7, i32 32)
%19 = call i32 @BIO_flush(i32* %17)
%20 = call i32 @BIO_get_mem_ptr(i32* %17, %struct.TYPE_3__** %4)
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i64 0, i32 0
%30 = load i32, i32* %29
%31 = add nsw i32 %30, -1
%32 = call i32 @memcpy(i8* %25, i32 %28, i32 %31)
%33 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i64 0, i32 0
%35 = load i32, i32* %34
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %25, i64 %37
store i8 0, i8* %38
%39 = call i32 @BIO_free_all(i32* %17)
ret i8* %25
}