#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*/ printf(char *, ...);
int sscanf(char const *, char *, int *, int *, int *, int *, int *, int *);
int /*<<< orphan*/ validate_macaddr(char const *);
int validate_sys_macaddr(const char *str) {
  if (!str)
    return 0;
  if (!validate_macaddr(str))
    return 0;
  int a[6];
  int sum = 0;
  if (sscanf(str, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], &a[4],
             &a[5]) != 6) {
    printf("Error: wrong number of octets\n");
    return 0;
  }
  if (a[0] & 1) {
    printf("Error: %x:%x:%x:%x:%x:%x is a multicast address\n", a[0], a[1],
           a[2], a[3], a[4], a[5]);
    return 0;
  }
  if ((a[0] == 0) && (a[1] == 0) && (a[2] == 94) && (a[3] == 0) &&
      (a[4] == 1)) {
    printf("Error: %x:%x:%x:%x:%x:%x is a vrrp mac address\n", a[0], a[1], a[2],
           a[3], a[4], a[5]);
    return 0;
  }
  int i;
  for (i = 0; i < 6; ++i) {
    sum += a[i];
  }
  if (sum == 0) {
    printf("Error: zero is not a valid address\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<validate_sys_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <validate_sys_macaddr+0x23>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
mov    -0x10(%rbp),%rdi
call   1030 <validate_macaddr@plt>
cmp    $0x0,%eax
jne    1171 <validate_sys_macaddr+0x41>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
movl   $0x0,-0x34(%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    0xe51(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
cmp    $0x6,%eax
je     11e0 <validate_sys_macaddr+0xb0>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
mov    -0x30(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1220 <validate_sys_macaddr+0xf0>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xe27(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
cmpl   $0x0,-0x30(%rbp)
jne    1283 <validate_sys_macaddr+0x153>
cmpl   $0x0,-0x2c(%rbp)
jne    1283 <validate_sys_macaddr+0x153>
cmpl   $0x5e,-0x28(%rbp)
jne    1283 <validate_sys_macaddr+0x153>
cmpl   $0x0,-0x24(%rbp)
jne    1283 <validate_sys_macaddr+0x153>
cmpl   $0x1,-0x20(%rbp)
jne    1283 <validate_sys_macaddr+0x153>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xdf5(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
movl   $0x0,-0x38(%rbp)
cmpl   $0x6,-0x38(%rbp)
jge    12b0 <validate_sys_macaddr+0x180>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    128a <validate_sys_macaddr+0x15a>
cmpl   $0x0,-0x34(%rbp)
jne    12d4 <validate_sys_macaddr+0x1a4>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12db <validate_sys_macaddr+0x1ab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_sys_macaddr>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1229 <validate_sys_macaddr+0xe9>
mov    %rdi,%rbx
call   1040 <validate_macaddr@plt>
test   %eax,%eax
je     1229 <validate_sys_macaddr+0xe9>
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x20(%rsp),%rax
lea    0x24(%rsp),%rdx
mov    %rdx,0x8(%rsp)
mov    %rax,(%rsp)
lea    0xe76(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
cmp    $0x6,%eax
jne    11f0 <validate_sys_macaddr+0xb0>
mov    0x10(%rsp),%esi
test   $0x1,%sil
jne    1200 <validate_sys_macaddr+0xc0>
mov    0x14(%rsp),%edi
mov    0x18(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x20(%rsp),%eax
test   %esi,%esi
jne    1232 <validate_sys_macaddr+0xf2>
test   %edi,%edi
jne    1232 <validate_sys_macaddr+0xf2>
cmp    $0x5e,%edx
jne    1232 <validate_sys_macaddr+0xf2>
test   %ecx,%ecx
jne    1232 <validate_sys_macaddr+0xf2>
cmp    $0x1,%eax
jne    1232 <validate_sys_macaddr+0xf2>
mov    0x24(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe69(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
xor    %edx,%edx
mov    $0x5e,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
jmp    1222 <validate_sys_macaddr+0xe2>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1229 <validate_sys_macaddr+0xe9>
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    0x20(%rsp),%r9d
mov    0x24(%rsp),%eax
mov    %eax,(%rsp)
lea    0xdf2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
add    %esi,%edi
add    %edi,%edx
add    %edx,%ecx
add    %ecx,%eax
mov    $0x1,%ebp
add    0x24(%rsp),%eax
jne    1229 <validate_sys_macaddr+0xe9>
lea    0xe27(%rip),%rdi
jmp    11f7 <validate_sys_macaddr+0xb7>

LLVM IR (-O0):
@.str = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.1 = [31 x i8] c"Error: wrong number of octets\0A\00"
@.str.2 = [49 x i8] c"Error: %x:%x:%x:%x:%x:%x is a multicast address\0A\00"
@.str.3 = [48 x i8] c"Error: %x:%x:%x:%x:%x:%x is a vrrp mac address\0A\00"
@.str.4 = [36 x i8] c"Error: zero is not a valid address\0A\00"
define i32 @validate_sys_macaddr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [6 x i32]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %100
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @validate_macaddr(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10
store i32 0, i32* %2
br label %100
15: ; preds = %10
store i32 0, i32* %5
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%22 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%23 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %17, i32* %18, i32* %19, i32* %20, i32* %21, i32* %22)
%24 = icmp ne i32 %23, 6
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %100
27: ; preds = %15
%28 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%29 = load i32, i32* %28
%30 = and i32 %29, 1
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %27
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%38 = load i32, i32* %37
%39 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%40 = load i32, i32* %39
%41 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%42 = load i32, i32* %41
%43 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %36, i32 %38, i32 %40, i32 %42, i32 %44)
store i32 0, i32* %2
br label %100
46: ; preds = %27
%47 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %80
50: ; preds = %46
%51 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%52 = load i32, i32* %51
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %80
54: ; preds = %50
%55 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, 94
br i1 %57, label %58, label %80
58: ; preds = %54
%59 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%60 = load i32, i32* %59
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %80
62: ; preds = %58
%63 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%64 = load i32, i32* %63
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %80
66: ; preds = %62
%67 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%72 = load i32, i32* %71
%73 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%74 = load i32, i32* %73
%75 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%76 = load i32, i32* %75
%77 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %68, i32 %70, i32 %72, i32 %74, i32 %76, i32 %78)
store i32 0, i32* %2
br label %100
80: ; preds = %62, %58, %54, %50, %46
store i32 0, i32* %6
br label %81
81: ; preds = %91, %80
%82 = load i32, i32* %6
%83 = icmp slt i32 %82, 6
br i1 %83, label %84, label %94
84: ; preds = %81
%85 = load i32, i32* %6
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = load i32, i32* %5
%90 = add nsw i32 %89, %88
store i32 %90, i32* %5
br label %91
91: ; preds = %84
%92 = load i32, i32* %6
%93 = add nsw i32 %92, 1
store i32 %93, i32* %6
br label %81
94: ; preds = %81
%95 = load i32, i32* %5
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %100
99: ; preds = %94
store i32 1, i32* %2
br label %100
100: ; preds = %99, %97, %66, %32, %25, %14, %9
%101 = load i32, i32* %2
ret i32 %101
}

LLVM IR (-O2):
@.str = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.2 = [49 x i8] c"Error: %x:%x:%x:%x:%x:%x is a multicast address\0A\00"
@.str.3 = [48 x i8] c"Error: %x:%x:%x:%x:%x:%x is a vrrp mac address\0A\00"
@str = [35 x i8] c"Error: zero is not a valid address\00"
@str.5 = [30 x i8] c"Error: wrong number of octets\00"
define i32 @validate_sys_macaddr(i8* %0) {
%2 = alloca [6 x i32]
%3 = icmp eq i8* %0, null
br i1 %3, label %59, label %4
4: ; preds = %1
%5 = tail call i32 @validate_macaddr(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %59, label %7
7: ; preds = %4
%8 = bitcast [6 x i32]* %2 to i8*
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 1
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 2
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 3
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 4
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 5
%15 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14)
%16 = icmp eq i32 %15, 6
br i1 %16, label %19, label %17
17: ; preds = %7
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
br label %57
19: ; preds = %7
%20 = load i32, i32* %9
%21 = and i32 %20, 1
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = load i32, i32* %13
%28 = load i32, i32* %14
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %24, i32 %25, i32 %26, i32 %27, i32 %28)
br label %57
30: ; preds = %19
%31 = icmp eq i32 %20, 0
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, 0
%34 = select i1 %31, i1 %33, i1 false
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 94
%37 = select i1 %34, i1 %36, i1 false
%38 = load i32, i32* %12
%39 = icmp eq i32 %38, 0
%40 = select i1 %37, i1 %39, i1 false
%41 = load i32, i32* %13
%42 = icmp eq i32 %41, 1
%43 = select i1 %40, i1 %42, i1 false
br i1 %43, label %52, label %44
44: ; preds = %30
%45 = add nsw i32 %32, %20
%46 = add nsw i32 %35, %45
%47 = add nsw i32 %38, %46
%48 = add nsw i32 %41, %47
%49 = load i32, i32* %14
%50 = sub i32 0, %48
%51 = icmp eq i32 %49, %50
br i1 %51, label %55, label %57
52: ; preds = %30
%53 = load i32, i32* %14
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0, i32 94, i32 0, i32 1, i32 %53)
br label %57
55: ; preds = %44
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %57
57: ; preds = %55, %44, %52, %23, %17
%58 = phi i32 [ 0, %17 ], [ 0, %23 ], [ 0, %52 ], [ 0, %55 ], [ 1, %44 ]
br label %59
59: ; preds = %4, %1, %57
%60 = phi i32 [ %58, %57 ], [ 0, %1 ], [ 0, %4 ]
ret i32 %60
}