#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int sa_family;
  scalar_t__ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ bb_error_msg_and_die(char *, char *, int);
int /*<<< orphan*/ exit(int);
int ll_addr_a2n(unsigned char *, int, char *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
void parse_address(char *dev, int hatype, int halen, char *lla,
                   struct ifreq *ifr) {
  int alen;
  memset(ifr, 0, sizeof(*ifr));
  strncpy(ifr->ifr_name, dev, sizeof(ifr->ifr_name));
  ifr->ifr_hwaddr.sa_family = hatype;
  alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), 14, lla);
  if (alen < 0)
    exit(1);
  if (alen != halen) {
    bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla,
                         halen);
  }
}


x86 assembly (clang, -O0):
<parse_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xe,%esi
call   1050 <ll_addr_a2n@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c5 <parse_address+0x75>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11e4 <parse_address+0x94>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe21(%rip),%rdi
call   1060 <bb_error_msg_and_die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%rbp
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %r8,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x10(%rbp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r12d,0x0(%rbp)
mov    0x8(%rbp),%rdi
mov    $0xe,%esi
mov    %r15,%rdx
call   1050 <ll_addr_a2n@plt>
test   %eax,%eax
js     11c7 <parse_address+0x77>
cmp    %r14d,%eax
jne    11ad <parse_address+0x5d>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <bb_error_msg_and_die@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i64 }
@.str = [45 x i8] c"wrong address (%s) length: expected %d bytes\00"
define void @parse_address(i8* %0, i32 %1, i32 %2, i8* %3, %struct.ifreq* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.ifreq*
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store %struct.ifreq* %4, %struct.ifreq** %10
%12 = load %struct.ifreq*, %struct.ifreq** %10
%13 = call i32 @memset(%struct.ifreq* %12, i32 0, i32 24)
%14 = load %struct.ifreq*, %struct.ifreq** %10
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load i8*, i8** %6
%18 = call i32 @strncpy(i32 %16, i8* %17, i32 4)
%19 = load i32, i32* %7
%20 = load %struct.ifreq*, %struct.ifreq** %10
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = load %struct.ifreq*, %struct.ifreq** %10
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to i8*
%28 = load i8*, i8** %9
%29 = call i32 @ll_addr_a2n(i8* %27, i32 14, i8* %28)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %5
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %5
%35 = load i32, i32* %11
%36 = load i32, i32* %8
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8*, i8** %9
%40 = load i32, i32* %8
%41 = call i32 @bb_error_msg_and_die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %39, i32 %40)
br label %42
42: ; preds = %38, %34
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i64 }
@.str = [45 x i8] c"wrong address (%s) length: expected %d bytes\00"
define void @parse_address(i8* %0, i32 %1, i32 %2, i8* %3, %struct.ifreq* %4) {
%6 = tail call i32 @memset(%struct.ifreq* %4, i32 0, i32 24)
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i32 @strncpy(i32 %8, i8* %0, i32 4)
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0, i32 0
store i32 %1, i32* %10
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0, i32 1
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @ll_addr_a2n(i8* %13, i32 14, i8* %3)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %5
%19 = icmp eq i32 %14, %2
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = tail call i32 @bb_error_msg_and_die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %2)
br label %22
22: ; preds = %20, %18
ret void
}