#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 */
int ETHER_ADDR_LEN;
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
scalar_t__ strtoul(char *, char **, int);
int ether_atoe(const char *a, unsigned char *e) {
  char *c = (char *)a;
  int i = 0;
  memset(e, 0, ETHER_ADDR_LEN);
  for (;;) {
    e[i++] = (unsigned char)strtoul(c, &c, 16);
    if (!*c++ || i == ETHER_ADDR_LEN)
      break;
  }
  return (i == ETHER_ADDR_LEN);
}


x86 assembly (clang, -O0):
<ether_atoe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
je     11a6 <ether_atoe+0x86>
mov    -0x1c(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
jne    11ab <ether_atoe+0x8b>
jmp    11b0 <ether_atoe+0x90>
jmp    1153 <ether_atoe+0x33>
mov    -0x1c(%rbp),%eax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ether_atoe>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rdi,0x8(%rsp)
mov    0x2eb1(%rip),%r12
mov    (%r12),%edx
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0x1,%eax
lea    0x8(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,-0x1(%r14,%rbx,1)
mov    0x8(%rsp),%rax
lea    0x1(%rax),%r13
mov    %r13,0x8(%rsp)
cmpb   $0x0,(%rax)
mov    (%r12),%ecx
je     1198 <ether_atoe+0x78>
lea    0x1(%rbx),%rax
cmp    %rcx,%rbx
jne    1160 <ether_atoe+0x40>
xor    %eax,%eax
cmp    %rcx,%rbx
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ETHER_ADDR_LEN = global i32 0
define i32 @ether_atoe(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* @ETHER_ADDR_LEN
%10 = call i32 @memset(i8* %8, i32 0, i32 %9)
br label %11
11: ; preds = %29, %2
%12 = load i8*, i8** %5
%13 = call i64 @strtoul(i8* %12, i8** %5, i32 16)
%14 = trunc i64 %13 to i8
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 %14, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8, i8* %20
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %11
%25 = load i32, i32* %6
%26 = load i32, i32* @ETHER_ADDR_LEN
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24, %11
br label %30
29: ; preds = %24
br label %11
30: ; preds = %28
%31 = load i32, i32* %6
%32 = load i32, i32* @ETHER_ADDR_LEN
%33 = icmp eq i32 %31, %32
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
@ETHER_ADDR_LEN = global i32 0
define i32 @ether_atoe(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = load i32, i32* @ETHER_ADDR_LEN
%6 = tail call i32 @memset(i8* %1, i32 0, i32 %5)
br label %7
7: ; preds = %7, %2
%8 = phi i8* [ %15, %7 ], [ %0, %2 ]
%9 = phi i64 [ %12, %7 ], [ 0, %2 ]
%10 = call i64 @strtoul(i8* %8, i8** %3, i32 16)
%11 = trunc i64 %10 to i8
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %11, i8* %13
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %3
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
%18 = load i32, i32* @ETHER_ADDR_LEN
%19 = zext i32 %18 to i64
%20 = icmp eq i64 %12, %19
%21 = select i1 %17, i1 true, i1 %20
br i1 %21, label %22, label %7
22: ; preds = %7
%23 = zext i1 %20 to i32
ret i32 %23
}