#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*/ printf(char *, unsigned char, char);
void print_mac(unsigned char *mac, unsigned add) {
  int i;
  for (i = 0; i < 6; i++) {
    unsigned char m;
    char sep;
    if (i != (6 - 1)) {
      m = mac[i];
      sep = ':';
    } else {
      m = mac[i] + (add ? 1 : 0);
      sep = '\n';
    }
    printf("%02X%c", m, sep);
  }
}


x86 assembly (clang, -O0):
<print_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jge    119a <print_mac+0x8a>
cmpl   $0x5,-0x10(%rbp)
je     1151 <print_mac+0x41>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movb   $0x3a,-0x12(%rbp)
jmp    1176 <print_mac+0x66>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0xc(%rbp),%esi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %al,-0x11(%rbp)
movb   $0xa,-0x12(%rbp)
mov    -0x11(%rbp),%al
lea    0xe80(%rip),%rdi
movzbl %al,%esi
movsbl -0x12(%rbp),%edx
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <print_mac+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mac>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
movzbl (%rdi),%esi
lea    0xedc(%rip),%rbx
mov    %rbx,%rdi
mov    $0x3a,%edx
call   1030 <printf@plt>
movzbl 0x1(%rbp),%esi
mov    %rbx,%rdi
mov    $0x3a,%edx
call   1030 <printf@plt>
movzbl 0x2(%rbp),%esi
mov    %rbx,%rdi
mov    $0x3a,%edx
call   1030 <printf@plt>
movzbl 0x3(%rbp),%esi
mov    %rbx,%rdi
mov    $0x3a,%edx
call   1030 <printf@plt>
movzbl 0x4(%rbp),%esi
mov    %rbx,%rdi
mov    $0x3a,%edx
call   1030 <printf@plt>
mov    0x5(%rbp),%al
cmp    $0x1,%r14d
sbb    $0xff,%al
movzbl %al,%esi
mov    %rbx,%rdi
mov    $0xa,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [7 x i8] c"%02X%c\00"
define void @print_mac(i8* nocapture %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 5
%4 = icmp ne i32 %1, 0
%5 = zext i1 %4 to i8
%6 = load i8, i8* %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %6, i8 signext 58)
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 signext 58)
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i8 signext 58)
%14 = getelementptr inbounds i8, i8* %0, i64 3
%15 = load i8, i8* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %15, i8 signext 58)
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = load i8, i8* %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %18, i8 signext 58)
%20 = load i8, i8* %3
%21 = add i8 %20, %5
%22 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %21, i8 signext 10)
ret void
}