#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 */
struct ether_addr {
  int /*<<< orphan*/ *ether_addr_octet;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
char *ether_ntoa_r(const struct ether_addr *p_a, char *x) {
  char *y;
  y = x;
  for (int ii = 0; ii < 6; ii++) {
    x += sprintf(x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]);
  }
  return y;
}


x86 assembly (clang, -O0):
<ether_ntoa_r>:
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)
cmpl   $0x6,-0x1c(%rbp)
jge    1186 <ether_ntoa_r+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
lea    0xeb9(%rip),%rsi
lea    0xeb3(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <ether_ntoa_r+0x1f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ether_ntoa_r>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%rax
mov    (%rax),%edx
lea    0xed6(%rip),%rsi
mov    %r14,%rdi
call   1030 <sprintf@plt>
movslq %eax,%r13
add    %r14,%r13
mov    (%r12),%rax
mov    0x4(%rax),%edx
lea    0xeb9(%rip),%r15
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movslq %eax,%rbx
add    %r13,%rbx
mov    (%r12),%rax
mov    0x8(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movslq %eax,%r13
add    %rbx,%r13
mov    (%r12),%rax
mov    0xc(%rax),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movslq %eax,%rbx
add    %r13,%rbx
mov    (%r12),%rax
mov    0x10(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    (%r12),%rax
mov    0x14(%rax),%edx
mov    %r15,%rsi
call   1030 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ether_addr = type { i32* }
@.str = [5 x i8] c"%.2X\00"
@.str.1 = [6 x i8] c":%.2X\00"
define i8* @ether_ntoa_r(%struct.ether_addr* nocapture %0, i8* returned writeonly %1) {
%3 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %0, i64 0, i32 0
%4 = load i32*, i32** %3
%5 = load i32, i32* %4
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = load i32, i32* %10
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = load i32, i32* %16
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %14, i64 %19
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 3
%23 = load i32, i32* %22
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %20, i64 %25
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 4
%29 = load i32, i32* %28
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %26, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %26, i64 %31
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 5
%35 = load i32, i32* %34
%36 = tail call i32 @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
ret i8* %1
}