#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char const,
                            unsigned char const, unsigned char const,
                            unsigned char const, unsigned char const,
                            unsigned char const);
char *mac_ntoa(const unsigned char *mac) {
  static char buf[17 + 1];
  int buf_n = sizeof(buf);
  memset(buf, 0, buf_n);
  snprintf(buf, buf_n, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2],
           mac[3], mac[4], mac[5]);
  buf[buf_n - 1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<mac_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x12,-0xc(%rbp)
mov    -0xc(%rbp),%edx
lea    0x2f03(%rip),%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x8(%rbp),%rax
mov    0x3(%rax),%r11b
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x8(%rbp),%rax
lea    0x2ec8(%rip),%rdi
lea    0xe81(%rip),%rdx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r11b,%r11d
mov    %r11d,(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x8(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x10(%rsp)
call   1030 <snprintf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e88(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e7d(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mac_ntoa>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2f12(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1040 <memset@plt>
movzbl (%rbx),%ecx
movzbl 0x1(%rbx),%r8d
movzbl 0x2(%rbx),%r9d
movzbl 0x3(%rbx),%r10d
movzbl 0x4(%rbx),%eax
movzbl 0x5(%rbx),%ebx
sub    $0x8,%rsp
lea    0xe9e(%rip),%rdx
mov    %r14,%rdi
mov    $0x12,%esi
push   %rbx
push   %rax
push   %r10
call   1030 <snprintf@plt>
add    $0x20,%rsp
movb   $0x0,0x2ed3(%rip)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@mac_ntoa.buf = internal global [18 x i8] zeroinitializer
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @mac_ntoa(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 18, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @memset(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0), i32 0, i32 %4)
%6 = load i32, i32* %3
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 3
%18 = load i8, i8* %17
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 4
%21 = load i8, i8* %20
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 5
%24 = load i8, i8* %23
%25 = call i32 @snprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 zeroext %12, i8 zeroext %15, i8 zeroext %18, i8 zeroext %21, i8 zeroext %24)
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 %28
store i8 0, i8* %29
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@mac_ntoa.buf = internal global [18 x i8] zeroinitializer
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @mac_ntoa(i8* nocapture %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0), i32 0, i32 18)
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = getelementptr inbounds i8, i8* %0, i64 3
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 4
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 5
%13 = load i8, i8* %12
%14 = tail call i32 @snprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8 zeroext %3, i8 zeroext %5, i8 zeroext %7, i8 zeroext %9, i8 zeroext %11, i8 zeroext %13)
store i8 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 17)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @mac_ntoa.buf, i64 0, i64 0)
}