#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printhex(char *, unsigned char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int MakeAuthString(char *auth_name, char *data, int len, char **auth_ret) {
  char *auth, *ptr;
  int name_len;
  name_len = strlen(auth_name);
  auth = (char *)malloc(name_len + 1 + 2 * len + 1);
  if (auth == NULL)
    return 1;
  strcpy(auth, auth_name);
  ptr = auth + name_len;
  *ptr++ = ':';
  printhex(ptr, (unsigned char *)data, len);
  *auth_ret = auth;
  return 0;
}


x86 assembly (clang, -O0):
<MakeAuthString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
add    $0x1,%edi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
add    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1194 <MakeAuthString+0x54>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <MakeAuthString+0xa4>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x3a,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <printhex@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeAuthString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x2(%rbp,%r12,2),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     119c <MakeAuthString+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
movb   $0x3a,(%rbx,%rax,1)
mov    %r15,%rsi
mov    %r12d,%edx
call   1060 <printhex@plt>
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    11a1 <MakeAuthString+0x61>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @MakeAuthString(i8* %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = load i32, i32* %12
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %8
%18 = mul nsw i32 2, %17
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %10
%23 = load i8*, i8** %10
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 1, i32* %5
br label %42
26: ; preds = %4
%27 = load i8*, i8** %10
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %10
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %11
store i8 58, i8* %34
%36 = load i8*, i8** %11
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = call i32 @printhex(i8* %36, i8* %37, i32 %38)
%40 = load i8*, i8** %10
%41 = load i8**, i8*** %9
store i8* %40, i8** %41
store i32 0, i32* %5
br label %42
42: ; preds = %26, %25
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @MakeAuthString(i8* %0, i8* %1, i32 %2, i8** nocapture writeonly %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = shl nsw i32 %2, 1
%7 = add i32 %6, 2
%8 = add i32 %7, %5
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = tail call i32 @strcpy(i8* %10, i8* %0)
%14 = sext i32 %5 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 58, i8* %15
%17 = tail call i32 @printhex(i8* %16, i8* %1, i32 %2)
store i8* %10, i8** %3
br label %18
18: ; preds = %4, %12
%19 = phi i32 [ 0, %12 ], [ 1, %4 ]
ret i32 %19
}