#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*/ ENOBUFS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char const);
char *hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen, char *buf,
                  size_t buflen) {
  char *p;
  size_t i;
  if (buf == NULL) {
    return NULL;
  }
  if (hwlen * 3 > buflen) {
    errno = ENOBUFS;
    return 0;
  }
  p = buf;
  for (i = 0; i < hwlen; i++) {
    if (i > 0)
      *p++ = ':';
    p += snprintf(p, 3, "%.2x", hwaddr[i]);
  }
  *p++ = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<hwaddr_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1140 <hwaddr_ntoa+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1205 <hwaddr_ntoa+0xf5>
imul   $0x3,-0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    116e <hwaddr_ntoa+0x5e>
mov    0x2ea2(%rip),%rax
mov    (%rax),%ecx
mov    0x2e79(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1205 <hwaddr_ntoa+0xf5>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11eb <hwaddr_ntoa+0xdb>
cmpq   $0x0,-0x38(%rbp)
jbe    11a9 <hwaddr_ntoa+0x99>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x3a,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    $0x3,%esi
lea    0xe3f(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    117e <hwaddr_ntoa+0x6e>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwaddr_ntoa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     113e <hwaddr_ntoa+0x2e>
mov    %rsi,%r13
lea    (%rsi,%rsi,2),%rax
cmp    %rcx,%rax
jbe    1143 <hwaddr_ntoa+0x33>
mov    0x2ec5(%rip),%rax
mov    (%rax),%eax
mov    0x2e9c(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
jmp    11ae <hwaddr_ntoa+0x9e>
mov    %rdx,%r14
mov    %rdx,%rbx
test   %r13,%r13
je     11ab <hwaddr_ntoa+0x9b>
mov    %rdi,%r15
movzbl (%rdi),%ecx
lea    0xea5(%rip),%rdx
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <snprintf@plt>
movslq %eax,%rbx
add    %r14,%rbx
cmp    $0x1,%r13
je     11ab <hwaddr_ntoa+0x9b>
mov    $0x1,%ebp
lea    0xe80(%rip),%r12
lea    0x1(%rbx),%rdi
movb   $0x3a,(%rbx)
movzbl (%r15,%rbp,1),%ecx
mov    $0x3,%esi
mov    %r12,%rdx
call   1030 <snprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <hwaddr_ntoa+0x70>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOBUFS = global i32 0
@errno = global i32 0
@.str = [5 x i8] c"%.2x\00"
define i8* @hwaddr_ntoa(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %4
store i8* null, i8** %5
br label %51
15: ; preds = %4
%16 = load i64, i64* %7
%17 = mul i64 %16, 3
%18 = load i64, i64* %9
%19 = icmp ugt i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* @ENOBUFS
store i32 %21, i32* @errno
store i8* null, i8** %5
br label %51
22: ; preds = %15
%23 = load i8*, i8** %8
store i8* %23, i8** %10
store i64 0, i64* %11
br label %24
24: ; preds = %44, %22
%25 = load i64, i64* %11
%26 = load i64, i64* %7
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %47
28: ; preds = %24
%29 = load i64, i64* %11
%30 = icmp ugt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %10
store i8 58, i8* %32
br label %34
34: ; preds = %31, %28
%35 = load i8*, i8** %10
%36 = load i8*, i8** %6
%37 = load i64, i64* %11
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @snprintf(i8* %35, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %39)
%41 = load i8*, i8** %10
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %10
br label %44
44: ; preds = %34
%45 = load i64, i64* %11
%46 = add i64 %45, 1
store i64 %46, i64* %11
br label %24
47: ; preds = %24
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %10
store i8 0, i8* %48
%50 = load i8*, i8** %8
store i8* %50, i8** %5
br label %51
51: ; preds = %47, %20, %14
%52 = load i8*, i8** %5
ret i8* %52
}

LLVM IR (-O2):
@ENOBUFS = global i32 0
@errno = global i32 0
@.str = [5 x i8] c"%.2x\00"
define i8* @hwaddr_ntoa(i8* nocapture %0, i64 %1, i8* %2, i64 %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %32, label %6
6: ; preds = %4
%7 = mul i64 %1, 3
%8 = icmp ugt i64 %7, %3
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = icmp eq i64 %1, 0
br i1 %10, label %30, label %11
11: ; preds = %9
%12 = load i8, i8* %0
%13 = tail call i32 @snprintf(i8* %2, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = icmp eq i64 %1, 1
br i1 %16, label %30, label %19
17: ; preds = %6
%18 = load i32, i32* @ENOBUFS
store i32 %18, i32* @errno
br label %32
19: ; preds = %11, %19
%20 = phi i64 [ %28, %19 ], [ 1, %11 ]
%21 = phi i8* [ %27, %19 ], [ %15, %11 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 58, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 %20
%24 = load i8, i8* %23
%25 = tail call i32 @snprintf(i8* %22, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = add nuw i64 %20, 1
%29 = icmp eq i64 %28, %1
br i1 %29, label %30, label %19
30: ; preds = %19, %11, %9
%31 = phi i8* [ %2, %9 ], [ %15, %11 ], [ %27, %19 ]
store i8 0, i8* %31
br label %32
32: ; preds = %4, %30, %17
%33 = phi i8* [ null, %17 ], [ %2, %30 ], [ null, %4 ]
ret i8* %33
}