#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 len1;

/* Variables and functions */
scalar_t__ alloca(int);
int /*<<< orphan*/ base64_encode(char *, int, char *);
char *concat_strings(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int strlen(char const *);
char *basic_authentication_encode(const char *user, const char *passwd) {
  char *t1, *t2;
  int len1 = strlen(user) + 1 + strlen(passwd);
  t1 = (char *)alloca(len1 + 1);
  sprintf(t1, "%s:%s", user, passwd);
  t2 = (char *)alloca((4 * (((len1) + 2) / 3)) + 1);
  base64_encode(t1, len1, t2);
  return concat_strings("Basic ", t2, (char *)0);
}


x86 assembly (clang, -O0):
<basic_authentication_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1040 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe5c(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
shl    $0x2,%edi
add    $0x1,%edi
call   1040 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <base64_encode@plt>
mov    -0x20(%rbp),%rsi
lea    0xe23(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <concat_strings@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_authentication_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    (%rbx,%rbp,1),%r14d
add    $0x1,%r14d
lea    (%rbx,%rbp,1),%edi
add    $0x2,%edi
call   1040 <alloca@plt>
mov    %rax,%r13
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1070 <sprintf@plt>
lea    (%rbx,%rbp,1),%eax
add    $0x3,%eax
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    0x1(,%rax,4),%edi
call   1040 <alloca@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1060 <base64_encode@plt>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <concat_strings@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s:%s\00"
@.str.1 = [7 x i8] c"Basic \00"
define i8* @basic_authentication_encode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = call i64 @alloca(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 2
%24 = sdiv i32 %23, 3
%25 = mul nsw i32 4, %24
%26 = add nsw i32 %25, 1
%27 = call i64 @alloca(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %6
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = load i8*, i8** %6
%32 = call i32 @base64_encode(i8* %29, i32 %30, i8* %31)
%33 = load i8*, i8** %6
%34 = call i8* @concat_strings(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* null)
ret i8* %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s:%s\00"
@.str.1 = [7 x i8] c"Basic \00"
define i8* @basic_authentication_encode(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %4, %5
%7 = add nsw i32 %6, 1
%8 = tail call i64 @alloca(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = add nsw i32 %6, 2
%12 = sdiv i32 %11, 3
%13 = shl nsw i32 %12, 2
%14 = or i32 %13, 1
%15 = tail call i64 @alloca(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @base64_encode(i8* %9, i32 %6, i8* %16)
%18 = tail call i8* @concat_strings(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* null)
ret i8* %18
}