#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 EINVAL;
int ETH_ALEN;
int strlen(char *);
unsigned char strtoul(char *, int /*<<< orphan*/ *, int);
int packet_parse_addr(char *str, unsigned char addr[]) {
  int i;
  char *p = str;
  if (strlen(str) != 2 * ETH_ALEN + ETH_ALEN - 1) {

    ;
    return -EINVAL;
  }
  for (i = 0; i < ETH_ALEN; ++i) {
    p = str + 2;
    *p = 0;
    addr[i] = strtoul(str, NULL, 16);
    str = p + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<packet_parse_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
mov    0x2e94(%rip),%rdx
add    (%rdx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1174 <packet_parse_addr+0x54>
xor    %eax,%eax
mov    0x2e6e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <packet_parse_addr+0xc0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
jge    11d9 <packet_parse_addr+0xb9>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <packet_parse_addr+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_parse_addr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    0x2ead(%rip),%r12
mov    (%r12),%ecx
lea    (%rcx,%rcx,2),%edx
add    $0xffffffff,%edx
cmp    %edx,%eax
jne    118b <packet_parse_addr+0x6b>
xor    %r15d,%r15d
test   %ecx,%ecx
jle    1198 <packet_parse_addr+0x78>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,0x2(%r13)
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,(%r14,%rbx,1)
add    $0x3,%r13
add    $0x1,%rbx
movslq (%r12),%rax
cmp    %rax,%rbx
jl     1160 <packet_parse_addr+0x40>
jmp    1198 <packet_parse_addr+0x78>
mov    0x2e46(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ETH_ALEN = global i32 0
@EINVAL = global i32 0
define i32 @packet_parse_addr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i32, i32* @ETH_ALEN
%12 = mul nsw i32 2, %11
%13 = load i32, i32* @ETH_ALEN
%14 = add nsw i32 %12, %13
%15 = sub nsw i32 %14, 1
%16 = icmp ne i32 %10, %15
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @EINVAL
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %41
20: ; preds = %2
store i32 0, i32* %6
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %6
%23 = load i32, i32* @ETH_ALEN
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %7
%28 = load i8*, i8** %7
store i8 0, i8* %28
%29 = load i8*, i8** %4
%30 = call zeroext i8 @strtoul(i8* %29, i32* null, i32 16)
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %4
br label %37
37: ; preds = %25
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %21
40: ; preds = %21
store i32 0, i32* %3
br label %41
41: ; preds = %40, %17
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@ETH_ALEN = global i32 0
@EINVAL = global i32 0
define i32 @packet_parse_addr(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = load i32, i32* @ETH_ALEN
%5 = mul nsw i32 %4, 3
%6 = add nsw i32 %5, -1
%7 = icmp eq i32 %3, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = icmp sgt i32 %4, 0
br i1 %9, label %13, label %24
10: ; preds = %2
%11 = load i32, i32* @EINVAL
%12 = sub nsw i32 0, %11
br label %24
13: ; preds = %8, %13
%14 = phi i64 [ %20, %13 ], [ 0, %8 ]
%15 = phi i8* [ %19, %13 ], [ %0, %8 ]
%16 = getelementptr inbounds i8, i8* %15, i64 2
store i8 0, i8* %16
%17 = tail call zeroext i8 @strtoul(i8* nocapture %15, i32* null, i32 16)
%18 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %17, i8* %18
%19 = getelementptr inbounds i8, i8* %15, i64 3
%20 = add nuw nsw i64 %14, 1
%21 = load i32, i32* @ETH_ALEN
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %13, label %24
24: ; preds = %13, %8, %10
%25 = phi i32 [ %12, %10 ], [ 0, %8 ], [ 0, %13 ]
ret i32 %25
}