#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 u_int;
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
scalar_t__ isxdigit(char const);
scalar_t__ malloc(int);
int xdtoi(int /*<<< orphan*/);
u_char *pcap_ether_aton(const char *s) {
  register u_char *ep, *e;
  register u_int d;
  e = ep = (u_char *)malloc(6);
  while (*s) {
    if (*s == ':')
      s += 1;
    d = xdtoi(*s++);
    if (isxdigit(*s)) {
      d <<= 4;
      d |= xdtoi(*s++);
    }
    *ep++ = d;
  }
  return (e);
}


x86 assembly (clang, -O0):
<pcap_ether_aton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e6 <pcap_ether_aton+0xb6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1177 <pcap_ether_aton+0x47>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <xdtoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
je     11cd <pcap_ether_aton+0x9d>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <xdtoi@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
jmp    114e <pcap_ether_aton+0x1e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcap_ether_aton>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%r15
jmp    1169 <pcap_ether_aton+0x39>
nopl   0x0(%rax)
shl    $0x4,%ebp
movsbl 0x1(%rbx),%edi
add    $0x2,%rbx
call   1030 <xdtoi@plt>
or     %eax,%ebp
mov    %ebp,(%r15)
add    $0x4,%r15
movzbl (%rbx),%eax
cmp    $0x3a,%al
je     1180 <pcap_ether_aton+0x50>
test   %al,%al
jne    1188 <pcap_ether_aton+0x58>
jmp    11a6 <pcap_ether_aton+0x76>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
movsbl %al,%edi
call   1030 <xdtoi@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
jne    1150 <pcap_ether_aton+0x20>
add    $0x1,%rbx
jmp    1162 <pcap_ether_aton+0x32>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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