char *print_hw_addr(htype, hlen, data)
int htype;
int hlen;
unsigned char *data;
{
  static char habuf[49];
  char *s;
  int i;
  if (hlen <= 0)
    habuf[0] = 0;
  else {
    s = habuf;
    for (i = 0; i < hlen; i++) {
      sprintf(s, "%02x", data[i]);
      s += strlen(s);
      *s++ = ':';
    }
    *--s = 0;
  }
  return habuf;
}


x86 assembly (clang, -O0):
<print_hw_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1148 <print_hw_addr+0x28>
movb   $0x0,0x2efd(%rip)
jmp    11c8 <print_hw_addr+0xa8>
lea    0x2ef1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b5 <print_hw_addr+0x95>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x3a,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <print_hw_addr+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,-0x1(%rax)
lea    0x2e71(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hw_addr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    118a <print_hw_addr+0x6a>
mov    %rdx,%r15
mov    %esi,%r12d
lea    0x2f06(%rip),%rcx
lea    0xebf(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%r13
movzbl (%r15,%rbx,1),%edx
mov    %rcx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    (%rax,%r13,1),%rcx
add    $0x1,%rcx
movb   $0x3a,0x0(%r13,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <print_hw_addr+0x30>
movb   $0x0,-0x1(%rcx)
jmp    1191 <print_hw_addr+0x71>
movb   $0x0,0x2eaf(%rip)
lea    0x2ea8(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@print_hw_addr.habuf = internal global [49 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @print_hw_addr(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i8 0, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0)
br label %38
12: ; preds = %3
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0), i8** %7
store i32 0, i32* %8
br label %13
13: ; preds = %32, %12
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = load i8*, i8** %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %7
%27 = call i64 @strlen(i8* %26)
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 %27
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
store i8 58, i8* %30
br label %32
32: ; preds = %17
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %13
35: ; preds = %13
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %7
store i8 0, i8* %37
br label %38
38: ; preds = %35, %11
ret i8* getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0)
}

LLVM IR (-O2):
@print_hw_addr.habuf = internal global [49 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @print_hw_addr(i32 %0, i32 %1, i8* nocapture %2) {
%4 = icmp slt i32 %1, 1
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %3
store i8 0, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0)
br label %22
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %18, %8 ]
%10 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0), %5 ], [ %17, %8 ]
%11 = getelementptr inbounds i8, i8* %2, i64 %9
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%16 = getelementptr inbounds i8, i8* %10, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 58, i8* %16
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %20, label %8
20: ; preds = %8
%21 = getelementptr inbounds i8, i8* %17, i64 -1
store i8 0, i8* %21
br label %22
22: ; preds = %20, %7
ret i8* getelementptr inbounds ([49 x i8], [49 x i8]* @print_hw_addr.habuf, i64 0, i64 0)
}