#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 ssize_t;

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *, int *, int *, int *,
           char *);
ssize_t parse_macaddr(const char *buffer,
                      __attribute__((unused)) const char **error) {
  char c;
  int num, parts[6];
  num = sscanf(buffer, "%x:%x:%x:%x:%x:%x%c", &parts[0], &parts[1], &parts[2],
               &parts[3], &parts[4], &parts[5], &c);
  if (num != 6) {
    return 0;
  }
  for (num = 0; num < 6; num++) {
    if (parts[num] < 0)
      return 0;
    if (parts[num] > 255)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x40(%rbp),%rcx
add    $0x4,%rcx
lea    -0x40(%rbp),%r8
add    $0x8,%r8
lea    -0x40(%rbp),%r9
add    $0xc,%r9
lea    -0x40(%rbp),%r11
add    $0x10,%r11
lea    -0x40(%rbp),%r10
add    $0x14,%r10
lea    0xea9(%rip),%rsi
lea    -0x19(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
je     1187 <parse_macaddr+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11eb <parse_macaddr+0xdb>
movl   $0x0,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
jge    11e4 <parse_macaddr+0xd4>
movslq -0x20(%rbp),%rax
cmpl   $0x0,-0x40(%rbp,%rax,4)
jge    11b3 <parse_macaddr+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    11eb <parse_macaddr+0xdb>
movslq -0x20(%rbp),%rax
cmpl   $0xff,-0x40(%rbp,%rax,4)
jle    11d1 <parse_macaddr+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    11eb <parse_macaddr+0xdb>
jmp    11d6 <parse_macaddr+0xc6>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118e <parse_macaddr+0x7e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_macaddr>:
sub    $0x28,%rsp
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x20(%rsp),%r10
lea    0x24(%rsp),%r11
sub    $0x8,%rsp
lea    0x17(%rsp),%rax
lea    0xec3(%rip),%rsi
lea    0x18(%rsp),%rdx
push   %rax
push   %r11
push   %r10
call   1030 <sscanf@plt>
add    $0x20,%rsp
cmp    $0x6,%eax
sete   %al
cmpl   $0x100,0x10(%rsp)
setb   %cl
and    %al,%cl
cmpl   $0x100,0x14(%rsp)
setb   %al
cmpl   $0x100,0x18(%rsp)
setb   %dl
and    %al,%dl
and    %cl,%dl
cmpl   $0x100,0x1c(%rsp)
setb   %al
cmpl   $0x100,0x20(%rsp)
setb   %cl
and    %al,%cl
cmpl   $0x100,0x24(%rsp)
setb   %al
and    %cl,%al
and    %dl,%al
movzbl %al,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"%x:%x:%x:%x:%x:%x%c\00"
define i32 @parse_macaddr(i8* nocapture %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca [6 x i32]
%5 = bitcast [6 x i32]* %4 to i8*
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i8* %3)
%13 = icmp eq i32 %12, 6
%14 = load i32, i32* %6
%15 = icmp ult i32 %14, 256
%16 = select i1 %13, i1 %15, i1 false
%17 = load i32, i32* %7
%18 = icmp ult i32 %17, 256
%19 = select i1 %16, i1 %18, i1 false
%20 = load i32, i32* %8
%21 = icmp ult i32 %20, 256
%22 = select i1 %19, i1 %21, i1 false
%23 = load i32, i32* %9
%24 = icmp ult i32 %23, 256
%25 = select i1 %22, i1 %24, i1 false
%26 = load i32, i32* %10
%27 = icmp ult i32 %26, 256
%28 = select i1 %25, i1 %27, i1 false
%29 = load i32, i32* %11
%30 = icmp ult i32 %29, 256
%31 = select i1 %28, i1 %30, i1 false
%32 = zext i1 %31 to i32
ret i32 %32
}