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

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pcap_snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ pcap_strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int iface_get_arptype(int fd, const char *device, char *ebuf) {
  struct ifreq ifr;
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
  if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
    pcap_snprintf(ebuf, 256, "SIOCGIFHWADDR: %s", pcap_strerror(errno));
    return -1;
  }
  return ifr.ifr_hwaddr.sa_family;
}


x86 assembly (clang, -O0):
<iface_get_arptype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11db <iface_get_arptype+0x8b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1060 <pcap_strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe36(%rip),%rdx
call   1070 <pcap_snprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <iface_get_arptype+0x91>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iface_get_arptype>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     119f <iface_get_arptype+0x4f>
mov    (%rsp),%eax
jmp    11c8 <iface_get_arptype+0x78>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <pcap_strerror@plt>
lea    0xe4c(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1070 <pcap_snprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
@.str = [18 x i8] c"SIOCGIFHWADDR: %s\00"
@errno = global i32 0
define i32 @iface_get_arptype(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.ifreq
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = call i32 @memset(%struct.ifreq* %8, i32 0, i32 8)
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load i8*, i8** %6
%13 = call i32 @strncpy(i32 %11, i8* %12, i32 4)
%14 = load i32, i32* %5
%15 = load i32, i32* @SIOCGIFHWADDR
%16 = call i32 @ioctl(i32 %14, i32 %15, %struct.ifreq* %8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i32, i32* @errno
%21 = call i32 @pcap_strerror(i32 %20)
%22 = call i32 @pcap_snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 -1, i32* %4
br label %27
23: ; preds = %3
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = load i32, i32* %25
store i32 %26, i32* %4
br label %27
27: ; preds = %23, %18
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
@.str = [18 x i8] c"SIOCGIFHWADDR: %s\00"
@errno = global i32 0
define i32 @iface_get_arptype(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.ifreq
%5 = bitcast %struct.ifreq* %4 to i8*
%6 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 8)
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%8 = load i32, i32* %7
%9 = call i32 @strncpy(i32 %8, i8* %1, i32 4)
%10 = load i32, i32* @SIOCGIFHWADDR
%11 = call i32 @ioctl(i32 %0, i32 %10, %struct.ifreq* %4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = call i32 @pcap_strerror(i32 %14)
%16 = call i32 @pcap_snprintf(i8* %2, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %20
17: ; preds = %3
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0, i32 0
%19 = load i32, i32* %18
br label %20
20: ; preds = %17, %13
%21 = phi i32 [ -1, %13 ], [ %19, %17 ]
ret i32 %21
}