#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
char *ether_ntoa(const unsigned char *mac) {
  int i;
  static char themac[18];
  memset(themac, 0, 18);
  for (i = 0; i < 5; i++)
    sprintf(themac + (3 * i), "%02x:", mac[i]);
  sprintf(themac + (3 * i), "%02x", mac[i]);
  return themac;
}


x86 assembly (clang, -O0):
<ether_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1030 <memset@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1186 <ether_ntoa+0x66>
imul   $0x3,-0xc(%rbp),%eax
cltq
lea    0x2ee3(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xe91(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <ether_ntoa+0x26>
imul   $0x3,-0xc(%rbp),%eax
cltq
lea    0x2ead(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xe61(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
lea    0x2e8b(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ether_ntoa>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0x2f11(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1030 <memset@plt>
movzbl (%rbx),%edx
lea    0xeb8(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
movzbl 0x1(%rbx),%edx
lea    0x2ee5(%rip),%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
movzbl 0x2(%rbx),%edx
lea    0x2ed5(%rip),%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
movzbl 0x3(%rbx),%edx
lea    0x2ec5(%rip),%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
movzbl 0x4(%rbx),%edx
lea    0x2eb5(%rip),%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
movzbl 0x5(%rbx),%edx
lea    0x2ea5(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1040 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@ether_ntoa.themac = internal global [18 x i8] zeroinitializer
@.str = [6 x i8] c"%02x:\00"
@.str.1 = [5 x i8] c"%02x\00"
define i8* @ether_ntoa(i8* nocapture %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 0), i32 0, i32 18)
%3 = load i8, i8* %0
%4 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %3)
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 3), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 6), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
%13 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 9), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = getelementptr inbounds i8, i8* %0, i64 4
%15 = load i8, i8* %14
%16 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 12), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
%17 = getelementptr inbounds i8, i8* %0, i64 5
%18 = load i8, i8* %17
%19 = tail call i32 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 15), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %18)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ether_ntoa.themac, i64 0, i64 0)
}