#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_b64url();
int /*<<< orphan*/ BIO_f_base64();
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*/ *, char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char const *, int);
int base64contraction(int);
int base64dec(char *pt, int len, const char *b64) {
  BIO *bio_64url = BIO_new(BIO_f_b64url());
  BIO *bio_64 = BIO_new(BIO_f_base64());
  BIO *bio_mem = BIO_new(BIO_s_mem());
  BIO_push(bio_64url, bio_mem);
  BIO_push(bio_64, bio_64url);
  BIO_set_flags(bio_64, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio_mem, b64, len);
  char pad[3] = "==";
  BIO_write(bio_mem, pad, 4 * (len % 4 != 0) - (len % 4));
  int lenOut = base64contraction(len);
  int ret = BIO_read(bio_64, pt, lenOut);
  BIO_free_all(bio_64);
  return ret;
}


x86 assembly (clang, -O0):
<base64dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <BIO_f_b64url@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10b0 <BIO_write@plt>
mov    0xdd4(%rip),%ax
mov    %ax,-0x33(%rbp)
mov    0xdcc(%rip),%al
mov    %al,-0x31(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x33(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
setne  %al
and    $0x1,%al
movzbl %al,%eax
shl    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x40(%rbp),%edx
sub    %eax,%edx
call   10b0 <BIO_write@plt>
mov    -0xc(%rbp),%edi
call   1080 <base64contraction@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64dec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,%r14
xor    %eax,%eax
call   10a0 <BIO_f_b64url@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <BIO_push@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1060 <BIO_set_flags@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <BIO_write@plt>
movb   $0x0,0x6(%rsp)
movw   $0x3d3d,0x4(%rsp)
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
xor    %edx,%edx
mov    %ebx,%ecx
sub    %eax,%ecx
setne  %dl
shl    $0x2,%edx
sub    %ecx,%edx
lea    0x4(%rsp),%rsi
mov    %r13,%rdi
call   10b0 <BIO_write@plt>
mov    %ebx,%edi
call   1080 <base64contraction@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <BIO_read@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1090 <BIO_free_all@plt>
mov    %ebx,%eax
add    $0x8,%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
@__const.base64dec.pad = [3 x i8] c"==\00"
define i32 @base64dec(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [3 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%13 = call i32 (...) @BIO_f_b64url()
%14 = call i32* @BIO_new(i32 %13)
store i32* %14, i32** %7
%15 = call i32 (...) @BIO_f_base64()
%16 = call i32* @BIO_new(i32 %15)
store i32* %16, i32** %8
%17 = call i32 (...) @BIO_s_mem()
%18 = call i32* @BIO_new(i32 %17)
store i32* %18, i32** %9
%19 = load i32*, i32** %7
%20 = load i32*, i32** %9
%21 = call i32 @BIO_push(i32* %19, i32* %20)
%22 = load i32*, i32** %8
%23 = load i32*, i32** %7
%24 = call i32 @BIO_push(i32* %22, i32* %23)
%25 = load i32*, i32** %8
%26 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%27 = call i32 @BIO_set_flags(i32* %25, i32 %26)
%28 = load i32*, i32** %9
%29 = load i8*, i8** %6
%30 = load i32, i32* %5
%31 = call i32 @BIO_write(i32* %28, i8* %29, i32 %30)
%32 = bitcast [3 x i8]* %10 to i8*
%33 = load i32*, i32** %9
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%35 = load i32, i32* %5
%36 = srem i32 %35, 4
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i32
%39 = mul nsw i32 4, %38
%40 = load i32, i32* %5
%41 = srem i32 %40, 4
%42 = sub nsw i32 %39, %41
%43 = call i32 @BIO_write(i32* %33, i8* %34, i32 %42)
%44 = load i32, i32* %5
%45 = call i32 @base64contraction(i32 %44)
store i32 %45, i32* %11
%46 = load i32*, i32** %8
%47 = load i8*, i8** %4
%48 = load i32, i32* %11
%49 = call i32 @BIO_read(i32* %46, i8* %47, i32 %48)
store i32 %49, i32* %12
%50 = load i32*, i32** %8
%51 = call i32 @BIO_free_all(i32* %50)
%52 = load i32, i32* %12
ret i32 %52
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@__const.base64dec.pad = [3 x i8] c"==\00"
define i32 @base64dec(i8* %0, i32 %1, i8* %2) {
%4 = alloca [3 x i8]
%5 = tail call i32 (...) @BIO_f_b64url()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32 (...) @BIO_f_base64()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = tail call i32 (...) @BIO_s_mem()
%10 = tail call i32* @BIO_new(i32 %9)
%11 = tail call i32 @BIO_push(i32* %6, i32* %10)
%12 = tail call i32 @BIO_push(i32* %8, i32* %6)
%13 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%14 = tail call i32 @BIO_set_flags(i32* %8, i32 %13)
%15 = tail call i32 @BIO_write(i32* %10, i8* %2, i32 %1)
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%17 = srem i32 %1, 4
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 0, i32 4
%20 = sub nsw i32 %19, %17
%21 = call i32 @BIO_write(i32* %10, i8* %16, i32 %20)
%22 = call i32 @base64contraction(i32 %1)
%23 = call i32 @BIO_read(i32* %8, i8* %0, i32 %22)
%24 = call i32 @BIO_free_all(i32* %8)
ret i32 %23
}