#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*/ debug_err(char *, int);
scalar_t__ parse_uint8_hex(char *, unsigned char *);
int strlen(char *);
int parse_mac(char *mac, unsigned char *bytes) {
  int i;
  int rc = -1;
  int loc_seps[5] = {2, 5, 8, 11, 14};
  int loc_bytes[6] = {0, 3, 6, 9, 12, 15};
  if (strlen(mac) != (2 * 6 + 5)) {
    debug_err("expected 17, but strlen(mac)==%zu\n", strlen(mac));
    goto cleanup;
  }
  for (i = 0; i < 5; ++i) {
    char *x = mac + loc_seps[i];
    if (*x != ':') {
      debug_err("mac[%d] was not a colon\n", loc_seps[i]);
      goto cleanup;
    }
    *x = '\0';
  }
  for (i = 0; i < 6; ++i) {
    if (parse_uint8_hex(mac + loc_bytes[i], bytes + i)) {
      debug_err("mac[%d] was not a valid byte\n", loc_bytes[i]);
      goto cleanup;
    }
  }
  rc = 0;
cleanup:
  return rc;
}


x86 assembly (clang, -O0):
<parse_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeaf(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xead(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x11,%eax
je     11b5 <parse_mac+0x85>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xe8d(%rip),%rdi
call   1050 <debug_err@plt>
jmp    1286 <parse_mac+0x156>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1218 <parse_mac+0xe8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movslq -0x30(%rbp,%rcx,4),%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1203 <parse_mac+0xd3>
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe62(%rip),%rdi
call   1050 <debug_err@plt>
jmp    1286 <parse_mac+0x156>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <parse_mac+0x8c>
movl   $0x0,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    127f <parse_mac+0x14f>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
movslq -0x50(%rbp,%rax,4),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1030 <parse_uint8_hex@plt>
cmp    $0x0,%rax
je     126c <parse_mac+0x13c>
movslq -0x14(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xe12(%rip),%rdi
call   1050 <debug_err@plt>
jmp    1286 <parse_mac+0x156>
jmp    1271 <parse_mac+0x141>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121f <parse_mac+0xef>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mac>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x11,%eax
jne    123b <parse_mac+0x10b>
mov    $0x2,%esi
cmpb   $0x3a,0x2(%rbx)
jne    124e <parse_mac+0x11e>
movb   $0x0,0x2(%rbx)
mov    $0x5,%esi
cmpb   $0x3a,0x5(%rbx)
jne    124e <parse_mac+0x11e>
movb   $0x0,0x5(%rbx)
mov    $0x8,%esi
cmpb   $0x3a,0x8(%rbx)
jne    124e <parse_mac+0x11e>
movb   $0x0,0x8(%rbx)
mov    $0xb,%esi
cmpb   $0x3a,0xb(%rbx)
jne    124e <parse_mac+0x11e>
movb   $0x0,0xb(%rbx)
mov    $0xe,%esi
cmpb   $0x3a,0xe(%rbx)
jne    124e <parse_mac+0x11e>
movb   $0x0,0xe(%rbx)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <parse_uint8_hex@plt>
xor    %esi,%esi
test   %rax,%rax
jne    1232 <parse_mac+0x102>
lea    0x3(%rbx),%rdi
lea    0x1(%r14),%rsi
call   1030 <parse_uint8_hex@plt>
mov    $0x3,%esi
test   %rax,%rax
jne    1232 <parse_mac+0x102>
lea    0x6(%rbx),%rdi
lea    0x2(%r14),%rsi
call   1030 <parse_uint8_hex@plt>
mov    $0x6,%esi
test   %rax,%rax
jne    1232 <parse_mac+0x102>
lea    0x9(%rbx),%rdi
lea    0x3(%r14),%rsi
call   1030 <parse_uint8_hex@plt>
mov    $0x9,%esi
test   %rax,%rax
jne    1232 <parse_mac+0x102>
lea    0xc(%rbx),%rdi
lea    0x4(%r14),%rsi
call   1030 <parse_uint8_hex@plt>
mov    $0xc,%esi
test   %rax,%rax
jne    1232 <parse_mac+0x102>
add    $0xf,%rbx
add    $0x5,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <parse_uint8_hex@plt>
mov    $0xf,%esi
test   %rax,%rax
je     1267 <parse_mac+0x137>
lea    0xe03(%rip),%rdi
jmp    1255 <parse_mac+0x125>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xdb6(%rip),%rdi
mov    %eax,%esi
jmp    1255 <parse_mac+0x125>
lea    0xdce(%rip),%rdi
call   1050 <debug_err@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    125f <parse_mac+0x12f>

LLVM IR (-O0):
@__const.parse_mac.loc_seps = [5 x i32] [i32 2, i32 5, i32 8, i32 11, i32 14]
@__const.parse_mac.loc_bytes = [6 x i32] [i32 0, i32 3, i32 6, i32 9, i32 12, i32 15]
@.str = [35 x i8] c"expected 17, but strlen(mac)==%zu\0A\00"
@.str.1 = [25 x i8] c"mac[%d] was not a colon\0A\00"
@.str.2 = [30 x i8] c"mac[%d] was not a valid byte\0A\00"
define i32 @parse_mac(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i32]
%8 = alloca [6 x i32]
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %6
%10 = bitcast [5 x i32]* %7 to i8*
%11 = bitcast [6 x i32]* %8 to i8*
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp ne i32 %13, 17
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @debug_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %75
19: ; preds = %2
store i32 0, i32* %5
br label %20
20: ; preds = %43, %19
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 5
br i1 %22, label %23, label %46
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 58
br i1 %34, label %35, label %41
35: ; preds = %23
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @debug_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %75
41: ; preds = %23
%42 = load i8*, i8** %9
store i8 0, i8* %42
br label %43
43: ; preds = %41
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %20
46: ; preds = %20
store i32 0, i32* %5
br label %47
47: ; preds = %71, %46
%48 = load i32, i32* %5
%49 = icmp slt i32 %48, 6
br i1 %49, label %50, label %74
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %51, i64 %56
%58 = load i8*, i8** %4
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = call i64 @parse_uint8_hex(i8* %57, i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %50
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = call i32 @debug_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %68)
br label %75
70: ; preds = %50
br label %71
71: ; preds = %70
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
br label %47
74: ; preds = %47
store i32 0, i32* %6
br label %75
75: ; preds = %74, %64, %35, %15
%76 = load i32, i32* %6
ret i32 %76
}

LLVM IR (-O2):
@.str = [35 x i8] c"expected 17, but strlen(mac)==%zu\0A\00"
@.str.1 = [25 x i8] c"mac[%d] was not a colon\0A\00"
@.str.2 = [30 x i8] c"mac[%d] was not a valid byte\0A\00"
define i32 @parse_mac(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 17
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 58
br i1 %8, label %15, label %12
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @debug_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %62
12: ; preds = %27, %23, %19, %15, %5
%13 = phi i32 [ 2, %5 ], [ 5, %15 ], [ 8, %19 ], [ 11, %23 ], [ 14, %27 ]
%14 = tail call i32 @debug_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %62
15: ; preds = %5
store i8 0, i8* %6
%16 = getelementptr inbounds i8, i8* %0, i64 5
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 58
br i1 %18, label %19, label %12
19: ; preds = %15
store i8 0, i8* %16
%20 = getelementptr inbounds i8, i8* %0, i64 8
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 58
br i1 %22, label %23, label %12
23: ; preds = %19
store i8 0, i8* %20
%24 = getelementptr inbounds i8, i8* %0, i64 11
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 58
br i1 %26, label %27, label %12
27: ; preds = %23
store i8 0, i8* %24
%28 = getelementptr inbounds i8, i8* %0, i64 14
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 58
br i1 %30, label %31, label %12
31: ; preds = %27
store i8 0, i8* %28
%32 = tail call i64 @parse_uint8_hex(i8* %0, i8* %1)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %59
34: ; preds = %31
%35 = getelementptr inbounds i8, i8* %0, i64 3
%36 = getelementptr inbounds i8, i8* %1, i64 1
%37 = tail call i64 @parse_uint8_hex(i8* %35, i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %59
39: ; preds = %34
%40 = getelementptr inbounds i8, i8* %0, i64 6
%41 = getelementptr inbounds i8, i8* %1, i64 2
%42 = tail call i64 @parse_uint8_hex(i8* %40, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %59
44: ; preds = %39
%45 = getelementptr inbounds i8, i8* %0, i64 9
%46 = getelementptr inbounds i8, i8* %1, i64 3
%47 = tail call i64 @parse_uint8_hex(i8* %45, i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %59
49: ; preds = %44
%50 = getelementptr inbounds i8, i8* %0, i64 12
%51 = getelementptr inbounds i8, i8* %1, i64 4
%52 = tail call i64 @parse_uint8_hex(i8* %50, i8* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = getelementptr inbounds i8, i8* %0, i64 15
%56 = getelementptr inbounds i8, i8* %1, i64 5
%57 = tail call i64 @parse_uint8_hex(i8* %55, i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %54, %49, %44, %39, %34, %31
%60 = phi i32 [ 0, %31 ], [ 3, %34 ], [ 6, %39 ], [ 9, %44 ], [ 12, %49 ], [ 15, %54 ]
%61 = tail call i32 @debug_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %54, %12, %9, %59
%63 = phi i32 [ -1, %9 ], [ -1, %12 ], [ -1, %59 ], [ 0, %54 ]
ret i32 %63
}