#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char const *, char *, int *, int *, int *, int *, int *, int *);
int strlen(char const *);
int inet_atonmac(const char *s, char *addr) {
  int mac[6], ret;
  memset(addr, 0, 6);
  if (strlen(s) != 17) {
    printf("error mac address string length, %d\n", strlen(s));
    return -1;
  }
  ret = sscanf(s, "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3],
               &mac[4], &mac[5]);
  if (ret != 6) {
    printf("parse mac address string error\n");
    return -1;
  }
  addr[0] = (char)mac[0];
  addr[1] = (char)mac[1];
  addr[2] = (char)mac[2];
  addr[3] = (char)mac[3];
  addr[4] = (char)mac[4];
  addr[5] = (char)mac[5];
  return 0;
}


x86 assembly (clang, -O0):
<inet_atonmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x11,%eax
je     1197 <inet_atonmac+0x57>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <inet_atonmac+0x111>
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    0xe57(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
je     1203 <inet_atonmac+0xc3>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <inet_atonmac+0x111>
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x5(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_atonmac>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x11,%eax
jne    11de <inet_atonmac+0x8e>
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%r10
lea    0x14(%rsp),%rax
lea    0xe9c(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
push   %rax
push   %r10
call   1070 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    11f8 <inet_atonmac+0xa8>
movdqa (%rsp),%xmm0
pand   0xe43(%rip),%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,(%r14)
mov    0x10(%rsp),%al
mov    %al,0x4(%r14)
mov    0x14(%rsp),%al
mov    %al,0x5(%r14)
xor    %eax,%eax
jmp    1209 <inet_atonmac+0xb9>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe23(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1204 <inet_atonmac+0xb4>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [37 x i8] c"error mac address string length, %d\0A\00"
@.str.1 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.2 = [32 x i8] c"parse mac address string error\0A\00"
define i32 @inet_atonmac(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** %5
%9 = call i32 @memset(i8* %8, i32 0, i32 6)
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp ne i32 %11, 17
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 -1, i32* %3
br label %61
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 1
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 2
%22 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 3
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 4
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 5
%25 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %19, i32* %20, i32* %21, i32* %22, i32* %23, i32* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 6
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
30: ; preds = %17
%31 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %31
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 %33, i8* %35
%36 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 1
%37 = load i32, i32* %36
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 %38, i8* %40
%41 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 2
%42 = load i32, i32* %41
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 2
store i8 %43, i8* %45
%46 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 3
%47 = load i32, i32* %46
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i64 3
store i8 %48, i8* %50
%51 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 4
%52 = load i32, i32* %51
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i64 4
store i8 %53, i8* %55
%56 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 5
%57 = load i32, i32* %56
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 5
store i8 %58, i8* %60
store i32 0, i32* %3
br label %61
61: ; preds = %30, %28, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [37 x i8] c"error mac address string length, %d\0A\00"
@.str.1 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@str = [31 x i8] c"parse mac address string error\00"
define i32 @inet_atonmac(i8* %0, i8* %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = tail call i32 @memset(i8* %1, i32 0, i32 6)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 17
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %33
11: ; preds = %2
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%16 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%18 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %12, i32* %13, i32* %14, i32* %15, i32* %16, i32* %17)
%19 = icmp eq i32 %18, 6
br i1 %19, label %22, label %20
20: ; preds = %11
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %33
22: ; preds = %11
%23 = bitcast [6 x i32]* %3 to <4 x i32>*
%24 = load <4 x i32>, <4 x i32>* %23
%25 = trunc <4 x i32> %24 to <4 x i8>
%26 = bitcast i8* %1 to <4 x i8>*
store <4 x i8> %25, <4 x i8>* %26
%27 = load i32, i32* %16
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %28, i8* %29
%30 = load i32, i32* %17
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %31, i8* %32
br label %33
33: ; preds = %22, %20, %8
%34 = phi i32 [ -1, %8 ], [ -1, %20 ], [ 0, %22 ]
ret i32 %34
}