#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 */
typedef int /*<<< orphan*/ sMacStr;

/* Variables and functions */
char *osStrTok_r(char *, char *, char **);
int /*<<< orphan*/ utilMacZero(unsigned char *);
scalar_t__ utilStrChkShort(char *, int /*<<< orphan*/, int, short *);
int /*<<< orphan*/ utilStrMCpy(char *, char *, int);
long utilMacStr2Mac(char *sStr, unsigned char *byMac) {
  char sMacStr[20];
  char *pPtr;
  char *pLast;
  int iCnt;
  char sSubMac[6];
  short iSubMac;
  if (byMac == (0) || sStr == (0))
    return (-1);
  utilStrMCpy(sMacStr, sStr, sizeof(sMacStr));
  utilMacZero(byMac);
  sSubMac[0] = '0';
  sSubMac[1] = 'x';
  sSubMac[5] = 'x';
  for (iCnt = 0, pPtr = osStrTok_r(sMacStr, ":-., ", &pLast);
       iCnt < 6 && pPtr != 0;
       iCnt++, pPtr = osStrTok_r(pLast, ":-., ", &pLast)) {
    sSubMac[2] = pPtr[0];
    sSubMac[3] = pPtr[1];
    sSubMac[4] = pPtr[2];
    if (utilStrChkShort(sSubMac, 0, 255, &iSubMac) != 0)
      return -1;
    byMac[iCnt] = (unsigned char)iSubMac;
  }
  if (iCnt < 6 || pLast != (0))
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<utilMacStr2Mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1166 <utilMacStr2Mac+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    1173 <utilMacStr2Mac+0x33>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    128c <utilMacStr2Mac+0x14c>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x14,%edx
call   1040 <utilStrMCpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <utilMacZero@plt>
movb   $0x30,-0x4a(%rbp)
movb   $0x78,-0x49(%rbp)
movb   $0x78,-0x45(%rbp)
movl   $0x0,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe54(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <osStrTok_r@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x6,-0x44(%rbp)
mov    %al,-0x4d(%rbp)
jge    11d3 <utilMacStr2Mac+0x93>
cmpq   $0x0,-0x38(%rbp)
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    11e3 <utilMacStr2Mac+0xa3>
jmp    1262 <utilMacStr2Mac+0x122>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x47(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x46(%rbp)
lea    -0x4a(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
lea    -0x4c(%rbp),%rcx
call   1050 <utilStrChkShort@plt>
cmp    $0x0,%rax
je     122b <utilMacStr2Mac+0xeb>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    128c <utilMacStr2Mac+0x14c>
mov    -0x4c(%rbp),%ax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdb0(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <osStrTok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    11b9 <utilMacStr2Mac+0x79>
cmpl   $0x6,-0x44(%rbp)
jl     1277 <utilMacStr2Mac+0x137>
cmpq   $0x0,-0x40(%rbp)
je     1284 <utilMacStr2Mac+0x144>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    128c <utilMacStr2Mac+0x14c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilMacStr2Mac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffffffffffff,%rax
test   %rdi,%rdi
je     1246 <utilMacStr2Mac+0x106>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1246 <utilMacStr2Mac+0x106>
mov    %rdi,%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x14,%edx
call   1040 <utilStrMCpy@plt>
mov    %rbx,%rdi
call   1030 <utilMacZero@plt>
movw   $0x7830,0x2(%rsp)
movb   $0x78,0x7(%rsp)
lea    0xe66(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1060 <osStrTok_r@plt>
test   %rax,%rax
je     122a <utilMacStr2Mac+0xea>
xor    %r14d,%r14d
lea    0x2(%rsp),%r15
mov    %rsp,%r12
lea    0xe42(%rip),%r13
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rax),%ecx
mov    %cl,0x4(%rsp)
movzbl 0x1(%rax),%ecx
mov    %cl,0x5(%rsp)
movzbl 0x2(%rax),%eax
mov    %al,0x6(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xff,%edx
mov    %r12,%rcx
call   1050 <utilStrChkShort@plt>
test   %rax,%rax
jne    123f <utilMacStr2Mac+0xff>
movzbl (%rsp),%eax
mov    %al,(%rbx,%r14,1)
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <osStrTok_r@plt>
cmp    $0x5,%r14
setb   %cl
jae    122c <utilMacStr2Mac+0xec>
add    $0x1,%r14
test   %rax,%rax
jne    11d0 <utilMacStr2Mac+0x90>
jmp    122c <utilMacStr2Mac+0xec>
mov    $0x1,%cl
cmpq   $0x0,0x8(%rsp)
setne  %al
or     %cl,%al
movzbl %al,%eax
neg    %rax
jmp    1246 <utilMacStr2Mac+0x106>
mov    $0xffffffffffffffff,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c":-., \00"
define i64 @utilMacStr2Mac(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [6 x i8]
%11 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %2
store i64 -1, i64* %3
br label %74
18: ; preds = %14
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = call i32 @utilStrMCpy(i8* %19, i8* %20, i32 20)
%22 = load i8*, i8** %5
%23 = call i32 @utilMacZero(i8* %22)
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
store i8 48, i8* %24
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 1
store i8 120, i8* %25
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 5
store i8 120, i8* %26
store i32 0, i32* %9
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%28 = call i8* @osStrTok_r(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %28, i8** %7
br label %29
29: ; preds = %61, %18
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 6
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br label %35
35: ; preds = %32, %29
%36 = phi i1 [ false, %29 ], [ %34, %32 ]
br i1 %36, label %37, label %66
37: ; preds = %35
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 2
store i8 %40, i8* %41
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 3
store i8 %44, i8* %45
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 2
%48 = load i8, i8* %47
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 4
store i8 %48, i8* %49
%50 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%51 = call i64 @utilStrChkShort(i8* %50, i32 0, i32 255, i16* %11)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %37
store i64 -1, i64* %3
br label %74
54: ; preds = %37
%55 = load i16, i16* %11
%56 = trunc i16 %55 to i8
%57 = load i8*, i8** %5
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 %56, i8* %60
br label %61
61: ; preds = %54
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
%64 = load i8*, i8** %8
%65 = call i8* @osStrTok_r(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %65, i8** %7
br label %29
66: ; preds = %35
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 6
br i1 %68, label %72, label %69
69: ; preds = %66
%70 = load i8*, i8** %8
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %73
72: ; preds = %69, %66
store i64 -1, i64* %3
br label %74
73: ; preds = %69
store i64 0, i64* %3
br label %74
74: ; preds = %73, %72, %53, %17
%75 = load i64, i64* %3
ret i64 %75
}

LLVM IR (-O2):
@.str = [6 x i8] c":-., \00"
define i64 @utilMacStr2Mac(i8* %0, i8* %1) {
%3 = alloca [20 x i8]
%4 = alloca i8*
%5 = alloca [6 x i8]
%6 = alloca i16
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%10 = bitcast i16* %6 to i8*
%11 = icmp eq i8* %1, null
%12 = icmp eq i8* %0, null
%13 = or i1 %12, %11
br i1 %13, label %51, label %14
14: ; preds = %2
%15 = call i32 @utilStrMCpy(i8* %7, i8* %0, i32 20)
%16 = call i32 @utilMacZero(i8* %1)
store i8 48, i8* %9
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
store i8 120, i8* %17
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
store i8 120, i8* %18
%19 = call i8* @osStrTok_r(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4)
%20 = icmp eq i8* %19, null
br i1 %20, label %45, label %21
21: ; preds = %14
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 2
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 3
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 4
br label %25
25: ; preds = %21, %35
%26 = phi i64 [ 0, %21 ], [ %39, %35 ]
%27 = phi i8* [ %19, %21 ], [ %41, %35 ]
%28 = load i8, i8* %27
store i8 %28, i8* %22
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = load i8, i8* %29
store i8 %30, i8* %23
%31 = getelementptr inbounds i8, i8* %27, i64 2
%32 = load i8, i8* %31
store i8 %32, i8* %24
%33 = call i64 @utilStrChkShort(i8* %9, i32 0, i32 255, i16* %6)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %51
35: ; preds = %25
%36 = load i16, i16* %6
%37 = trunc i16 %36 to i8
%38 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 %37, i8* %38
%39 = add nuw nsw i64 %26, 1
%40 = load i8*, i8** %4
%41 = call i8* @osStrTok_r(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4)
%42 = icmp ult i64 %26, 5
%43 = icmp ne i8* %41, null
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %25, label %45
45: ; preds = %35, %14
%46 = phi i1 [ true, %14 ], [ %42, %35 ]
%47 = load i8*, i8** %4
%48 = icmp ne i8* %47, null
%49 = select i1 %46, i1 true, i1 %48
%50 = sext i1 %49 to i64
br label %51
51: ; preds = %25, %45, %2
%52 = phi i64 [ -1, %2 ], [ %50, %45 ], [ -1, %25 ]
ret i64 %52
}