#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__ isxdigit(char const);
scalar_t__ scan_fromhex(char const);
unsigned scan_mac(const char *s, char mac[6]) {
  const char *tmp = s;
  unsigned len = 0;
  unsigned pos = 0;
  while (isxdigit(*tmp)) {
    mac[pos] =
        ((char)scan_fromhex(*tmp)) << 4 | ((char)scan_fromhex(*(tmp + 1)));
    ++pos;
    ++len;
    tmp += 2;
    if (*tmp == ':' || *tmp == '-' || *tmp == '.')
      ++tmp;
  }
  return len;
}


x86 assembly (clang, -O0):
<scan_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%rax
je     11f4 <scan_mac+0xd4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <scan_fromhex@plt>
movsbl %al,%eax
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <scan_fromhex@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
movsbl %cl,%ecx
or     %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11e3 <scan_mac+0xc3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11e3 <scan_mac+0xc3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ef <scan_mac+0xcf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <scan_mac+0x26>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_mac>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <isxdigit@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11a7 <scan_mac+0x87>
movabs $0x400600000000000,%r12
jmp    1164 <scan_mac+0x44>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isxdigit@plt>
add    $0x1,%r15d
mov    %rbp,%rbx
test   %rax,%rax
je     11a7 <scan_mac+0x87>
movsbl (%rbx),%edi
call   1030 <scan_fromhex@plt>
mov    %rax,%rbp
shl    $0x4,%bpl
movsbl 0x1(%rbx),%edi
call   1030 <scan_fromhex@plt>
or     %bpl,%al
mov    %r15d,%ecx
mov    %al,(%r14,%rcx,1)
lea    0x2(%rbx),%rbp
movzbl 0x2(%rbx),%eax
cmp    $0x3a,%rax
ja     1150 <scan_mac+0x30>
bt     %rax,%r12
jae    1150 <scan_mac+0x30>
movzbl 0x3(%rbx),%eax
add    $0x3,%rbx
mov    %rbx,%rbp
jmp    1150 <scan_mac+0x30>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scan_mac(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %56, %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = call i64 @isxdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %57
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = call i64 @scan_fromhex(i8 signext %16)
%18 = trunc i64 %17 to i8
%19 = sext i8 %18 to i32
%20 = shl i32 %19, 4
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = call i64 @scan_fromhex(i8 signext %23)
%25 = trunc i64 %24 to i8
%26 = sext i8 %25 to i32
%27 = or i32 %20, %26
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %4
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
%33 = load i32, i32* %7
%34 = add i32 %33, 1
store i32 %34, i32* %7
%35 = load i32, i32* %6
%36 = add i32 %35, 1
store i32 %36, i32* %6
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 58
br i1 %42, label %53, label %43
43: ; preds = %14
%44 = load i8*, i8** %5
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 45
br i1 %47, label %53, label %48
48: ; preds = %43
%49 = load i8*, i8** %5
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 46
br i1 %52, label %53, label %56
53: ; preds = %48, %43, %14
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
br label %56
56: ; preds = %53, %48
br label %9
57: ; preds = %9
%58 = load i32, i32* %6
ret i32 %58
}

LLVM IR (-O2):
define i32 @scan_mac(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @isxdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %2, %26
%7 = phi i32 [ %20, %26 ], [ 0, %2 ]
%8 = phi i8* [ %28, %26 ], [ %0, %2 ]
%9 = load i8, i8* %8
%10 = tail call i64 @scan_fromhex(i8 signext %9)
%11 = trunc i64 %10 to i8
%12 = shl i8 %11, 4
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = load i8, i8* %13
%15 = tail call i64 @scan_fromhex(i8 signext %14)
%16 = trunc i64 %15 to i8
%17 = or i8 %12, %16
%18 = zext i32 %7 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %17, i8* %19
%20 = add i32 %7, 1
%21 = getelementptr inbounds i8, i8* %8, i64 2
%22 = load i8, i8* %21
switch i8 %22, label %26 [
i8 58, label %23
i8 45, label %23
i8 46, label %23
]
23: ; preds = %6, %6, %6
%24 = getelementptr inbounds i8, i8* %8, i64 3
%25 = load i8, i8* %24
br label %26
26: ; preds = %6, %23
%27 = phi i8 [ %25, %23 ], [ %22, %6 ]
%28 = phi i8* [ %24, %23 ], [ %21, %6 ]
%29 = tail call i64 @isxdigit(i8 signext %27)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %6
31: ; preds = %26, %2
%32 = phi i32 [ 0, %2 ], [ %20, %26 ]
ret i32 %32
}