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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int);
char *zrpc_util_mac2str(char *mac) {
  char *ptr;
  if (!mac)
    return NULL;
  ptr = (char *)malloc((6 * 2 + 6 - 1 + 1) * sizeof(char));
  snprintf(ptr, (6 * 2 + 6 - 1 + 1), "%02x:%02x:%02x:%02x:%02x:%02x",
           (uint8_t)mac[0], (uint8_t)mac[1], (uint8_t)mac[2], (uint8_t)mac[3],
           (uint8_t)mac[4], (uint8_t)mac[5]);
  return ptr;
}


x86 assembly (clang, -O0):
<zrpc_util_mac2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <zrpc_util_mac2str+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11af <zrpc_util_mac2str+0x8f>
mov    $0x12,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%r8d
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%r9d
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%r11d
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%r10d
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
mov    $0x12,%esi
lea    0xe6b(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zrpc_util_mac2str>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1175 <zrpc_util_mac2str+0x55>
mov    %rdi,%rbx
mov    $0x12,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movsbl (%rbx),%ecx
movsbl 0x1(%rbx),%r8d
movsbl 0x2(%rbx),%r9d
movsbl 0x3(%rbx),%r10d
movsbl 0x4(%rbx),%eax
movsbl 0x5(%rbx),%ebx
sub    $0x8,%rsp
lea    0xea2(%rip),%rdx
mov    %r14,%rdi
mov    $0x12,%esi
push   %rbx
push   %rax
push   %r10
call   1030 <snprintf@plt>
add    $0x20,%rsp
jmp    1178 <zrpc_util_mac2str+0x58>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @zrpc_util_mac2str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %38
8: ; preds = %1
%9 = call i64 @malloc(i32 18)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 5
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 @snprintf(i8* %11, i32 18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %19, i32 %23, i32 %27, i32 %31, i32 %35)
%37 = load i8*, i8** %4
store i8* %37, i8** %2
br label %38
38: ; preds = %8, %7
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @zrpc_util_mac2str(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = tail call i64 @malloc(i32 18)
%5 = inttoptr i64 %4 to i8*
%6 = load i8, i8* %0
%7 = sext i8 %6 to i32
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = getelementptr inbounds i8, i8* %0, i64 3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = getelementptr inbounds i8, i8* %0, i64 5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = tail call i32 @snprintf(i8* %5, i32 18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %13, i32 %16, i32 %19, i32 %22)
br label %24
24: ; preds = %1, %3
%25 = phi i8* [ %5, %3 ], [ null, %1 ]
ret i8* %25
}