#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 sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
int mac_str_to_n(const char *addr, unsigned char mac0[6]) {
  unsigned int mac[6];
  int i;
  if (sscanf(addr, "%2x:%2x:%2x:%2x:%2x:%2x", mac, mac + 1, mac + 2, mac + 3,
             mac + 4, mac + 5) != 6)
    return -1;
  for (i = 0; i < 6; i++)
    mac0[i] = mac[i];
  return 0;
}


x86 assembly (clang, -O0):
<mac_str_to_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%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    0xea9(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     117a <mac_str_to_n+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <mac_str_to_n+0xa5>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    11ae <mac_str_to_n+0x9e>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1181 <mac_str_to_n+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mac_str_to_n>:
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    0xed8(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %r10
call   1030 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x6,%ecx
jne    117c <mac_str_to_n+0x6c>
movdqa (%rsp),%xmm0
pand   0xea0(%rip),%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,(%rbx)
mov    0x10(%rsp),%al
mov    %al,0x4(%rbx)
mov    0x14(%rsp),%al
mov    %al,0x5(%rbx)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
define i32 @mac_str_to_n(i8* nocapture %0, i8* 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 %24
13: ; preds = %2
%14 = bitcast [6 x i32]* %3 to <4 x i32>*
%15 = load <4 x i32>, <4 x i32>* %14
%16 = trunc <4 x i32> %15 to <4 x i8>
%17 = bitcast i8* %1 to <4 x i8>*
store <4 x i8> %16, <4 x i8>* %17
%18 = load i32, i32* %9
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %19, i8* %20
%21 = load i32, i32* %10
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %22, i8* %23
br label %24
24: ; preds = %13, %2
%25 = phi i32 [ -1, %2 ], [ 0, %13 ]
ret i32 %25
}