#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__ {
  scalar_t__ sa_family;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
};

/* Variables and functions */
scalar_t__ ARPHRD_ETHER;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
char *strerror(int /*<<< orphan*/);
void get_ifr_hwaddr(int fd, struct ifreq *ifr) {
  if (ioctl(fd, SIOCGIFHWADDR, ifr) == -1) {
    die(strerror(errno));
  }
  if (ifr->ifr_hwaddr.sa_family != ARPHRD_ETHER) {
    die("Not an ethernet interface");
  }
}


x86 assembly (clang, -O0):
<get_ifr_hwaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1173 <get_ifr_hwaddr+0x43>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdi
call   1040 <die@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     1196 <get_ifr_hwaddr+0x66>
lea    0xe6f(%rip),%rdi
call   1040 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ifr_hwaddr>:
push   %rbx
mov    %rsi,%rbx
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1160 <get_ifr_hwaddr+0x30>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdi
call   1040 <die@plt>
mov    (%rbx),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    1171 <get_ifr_hwaddr+0x41>
pop    %rbx
ret
lea    0xe88(%rip),%rdi
pop    %rbx
jmp    1040 <die@plt>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@SIOCGIFHWADDR = global i32 0
@errno = global i32 0
@ARPHRD_ETHER = global i64 0
@.str = [26 x i8] c"Not an ethernet interface\00"
define void @get_ifr_hwaddr(i32 %0, %struct.ifreq* %1) {
%3 = alloca i32
%4 = alloca %struct.ifreq*
store i32 %0, i32* %3
store %struct.ifreq* %1, %struct.ifreq** %4
%5 = load i32, i32* %3
%6 = load i32, i32* @SIOCGIFHWADDR
%7 = load %struct.ifreq*, %struct.ifreq** %4
%8 = call i32 @ioctl(i32 %5, i32 %6, %struct.ifreq* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @die(i8* %12)
br label %14
14: ; preds = %10, %2
%15 = load %struct.ifreq*, %struct.ifreq** %4
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @ARPHRD_ETHER
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@SIOCGIFHWADDR = global i32 0
@errno = global i32 0
@ARPHRD_ETHER = global i64 0
@.str = [26 x i8] c"Not an ethernet interface\00"
define void @get_ifr_hwaddr(i32 %0, %struct.ifreq* %1) {
%3 = load i32, i32* @SIOCGIFHWADDR
%4 = tail call i32 @ioctl(i32 %0, i32 %3, %struct.ifreq* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @die(i8* %8)
br label %10
10: ; preds = %6, %2
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* @ARPHRD_ETHER
%14 = icmp eq i64 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
ret void
}