#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 ETHER_ADDR_LEN;
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
char *ether_etoa(const unsigned char *e, char *a) {
  char *c = a;
  int i;
  for (i = 0; i < ETHER_ADDR_LEN; i++) {
    if (i)
      *c++ = ':';
    c += sprintf(c, "%02X", e[i] & 0xff);
  }
  return a;
}


x86 assembly (clang, -O0):
<ether_etoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2eb7(%rip),%rcx
cmp    (%rcx),%eax
jge    119f <ether_etoa+0x8f>
cmpl   $0x0,-0x1c(%rbp)
je     115d <ether_etoa+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x3a,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xff,%eax
lea    0xe87(%rip),%rsi
movzbl %al,%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <ether_etoa+0x1f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ether_etoa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2ecb(%rip),%r12
cmpl   $0x0,(%r12)
jle    118b <ether_etoa+0x7b>
mov    %rdi,%r13
movzbl (%rdi),%edx
lea    0xec7(%rip),%rsi
mov    %r14,%rdi
call   1030 <sprintf@plt>
cmpl   $0x2,(%r12)
jl     118b <ether_etoa+0x7b>
movslq %eax,%rbx
add    %r14,%rbx
mov    $0x1,%ebp
lea    0xea6(%rip),%r15
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rdi
movb   $0x3a,(%rbx)
movzbl 0x0(%r13,%rbp,1),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%rbp
movslq (%r12),%rax
cmp    %rax,%rbp
jl     1160 <ether_etoa+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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