#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 sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char *, char);
int /*<<< orphan*/ strlen(char *);
char *niFormatMACAddress(char *dest, struct sockaddr *sa) {
  char *retval = dest;
  int lpc, hlen;
  char *haddr;
  hlen = 0;
  for (lpc = 0; lpc < hlen; lpc++) {
    sprintf(dest, "%s%02x", (lpc > 0) ? ":" : "", haddr[lpc] & 0xff);
    dest += strlen(dest);
  }
  return (retval);
}


x86 assembly (clang, -O0):
<niFormatMACAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b5 <niFormatMACAddress+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
lea    0xea8(%rip),%rdx
lea    0xea0(%rip),%rax
cmp    $0x0,%ecx
cmovg  %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
lea    0xe7a(%rip),%rsi
movsbl %al,%ecx
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <niFormatMACAddress+0x26>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<niFormatMACAddress>:
mov    %rdi,%rax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"%s%02x\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @niFormatMACAddress(i8* %0, %struct.sockaddr* %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store %struct.sockaddr* %1, %struct.sockaddr** %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %10
10: ; preds = %34, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%20 = load i8*, i8** %8
%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 = sext i8 %24 to i32
%26 = and i32 %25, 255
%27 = trunc i32 %26 to i8
%28 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %19, i8 signext %27)
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = load i8*, i8** %3
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %3
br label %34
34: ; preds = %14
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %10
37: ; preds = %10
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i8* @niFormatMACAddress(i8* readnone returned %0, %struct.sockaddr* nocapture readnone %1) {
ret i8* %0
}