#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 */
scalar_t__ is_hex(char *);
int /*<<< orphan*/ isxdigit(char);
int strlen(char *);
short int is_macaddr(char *str) {
  char *ch;
  int len;
  if (is_hex(str))
    return 1;
  len = strlen(str);
  if (len != 17)
    return 0;
  ch = str;
  while (len) {
    if (len % 3) {
      if (!isxdigit(*ch))
        return 0;
    } else {
      if (*ch != ':')
        return 0;
    }
    ch++;
    len--;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_hex@plt>
cmp    $0x0,%rax
je     115a <is_macaddr+0x2a>
movw   $0x1,-0x2(%rbp)
jmp    1206 <is_macaddr+0xd6>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x11,-0x1c(%rbp)
je     117b <is_macaddr+0x4b>
movw   $0x0,-0x2(%rbp)
jmp    1206 <is_macaddr+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1200 <is_macaddr+0xd0>
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11c6 <is_macaddr+0x96>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
jne    11c1 <is_macaddr+0x91>
movw   $0x0,-0x2(%rbp)
jmp    1206 <is_macaddr+0xd6>
jmp    11e6 <is_macaddr+0xb6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11e1 <is_macaddr+0xb1>
movw   $0x0,-0x2(%rbp)
jmp    1206 <is_macaddr+0xd6>
jmp    11e6 <is_macaddr+0xb6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <is_macaddr+0x53>
movw   $0x1,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_macaddr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <is_hex@plt>
mov    $0x1,%r14w
test   %rax,%rax
jne    11aa <is_macaddr+0x7a>
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0x11,%eax
jne    11a7 <is_macaddr+0x77>
mov    $0x11,%r12d
mov    $0xffffffef,%ebx
xor    %ebp,%ebp
mov    $0xaaaaaaab,%r13d
jmp    1184 <is_macaddr+0x54>
nop
cmp    $0x3a,%al
jne    11a7 <is_macaddr+0x77>
add    $0xffffffff,%r12d
add    $0x1,%ebx
add    $0x1,%rbp
cmp    $0x11,%ebp
je     11aa <is_macaddr+0x7a>
mov    %r12d,%eax
imul   %r13,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%ecx
movzbl (%r15,%rbp,1),%eax
add    %ebx,%ecx
je     1170 <is_macaddr+0x40>
movsbl %al,%edi
call   1050 <isxdigit@plt>
test   %eax,%eax
jne    1174 <is_macaddr+0x44>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @is_macaddr(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @is_hex(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i16 1, i16* %2
br label %45
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 17
br i1 %14, label %15, label %16
15: ; preds = %10
store i16 0, i16* %2
br label %45
16: ; preds = %10
%17 = load i8*, i8** %3
store i8* %17, i8** %4
br label %18
18: ; preds = %39, %16
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %18
%22 = load i32, i32* %5
%23 = srem i32 %22, 3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = call i32 @isxdigit(i8 signext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store i16 0, i16* %2
br label %45
31: ; preds = %25
br label %39
32: ; preds = %21
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 58
br i1 %36, label %37, label %38
37: ; preds = %32
store i16 0, i16* %2
br label %45
38: ; preds = %32
br label %39
39: ; preds = %38, %31
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %18
44: ; preds = %18
store i16 1, i16* %2
br label %45
45: ; preds = %44, %37, %30, %15, %9
%46 = load i16, i16* %2
ret i16 %46
}

LLVM IR (-O2):
define signext i16 @is_macaddr(i8* %0) {
%2 = tail call i64 @is_hex(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 17
br i1 %6, label %7, label %22
7: ; preds = %4, %18
%8 = phi i32 [ %20, %18 ], [ 17, %4 ]
%9 = phi i8* [ %19, %18 ], [ %0, %4 ]
%10 = urem i32 %8, 3
%11 = icmp eq i32 %10, 0
%12 = load i8, i8* %9
br i1 %11, label %16, label %13
13: ; preds = %7
%14 = tail call i32 @isxdigit(i8 signext %12)
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %18
16: ; preds = %7
%17 = icmp eq i8 %12, 58
br i1 %17, label %18, label %22
18: ; preds = %16, %13
%19 = getelementptr inbounds i8, i8* %9, i64 1
%20 = add nsw i32 %8, -1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %7
22: ; preds = %18, %16, %13, %4, %1
%23 = phi i16 [ 1, %1 ], [ 0, %4 ], [ 1, %18 ], [ 0, %16 ], [ 0, %13 ]
ret i16 %23
}