#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*/ printf(char *, int /*<<< orphan*/, ...);
void printhex_macaddr(void *hex, int len, char *tag) {
  int i;
  unsigned char *p = (unsigned char *)hex;
  if (len < 1)
    return;
  for (i = 0; i < len - 1; i++) {
    if (*p < 0x10)
      printf("0%x%s", *p++, tag);
    else
      printf("%2x%s", *p++, tag);
  }
  if (*p < 0x10)
    printf("0%x", *p++);
  else
    printf("%2x", *p++);
}


x86 assembly (clang, -O0):
<printhex_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    113a <printhex_macaddr+0x2a>
jmp    1217 <printhex_macaddr+0x107>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c2 <printhex_macaddr+0xb2>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x10,%eax
jge    118b <printhex_macaddr+0x7b>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%esi
mov    -0x18(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <printhex_macaddr+0x9f>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%esi
mov    -0x18(%rbp),%rdx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b4 <printhex_macaddr+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <printhex_macaddr+0x31>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x10,%eax
jge    11f7 <printhex_macaddr+0xe7>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1217 <printhex_macaddr+0x107>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex_macaddr>:
test   %esi,%esi
jle    1187 <printhex_macaddr+0x77>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x1,%esi
je     1160 <printhex_macaddr+0x50>
mov    %rdx,%r14
add    $0xffffffff,%ebp
lea    0xecd(%rip),%r15
lea    0xecc(%rip),%r12
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%esi
cmp    $0x10,%esi
mov    %r12,%rdi
cmovb  %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    1140 <printhex_macaddr+0x30>
movzbl (%rbx),%esi
cmp    $0x10,%esi
lea    0xe9f(%rip),%rax
lea    0xe9c(%rip),%rdi
cmovb  %rax,%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
ret

LLVM IR (-O0):
@.str = [6 x i8] c"0%x%s\00"
@.str.1 = [6 x i8] c"%2x%s\00"
@.str.2 = [4 x i8] c"0%x\00"
@.str.3 = [4 x i8] c"%2x\00"
define void @printhex_macaddr(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
store i8* %9, i8** %8
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %3
br label %59
13: ; preds = %3
store i32 0, i32* %7
br label %14
14: ; preds = %39, %13
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %42
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp slt i32 %22, 16
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %8
%27 = load i8, i8* %25
%28 = zext i8 %27 to i32
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %29)
br label %38
31: ; preds = %19
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %8
%34 = load i8, i8* %32
%35 = zext i8 %34 to i32
%36 = load i8*, i8** %6
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35, i8* %36)
br label %38
38: ; preds = %31, %24
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %14
42: ; preds = %14
%43 = load i8*, i8** %8
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp slt i32 %45, 16
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %8
%50 = load i8, i8* %48
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %59
53: ; preds = %42
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %8
%56 = load i8, i8* %54
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %12, %53, %47
ret void
}

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