#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;
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int ll_addr_a2n(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int parse_address(const char *dev, int hatype, int halen, char *lla,
                  struct ifreq *ifr) {
  int alen;
  memset(ifr, 0, sizeof(*ifr));
  strncpy(ifr->ifr_name, dev, IFNAMSIZ);
  ifr->ifr_hwaddr.sa_family = hatype;
  alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla);
  if (alen < 0)
    return -1;
  if (alen != halen) {
    fprintf(stderr, "Wrong address (%s) length: expected %d bytes\n", lla,
            halen);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rdx
mov    $0xe,%esi
call   1060 <ll_addr_a2n@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ba <parse_address+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <parse_address+0xb5>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11ee <parse_address+0xae>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <parse_address+0xb5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%r13d
mov    %rdi,%rbp
xor    %r12d,%r12d
mov    %r8,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x8(%rbx),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rsi
call   1030 <strncpy@plt>
mov    %r13d,(%rbx)
mov    0x4(%rbx),%edi
mov    $0xe,%esi
mov    %r15,%rdx
call   1060 <ll_addr_a2n@plt>
test   %eax,%eax
js     11b7 <parse_address+0x77>
cmp    %r14d,%eax
je     11bd <parse_address+0x7d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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