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

/* Variables and functions */
int ETH_ALEN;
char *get_buf();
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/ const);
char *print_hw_addr(const u_char *addr) {
  int i;
  char *point = get_buf();
  char *current = point;
  for (i = 0; i < ETH_ALEN; i++)
    point += sprintf(point, i == (ETH_ALEN - 1) ? "%02x" : "%02x:", addr[i]);
  return current;
}


x86 assembly (clang, -O0):
<print_hw_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <get_buf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
jge    11ad <print_hw_addr+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
lea    0xe93(%rip),%rsi
lea    0xe87(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <print_hw_addr+0x26>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hw_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <get_buf@plt>
mov    %rax,(%rsp)
mov    0x2ea8(%rip),%r12
mov    (%r12),%eax
test   %eax,%eax
jle    118b <print_hw_addr+0x6b>
xor    %ebx,%ebx
lea    0xeaf(%rip),%rbp
lea    0xead(%rip),%r14
mov    (%rsp),%r13
nopl   0x0(%rax)
add    $0xffffffff,%eax
cmp    %rax,%rbx
mov    %r14,%rsi
cmove  %rbp,%rsi
mov    (%r15,%rbx,4),%edx
mov    %r13,%rdi
call   1030 <sprintf@plt>
cltq
add    %rax,%r13
add    $0x1,%rbx
movslq (%r12),%rax
cmp    %rax,%rbx
jl     1160 <print_hw_addr+0x40>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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