#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 */
unsigned char strtol(unsigned char *, int /*<<< orphan*/ *, int);
void parser_macaddr(unsigned char *buffer, unsigned char *macaddr) {
  int start, i, idx;
  idx = i = start = 0;
  while (macaddr[i] != '\0') {
    if (macaddr[i] == ':') {
      macaddr[i] = '\0';
      buffer[idx] = strtol(&macaddr[start], NULL, 16);
      start = i + 1;
      idx++;
    }
    i++;
  }
  buffer[idx] = strtol(&macaddr[start], NULL, 16);
}


x86 assembly (clang, -O0):
<parser_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11b1 <parser_macaddr+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    11a3 <parser_macaddr+0x93>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <parser_macaddr+0x25>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser_macaddr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebp,%ebp
movabs $0x100000000,%r12
xor    %edi,%edi
xor    %r15d,%r15d
mov    %rbp,%rbx
shl    $0x20,%rbx
nopl   0x0(%rax)
add    %r12,%rbx
add    $0x1,%rbp
movzbl -0x1(%r13,%rbp,1),%eax
test   %al,%al
je     117e <parser_macaddr+0x6e>
cmp    $0x3a,%al
jne    1140 <parser_macaddr+0x30>
movb   $0x0,-0x1(%r13,%rbp,1)
add    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %r15d,%ecx
mov    %al,(%r14,%rcx,1)
add    $0x1,%r15d
sar    $0x20,%rbx
mov    %rbx,%rdi
jmp    1132 <parser_macaddr+0x22>
add    %rdi,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %r15d,%ecx
mov    %al,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @parser_macaddr(i8* nocapture writeonly %0, i8* nocapture %1) {
br label %3
3: ; preds = %13, %2
%4 = phi i64 [ %19, %13 ], [ 0, %2 ]
%5 = phi i64 [ %22, %13 ], [ 0, %2 ]
%6 = phi i32 [ %20, %13 ], [ 0, %2 ]
br label %7
7: ; preds = %3, %11
%8 = phi i64 [ %12, %11 ], [ %4, %3 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %23
i8 58, label %13
]
11: ; preds = %7
%12 = add nuw i64 %8, 1
br label %7
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 0, i8* %14
%15 = getelementptr inbounds i8, i8* %1, i64 %5
%16 = tail call zeroext i8 @strtol(i8* nocapture %15, i32* null, i32 16)
%17 = zext i32 %6 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %16, i8* %18
%19 = add nuw i64 %8, 1
%20 = add nuw nsw i32 %6, 1
%21 = shl i64 %19, 32
%22 = ashr exact i64 %21, 32
br label %3
23: ; preds = %7
%24 = getelementptr inbounds i8, i8* %1, i64 %5
%25 = tail call zeroext i8 @strtol(i8* nocapture %24, i32* null, i32 16)
%26 = zext i32 %6 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 %25, i8* %27
ret void
}