#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*/ EINVAL;
int /*<<< orphan*/ errno;
int snprintf(char *, size_t const, char *, unsigned char const,
             unsigned char const, unsigned char const, unsigned char const,
             unsigned char const, unsigned char const);
int ethaddrstr(char *dst, const size_t dsize, const void *src,
               const size_t slen) {
  const unsigned char *addr = src;
  if (slen < 6 || dsize < 17) {
    errno = EINVAL;
    return (-1);
  }
  return (snprintf(dst, dsize, "%02X:%02X:%02X:%02X:%02X:%02X", addr[0],
                   addr[1], addr[2], addr[3], addr[4], addr[5]));
}


x86 assembly (clang, -O0):
<ethaddrstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x6,-0x28(%rbp)
jb     1146 <ethaddrstr+0x36>
cmpq   $0x11,-0x18(%rbp)
jae    1164 <ethaddrstr+0x54>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <ethaddrstr+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x30(%rbp),%rax
mov    0x3(%rax),%r11b
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x30(%rbp),%rax
lea    0xe63(%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    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ethaddrstr>:
push   %rax
cmp    $0x11,%rsi
jb     1153 <ethaddrstr+0x43>
cmp    $0x5,%rcx
jbe    1153 <ethaddrstr+0x43>
movzbl (%rdx),%ecx
movzbl 0x1(%rdx),%r8d
movzbl 0x2(%rdx),%r9d
movzbl 0x3(%rdx),%r10d
movzbl 0x4(%rdx),%r11d
movzbl 0x5(%rdx),%eax
sub    $0x8,%rsp
lea    0xebd(%rip),%rdx
push   %rax
push   %r11
push   %r10
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rcx
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    0x2e7d(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [30 x i8] c"%02X:%02X:%02X:%02X:%02X:%02X\00"
define i32 @ethaddrstr(i8* %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = icmp ult i64 %3, 6
%6 = icmp ult i64 %1, 17
%7 = or i1 %6, %5
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
br label %23
10: ; preds = %4
%11 = load i8, i8* %2
%12 = getelementptr inbounds i8, i8* %2, i64 1
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %2, i64 2
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %2, i64 3
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %2, i64 4
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %2, i64 5
%21 = load i8, i8* %20
%22 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8 zeroext %11, i8 zeroext %13, i8 zeroext %15, i8 zeroext %17, i8 zeroext %19, i8 zeroext %21)
br label %23
23: ; preds = %10, %8
%24 = phi i32 [ -1, %8 ], [ %22, %10 ]
ret i32 %24
}