#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*/ 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*/ strcpy(int /*<<< orphan*/, char *);
int parse_address(char *dev, int hatype, int halen, char *lla,
                  struct ifreq *ifr) {
  int alen;
  memset(ifr, 0, sizeof(*ifr));
  strcpy(ifr->ifr_name, dev);
  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
call   1030 <strcpy@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    11b1 <parse_address+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <parse_address+0xac>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e5 <parse_address+0xa5>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <parse_address+0xac>
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    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r13d,(%rbx)
mov    0x4(%rbx),%edi
mov    $0xe,%esi
mov    %r15,%rdx
call   1060 <ll_addr_a2n@plt>
test   %eax,%eax
js     11ae <parse_address+0x6e>
cmp    %r14d,%eax
je     11b4 <parse_address+0x74>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%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 }
@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 = call i32 @strcpy(i32 %17, i8* %18)
%20 = load i32, i32* %8
%21 = load %struct.ifreq*, %struct.ifreq** %11
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %20, i32* %23
%24 = load %struct.ifreq*, %struct.ifreq** %11
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i8*, i8** %10
%29 = call i32 @ll_addr_a2n(i32 %27, i32 14, i8* %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %5
store i32 -1, i32* %6
br label %43
33: ; preds = %5
%34 = load i32, i32* %12
%35 = load i32, i32* %9
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %10
%40 = load i32, i32* %9
%41 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %39, i32 %40)
store i32 -1, i32* %6
br label %43
42: ; preds = %33
store i32 0, i32* %6
br label %43
43: ; preds = %42, %37, %32
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@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 = tail call i32 @strcpy(i32 %8, i8* %0)
%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 i32, i32* %11
%13 = tail call i32 @ll_addr_a2n(i32 %12, i32 14, i8* %3)
%14 = icmp slt i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %5
%16 = icmp eq i32 %13, %2
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %2)
br label %20
20: ; preds = %15, %5, %17
%21 = phi i32 [ -1, %17 ], [ -1, %5 ], [ 0, %15 ]
ret i32 %21
}