#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*/ errx(int, char *, char const *);
int sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
void str2mac(const char *macaddr, unsigned char mac[6]) {
  unsigned int m[6];
  if (sscanf(macaddr, "%02x:%02x:%02x:%02x:%02x:%02x", &m[0], &m[1], &m[2],
             &m[3], &m[4], &m[5]) != 6)
    errx(1, "Failed to parse mac address '%s'", macaddr);
  mac[0] = m[0];
  mac[1] = m[1];
  mac[2] = m[2];
  mac[3] = m[3];
  mac[4] = m[4];
  mac[5] = m[5];
}


x86 assembly (clang, -O0):
<str2mac>:
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    0xe99(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
cmp    $0x6,%eax
je     1193 <str2mac+0x73>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe90(%rip),%rsi
call   1030 <errx@plt>
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2mac>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%r10
lea    0x14(%rsp),%rax
lea    0xec3(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %r10
call   1040 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
je     1175 <str2mac+0x55>
lea    0xec6(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1030 <errx@plt>
movdqa (%rsp),%xmm0
pand   0xe7e(%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)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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