#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char *, char *, int *, int *, int *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int parse_mac(char *src, unsigned int macaddr[]) {
  int count;
  int i;
  int buf[6];
  count = sscanf(src, "%2x:%2x:%2x:%2x:%2x:%2x", &buf[0], &buf[1], &buf[2],
                 &buf[3], &buf[4], &buf[5]);
  if (count != 6) {
    fprintf(stderr,
            "MAC parsing error: Expected %%2x:%%2x:%%2x:%%2x:%%2x:%%2x.\n");
    exit(-1);
  }
  for (i = 0; i < count; i++) {
    macaddr[i] = buf[i];
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x30(%rbp),%r10
add    $0x10,%r10
lea    -0x30(%rbp),%rax
add    $0x14,%rax
lea    0xe89(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
je     11b1 <parse_mac+0x81>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <parse_mac+0xb5>
movslq -0x18(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b8 <parse_mac+0x88>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mac>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%r10
lea    0x14(%rsp),%rax
lea    0xea8(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %r10
call   1040 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    1184 <parse_mac+0x54>
mov    0x10(%rsp),%rax
mov    %rax,0x10(%rbx)
movaps (%rsp),%xmm0
movups %xmm0,(%rbx)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
@stderr = global i32 0
@.str.1 = [60 x i8] c"MAC parsing error: Expected %%2x:%%2x:%%2x:%%2x:%%2x:%%2x.\0A\00"
define i32 @parse_mac(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [6 x i32]
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 1
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 2
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 3
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 4
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 5
%15 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 6
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
store i32 0, i32* %6
br label %23
23: ; preds = %36, %22
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %23
39: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
@stderr = global i32 0
@.str.1 = [60 x i8] c"MAC parsing error: Expected %%2x:%%2x:%%2x:%%2x:%%2x:%%2x.\0A\00"
define i32 @parse_mac(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%11 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10)
%12 = icmp eq i32 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = bitcast i32* %1 to i8*
ret i32 0
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
}