#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*/ str2;
typedef int /*<<< orphan*/ str1;

/* Variables and functions */
size_t base64_decode(unsigned char *, char *, int);
size_t base64_encode(char *, unsigned char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *, int, int, int);
scalar_t__ strlen(char *);
void test_base64(void) {
  char str1[((((23) * 4) / 3) + 3) + 1];
  char str2[23];
  memset(str1, 'x', sizeof(str1));
  memset(str2, 'x', sizeof(str2));
  size_t len_enc =
      base64_encode(str1, (unsigned char *)"Hello!12345612356..:-)", 23);
  printf("Encoded: %s strlen=%i len_enc=%i macro_encoded_size=%i\n", str1,
         (int)strlen(str1), (int)len_enc, ((((23) * 4) / 3) + 3));
  size_t len_dec = base64_decode((unsigned char *)str2, str1, 23);
  printf("Decoded: %s strlen=%i len_dec=%i macro_decode_size=%i\n", str2,
         (int)strlen(str2), (int)len_dec, (int)((((len_enc)) * 3) / 4));
}


x86 assembly (clang, -O0):
<test_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x30(%rbp),%rdi
mov    $0x78,%esi
mov    $0x22,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    $0x78,%esi
mov    $0x17,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x17,%edx
call   1060 <base64_encode@plt>
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
mov    -0x58(%rbp),%rax
mov    %eax,%ecx
lea    0xe5c(%rip),%rdi
mov    $0x21,%r8d
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x17,%edx
call   1070 <base64_decode@plt>
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
mov    -0x60(%rbp),%rax
mov    %eax,%ecx
imul   $0x3,-0x58(%rbp),%rax
shr    $0x2,%rax
mov    %eax,%r8d
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_base64>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x78,%esi
mov    $0x22,%edx
call   1050 <memset@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x78,%esi
mov    $0x17,%edx
call   1050 <memset@plt>
lea    0xe74(%rip),%rsi
mov    %r15,%rdi
mov    $0x17,%edx
call   1060 <base64_encode@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0xe6c(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %ebx,%ecx
mov    $0x21,%r8d
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x17,%edx
call   1070 <base64_decode@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rbx,2),%r8
shr    $0x2,%r8
lea    0xe68(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %r15d,%ecx
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Hello!12345612356..:-)\00"
@.str.1 = [56 x i8] c"Encoded: %s strlen=%i len_enc=%i macro_encoded_size=%i\0A\00"
@.str.2 = [55 x i8] c"Decoded: %s strlen=%i len_dec=%i macro_decode_size=%i\0A\00"
define void @test_base64() {
%1 = alloca [34 x i8]
%2 = alloca [23 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i8 signext 120, i32 34)
%7 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i8 signext 120, i32 23)
%9 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%10 = call i64 @base64_encode(i8* %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 23)
store i64 %10, i64* %3
%11 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%12 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
%15 = load i64, i64* %3
%16 = trunc i64 %15 to i32
%17 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %14, i32 %16, i32 33)
%18 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%19 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%20 = call i64 @base64_decode(i8* %18, i8* %19, i32 23)
store i64 %20, i64* %4
%21 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%23 = call i64 @strlen(i8* %22)
%24 = trunc i64 %23 to i32
%25 = load i64, i64* %4
%26 = trunc i64 %25 to i32
%27 = load i64, i64* %3
%28 = mul i64 %27, 3
%29 = udiv i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %24, i32 %26, i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Hello!12345612356..:-)\00"
@.str.1 = [56 x i8] c"Encoded: %s strlen=%i len_enc=%i macro_encoded_size=%i\0A\00"
@.str.2 = [55 x i8] c"Decoded: %s strlen=%i len_dec=%i macro_decode_size=%i\0A\00"
define void @test_base64() {
%1 = alloca [34 x i8]
%2 = alloca [23 x i8]
%3 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %3, i8 signext 120, i32 34)
%6 = call i32 @memset(i8* %4, i8 signext 120, i32 23)
%7 = call i64 @base64_encode(i8* %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 23)
%8 = call i64 @strlen(i8* %3)
%9 = trunc i64 %8 to i32
%10 = trunc i64 %7 to i32
%11 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %9, i32 %10, i32 33)
%12 = call i64 @base64_decode(i8* %4, i8* %3, i32 23)
%13 = call i64 @strlen(i8* %4)
%14 = trunc i64 %13 to i32
%15 = trunc i64 %12 to i32
%16 = mul i64 %7, 3
%17 = lshr i64 %16, 2
%18 = trunc i64 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %14, i32 %15, i32 %18)
ret void
}