#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*/ sprintf(char *, char *, unsigned char);
void hwaddr_str(char *str, char *hwaddr, size_t len) {
  int i;
  for (i = 0; i < len; i++) {
    sprintf(str, "%02x:", (unsigned char)hwaddr[i]);
    str += 3;
  }
  if (len)
    str--;
  *str = '\0';
}


x86 assembly (clang, -O0):
<hwaddr_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    116f <hwaddr_str+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xeb4(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <hwaddr_str+0x1b>
cmpq   $0x0,-0x18(%rbp)
je     1186 <hwaddr_str+0x76>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwaddr_str>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r13
test   %rdx,%rdx
je     114d <hwaddr_str+0x3d>
mov    %rsi,%r15
xor    %ebx,%ebx
lea    0xed0(%rip),%r12
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
add    $0x3,%r13
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <hwaddr_str+0x20>
cmp    $0x1,%r14
adc    $0xffffffffffffffff,%r13
movb   $0x0,0x0(%r13)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02x:\00"
define void @hwaddr_str(i8* nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %12, %5 ], [ 0, %3 ]
%7 = phi i8* [ %11, %5 ], [ %0, %3 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %6
%9 = load i8, i8* %8
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = getelementptr inbounds i8, i8* %7, i64 3
%12 = add nuw i64 %6, 1
%13 = icmp eq i64 %12, %2
br i1 %13, label %14, label %5
14: ; preds = %5, %3
%15 = phi i8* [ %0, %3 ], [ %11, %5 ]
%16 = icmp ne i64 %2, 0
%17 = sext i1 %16 to i64
%18 = getelementptr i8, i8* %15, i64 %17
store i8 0, i8* %18
ret void
}