#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*/ sprintf(unsigned char *, char *, unsigned char, char *);
unsigned char *mc_macbytes_into_string(unsigned char *macbytes) {
  unsigned char *string = (unsigned char *)malloc(18);
  int y;
  int i;
  for (i = 0; i < 6; i++) {
    sprintf(&string[i * 3], "%02x%s", macbytes[i], i < 5 ? ":" : "");
  }
  return string;
}


x86 assembly (clang, -O0):
<mc_macbytes_into_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x12,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    1198 <mc_macbytes_into_string+0x78>
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x18(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%esi
lea    0xe9b(%rip),%rcx
lea    0xe93(%rip),%rdx
cmp    $0x5,%esi
cmovl  %rdx,%rcx
lea    0xe7e(%rip),%rsi
movzbl %al,%edx
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1141 <mc_macbytes_into_string+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_macbytes_into_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x12,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movzbl (%r14),%edx
lea    0xebd(%rip),%r15
lea    0xebd(%rip),%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <sprintf@plt>
lea    0x3(%rbx),%rdi
movzbl 0x1(%r14),%edx
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <sprintf@plt>
lea    0x6(%rbx),%rdi
movzbl 0x2(%r14),%edx
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <sprintf@plt>
lea    0x9(%rbx),%rdi
movzbl 0x3(%r14),%edx
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <sprintf@plt>
lea    0xc(%rbx),%rdi
movzbl 0x4(%r14),%edx
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <sprintf@plt>
lea    0xf(%rbx),%rdi
movzbl 0x5(%r14),%edx
lea    0xe50(%rip),%rcx
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%02x%s\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @mc_macbytes_into_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i64 @malloc(i32 18)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
store i32 0, i32* %5
br label %8
8: ; preds = %27, %1
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 6
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = mul nsw i32 %13, 3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 5
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %21, i8* %25)
br label %27
27: ; preds = %11
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %8
30: ; preds = %8
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02x%s\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @mc_macbytes_into_string(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 18)
%3 = inttoptr i64 %2 to i8*
%4 = load i8, i8* %0
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds i8, i8* %3, i64 3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds i8, i8* %3, i64 6
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8, i8* %3, i64 9
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = load i8, i8* %15
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %3, i64 12
%19 = getelementptr inbounds i8, i8* %0, i64 4
%20 = load i8, i8* %19
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds i8, i8* %3, i64 15
%23 = getelementptr inbounds i8, i8* %0, i64 5
%24 = load i8, i8* %23
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %24, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
ret i8* %3
}