#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*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, void *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int BIO_write(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ free(void *);
void *malloc(size_t);
int saslc__crypto_decode_base64(const char *in, size_t inlen, void **out,
                                size_t *outlen) {
  BIO *bio;
  BIO *b64;
  void *r;
  size_t declen;
  int n;
  declen = ((inlen + 3) / 4) * 3;
  r = malloc(declen + 1);
  if (r == NULL)
    return -1;
  if ((bio = BIO_new(BIO_s_mem())) == NULL)
    goto err;
  if ((b64 = BIO_new(BIO_f_base64())) == NULL) {
    BIO_free(bio);
    goto err;
  }
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  b64 = BIO_push(b64, bio);
  if (BIO_write(bio, in, (int)inlen) != (int)inlen) {
    BIO_free_all(b64);
    goto err;
  }
  n = BIO_read(b64, r, (int)declen);
  BIO_free_all(b64);
  if (n < 0)
    goto err;
  ((char *)r)[n] = '\0';
  if (out)
    *out = r;
  if (outlen)
    *outlen = n;
  return 0;
err:
  free(r);
  return -1;
}


x86 assembly (clang, -O0):
<saslc__crypto_decode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3,%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1204 <saslc__crypto_decode_base64+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1321 <saslc__crypto_decode_base64+0x171>
mov    $0x0,%al
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1225 <saslc__crypto_decode_base64+0x75>
jmp    1311 <saslc__crypto_decode_base64+0x161>
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    124f <saslc__crypto_decode_base64+0x9f>
mov    -0x30(%rbp),%rdi
call   10a0 <BIO_free@plt>
jmp    1311 <saslc__crypto_decode_base64+0x161>
mov    -0x38(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   10c0 <BIO_write@plt>
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
je     129f <saslc__crypto_decode_base64+0xef>
mov    -0x38(%rbp),%rdi
call   10b0 <BIO_free_all@plt>
jmp    1311 <saslc__crypto_decode_base64+0x161>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
call   1050 <BIO_read@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   10b0 <BIO_free_all@plt>
cmpl   $0x0,-0x4c(%rbp)
jge    12cd <saslc__crypto_decode_base64+0x11d>
jmp    1311 <saslc__crypto_decode_base64+0x161>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x20(%rbp)
je     12ef <saslc__crypto_decode_base64+0x13f>
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1305 <saslc__crypto_decode_base64+0x155>
movslq -0x4c(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1321 <saslc__crypto_decode_base64+0x171>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saslc__crypto_decode_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x3(%rsi),%r13
shr    $0x2,%r13
lea    0x1(,%r13,2),%rdi
add    %r13,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     12df <saslc__crypto_decode_base64+0x12f>
mov    %rcx,0x8(%rsp)
mov    %rbp,0x20(%rsp)
mov    %rbx,0x18(%rsp)
xor    %eax,%eax
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
test   %rax,%rax
je     12d0 <saslc__crypto_decode_base64+0x120>
mov    %rax,%r14
mov    %r12,0x10(%rsp)
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
test   %rax,%rax
je     12be <saslc__crypto_decode_base64+0x10e>
mov    %rax,%rbx
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <BIO_push@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    0x20(%rsp),%rsi
mov    %r15d,%edx
call   10c0 <BIO_write@plt>
cmp    %r15d,%eax
jne    12c8 <saslc__crypto_decode_base64+0x118>
lea    0x0(,%r13,2),%rdx
add    %r13,%rdx
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1050 <BIO_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10b0 <BIO_free_all@plt>
test   %ebp,%ebp
mov    0x10(%rsp),%rcx
js     12d0 <saslc__crypto_decode_base64+0x120>
mov    %ebp,%esi
mov    0x8(%rsp),%rax
movb   $0x0,(%rax,%rsi,1)
mov    0x18(%rsp),%rdx
test   %rdx,%rdx
je     12b2 <saslc__crypto_decode_base64+0x102>
mov    %rax,(%rdx)
xor    %eax,%eax
test   %rcx,%rcx
je     12df <saslc__crypto_decode_base64+0x12f>
mov    %rsi,(%rcx)
jmp    12df <saslc__crypto_decode_base64+0x12f>
mov    %r14,%rdi
call   10a0 <BIO_free@plt>
jmp    12d0 <saslc__crypto_decode_base64+0x120>
mov    %rbx,%rdi
call   10b0 <BIO_free_all@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @saslc__crypto_decode_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*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%15 = load i64, i64* %7
%16 = add i64 %15, 3
%17 = udiv i64 %16, 4
%18 = mul i64 %17, 3
store i64 %18, i64* %13
%19 = load i64, i64* %13
%20 = add i64 %19, 1
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %12
%22 = load i8*, i8** %12
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
br label %87
25: ; preds = %4
%26 = call i32 (...) @BIO_s_mem()
%27 = call i32* @BIO_new(i32 %26)
store i32* %27, i32** %10
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %25
br label %84
30: ; preds = %25
%31 = call i32 (...) @BIO_f_base64()
%32 = call i32* @BIO_new(i32 %31)
store i32* %32, i32** %11
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32*, i32** %10
%36 = call i32 @BIO_free(i32* %35)
br label %84
37: ; preds = %30
%38 = load i32*, i32** %11
%39 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%40 = call i32 @BIO_set_flags(i32* %38, i32 %39)
%41 = load i32*, i32** %11
%42 = load i32*, i32** %10
%43 = call i32* @BIO_push(i32* %41, i32* %42)
store i32* %43, i32** %11
%44 = load i32*, i32** %10
%45 = load i8*, i8** %6
%46 = load i64, i64* %7
%47 = trunc i64 %46 to i32
%48 = call i32 @BIO_write(i32* %44, i8* %45, i32 %47)
%49 = load i64, i64* %7
%50 = trunc i64 %49 to i32
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %55
52: ; preds = %37
%53 = load i32*, i32** %11
%54 = call i32 @BIO_free_all(i32* %53)
br label %84
55: ; preds = %37
%56 = load i32*, i32** %11
%57 = load i8*, i8** %12
%58 = load i64, i64* %13
%59 = trunc i64 %58 to i32
%60 = call i32 @BIO_read(i32* %56, i8* %57, i32 %59)
store i32 %60, i32* %14
%61 = load i32*, i32** %11
%62 = call i32 @BIO_free_all(i32* %61)
%63 = load i32, i32* %14
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %55
br label %84
66: ; preds = %55
%67 = load i8*, i8** %12
%68 = load i32, i32* %14
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 0, i8* %70
%71 = load i8**, i8*** %8
%72 = icmp ne i8** %71, null
br i1 %72, label %73, label %76
73: ; preds = %66
%74 = load i8*, i8** %12
%75 = load i8**, i8*** %8
store i8* %74, i8** %75
br label %76
76: ; preds = %73, %66
%77 = load i64*, i64** %9
%78 = icmp ne i64* %77, null
br i1 %78, label %79, label %83
79: ; preds = %76
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = load i64*, i64** %9
store i64 %81, i64* %82
br label %83
83: ; preds = %79, %76
store i32 0, i32* %5
br label %87
84: ; preds = %65, %52, %34, %29
%85 = load i8*, i8** %12
%86 = call i32 @free(i8* %85)
store i32 -1, i32* %5
br label %87
87: ; preds = %84, %83, %24
%88 = load i32, i32* %5
ret i32 %88
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @saslc__crypto_decode_base64(i8* %0, i64 %1, i8** writeonly %2, i64* writeonly %3) {
%5 = add i64 %1, 3
%6 = lshr i64 %5, 2
%7 = mul nuw i64 %6, 3
%8 = add nuw i64 %7, 1
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %45, label %11
11: ; preds = %4
%12 = tail call i32 (...) @BIO_s_mem()
%13 = tail call i32* @BIO_new(i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %43, label %15
15: ; preds = %11
%16 = tail call i32 (...) @BIO_f_base64()
%17 = tail call i32* @BIO_new(i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @BIO_free(i32* %13)
br label %43
21: ; preds = %15
%22 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%23 = tail call i32 @BIO_set_flags(i32* %17, i32 %22)
%24 = tail call i32* @BIO_push(i32* %17, i32* %13)
%25 = trunc i64 %1 to i32
%26 = tail call i32 @BIO_write(i32* %13, i8* %0, i32 %25)
%27 = icmp eq i32 %26, %25
br i1 %27, label %30, label %28
28: ; preds = %21
%29 = tail call i32 @BIO_free_all(i32* %24)
br label %43
30: ; preds = %21
%31 = trunc i64 %7 to i32
%32 = tail call i32 @BIO_read(i32* %24, i8* %9, i32 %31)
%33 = tail call i32 @BIO_free_all(i32* %24)
%34 = icmp slt i32 %32, 0
br i1 %34, label %43, label %35
35: ; preds = %30
%36 = zext i32 %32 to i64
%37 = getelementptr inbounds i8, i8* %9, i64 %36
store i8 0, i8* %37
%38 = icmp eq i8** %2, null
br i1 %38, label %40, label %39
39: ; preds = %35
store i8* %9, i8** %2
br label %40
40: ; preds = %39, %35
%41 = icmp eq i64* %3, null
br i1 %41, label %45, label %42
42: ; preds = %40
store i64 %36, i64* %3
br label %45
43: ; preds = %30, %11, %28, %19
%44 = tail call i32 @free(i8* %9)
br label %45
45: ; preds = %40, %42, %4, %43
%46 = phi i32 [ -1, %43 ], [ -1, %4 ], [ 0, %42 ], [ 0, %40 ]
ret i32 %46
}