#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*/ sprintf(char *, char *, ...);
const char *renderMac(unsigned char *macBytes, unsigned char macLength,
                      char *buff, unsigned int buffLen) {
  buff[0] = 0;
  char *ptr = buff;
  for (int i = 0; i < macLength; i++) {
    if (i > 0) {
      sprintf(ptr, ":");
      ptr++;
    }
    sprintf(ptr, "%02X", (int)macBytes[i]);
    ptr += 2;
  }
  return buff;
}


x86 assembly (clang, -O0):
<renderMac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    11ae <renderMac+0x9e>
cmpl   $0x0,-0x2c(%rbp)
jle    1176 <renderMac+0x66>
mov    -0x28(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113f <renderMac+0x2f>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<renderMac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
movb   $0x0,(%rdx)
test   %esi,%esi
je     1185 <renderMac+0x75>
mov    %esi,%ebx
mov    %rdi,%r15
movzbl (%rdi),%edx
lea    0xecc(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
cmp    $0x1,%bl
je     1185 <renderMac+0x75>
movzbl %bl,%r13d
lea    0x3(%r14),%rbx
mov    $0x1,%ebp
lea    0xea9(%rip),%r12
nopw   0x0(%rax,%rax,1)
movw   $0x3a,-0x1(%rbx)
movzbl (%r15,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x1,%rbp
add    $0x3,%rbx
cmp    %rbp,%r13
jne    1160 <renderMac+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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