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

/* Variables and functions */
int /*<<< orphan*/ base64_encode(char *, char *, int);
int /*<<< orphan*/ kfree(char *);
char *kmalloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *get_basic_auth_str(char *user, char *passwd, char *auth_header) {
  char *p1, *p2, *ret;
  int len = strlen(user) + strlen(passwd) + 1;
  int b64len = 4 * ((len + 2) / 3);
  p1 = kmalloc(len + 1);
  sprintf(p1, "%s:%s", user, passwd);
  p2 = kmalloc(b64len + 1);
  base64_encode(p1, p2, len);
  ret = kmalloc(strlen(auth_header) + b64len + 11);
  sprintf(ret, "%s: Basic %s\r\n", auth_header, p2);
  kfree(p1);
  kfree(p2);
  return ret;
}


x86 assembly (clang, -O0):
<get_basic_auth_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
shl    $0x2,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe44(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%edi
add    $0x1,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <base64_encode@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    -0x38(%rbp),%edi
add    $0xb,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdf9(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <kfree@plt>
mov    -0x28(%rbp),%rdi
call   1040 <kfree@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_basic_auth_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%r12d
add    $0x1,%r12d
lea    (%rax,%rbx,1),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
imul   $0x55555556,%rcx,%r14
mov    %r14,%rcx
shr    $0x3f,%rcx
shr    $0x20,%r14
add    %ecx,%r14d
lea    (%rax,%rbx,1),%edi
add    $0x2,%edi
call   1070 <kmalloc@plt>
mov    %rax,%r13
lea    0xe51(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1060 <sprintf@plt>
lea    0x1(,%r14,4),%edi
call   1070 <kmalloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1050 <base64_encode@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    (%rax,%r14,4),%edi
add    $0xb,%edi
call   1070 <kmalloc@plt>
mov    %rax,%rbx
lea    0xe09(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1060 <sprintf@plt>
mov    %r13,%rdi
call   1040 <kfree@plt>
mov    %r15,%rdi
call   1040 <kfree@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s:%s\00"
@.str.1 = [15 x i8] c"%s: Basic %s\0D\0A\00"
define i8* @get_basic_auth_str(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = add nsw i32 %18, 2
%20 = sdiv i32 %19, 3
%21 = mul nsw i32 4, %20
store i32 %21, i32* %11
%22 = load i32, i32* %10
%23 = add nsw i32 %22, 1
%24 = call i8* @kmalloc(i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27)
%29 = load i32, i32* %11
%30 = add nsw i32 %29, 1
%31 = call i8* @kmalloc(i32 %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = load i32, i32* %10
%35 = call i32 @base64_encode(i8* %32, i8* %33, i32 %34)
%36 = load i8*, i8** %6
%37 = call i32 @strlen(i8* %36)
%38 = load i32, i32* %11
%39 = add nsw i32 %37, %38
%40 = add nsw i32 %39, 11
%41 = call i8* @kmalloc(i32 %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = load i8*, i8** %6
%44 = load i8*, i8** %8
%45 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i8*, i8** %7
%47 = call i32 @kfree(i8* %46)
%48 = load i8*, i8** %8
%49 = call i32 @kfree(i8* %48)
%50 = load i8*, i8** %9
ret i8* %50
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s:%s\00"
@.str.1 = [15 x i8] c"%s: Basic %s\0D\0A\00"
define i8* @get_basic_auth_str(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, %4
%7 = add nsw i32 %6, 1
%8 = add nsw i32 %6, 3
%9 = sdiv i32 %8, 3
%10 = shl nsw i32 %9, 2
%11 = add nsw i32 %6, 2
%12 = tail call i8* @kmalloc(i32 %11)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%14 = or i32 %10, 1
%15 = tail call i8* @kmalloc(i32 %14)
%16 = tail call i32 @base64_encode(i8* %12, i8* %15, i32 %7)
%17 = tail call i32 @strlen(i8* %2)
%18 = add i32 %10, 11
%19 = add i32 %18, %17
%20 = tail call i8* @kmalloc(i32 %19)
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %15)
%22 = tail call i32 @kfree(i8* %12)
%23 = tail call i32 @kfree(i8* %15)
ret i8* %20
}