#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 {
  char *ifr_name;
  TYPE_1__ ifr_hwaddr;
};
struct if_nameindex {
  scalar_t__ if_name;
  scalar_t__ if_index;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ENODEV;
int IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ if_freenameindex(struct if_nameindex *);
struct if_nameindex *if_nameindex();
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ log_debug(int, char *, char *, ...);
int /*<<< orphan*/ log_error(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char, unsigned char,
                           unsigned char);
int /*<<< orphan*/ strcasecmp(char *, char *);
int /*<<< orphan*/ strlcpy(char *, scalar_t__, int);
int net_get_netdev_from_hwaddress(char *hwaddress, char *netdev) {
  struct if_nameindex *ifni;
  struct ifreq if_hwaddr;
  int found = 0, sockfd, i = 0;
  unsigned char *hwaddr;
  char tmp_hwaddress[18];
  ifni = if_nameindex();
  if (ifni == NULL) {
    log_error("Could not match hwaddress %s to netdev. "
              "getifaddrs failed %d",
              hwaddress, errno);
    return errno;
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    log_error("Could not open socket for ioctl.");
    goto free_ifni;
  }
  for (i = 0; ifni[i].if_index && ifni[i].if_name; i++) {
    struct if_nameindex *n = &ifni[i];
    strlcpy(if_hwaddr.ifr_name, n->if_name, IFNAMSIZ);
    if (ioctl(sockfd, SIOCGIFHWADDR, &if_hwaddr) < 0) {
      log_error("Could not match %s to netdevice.", hwaddress);
      continue;
    }
    if (if_hwaddr.ifr_hwaddr.sa_family != 1)
      continue;
    hwaddr = (unsigned char *)if_hwaddr.ifr_hwaddr.sa_data;
    memset(tmp_hwaddress, 0, 18);
    sprintf(tmp_hwaddress, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", hwaddr[0],
            hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
    log_debug(4, "Found hardware address %s", tmp_hwaddress);
    if (!strcasecmp(tmp_hwaddress, hwaddress)) {
      log_debug(4, "Matches %s to %s", hwaddress, n->if_name);
      memset(netdev, 0, IFNAMSIZ);
      strlcpy(netdev, n->if_name, IFNAMSIZ);
      found = 1;
      break;
    }
  }
  close(sockfd);
free_ifni:
  if_freenameindex(ifni);
  if (!found)
    return ENODEV;
  return 0;
}


x86 assembly (clang, -O0):
<net_get_netdev_from_hwaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x0,%al
call   1090 <if_nameindex@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <net_get_netdev_from_hwaddress+0x63>
mov    -0x10(%rbp),%rsi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <log_error@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1445 <net_get_netdev_from_hwaddress+0x295>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    124c <net_get_netdev_from_hwaddress+0x9c>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <log_error@plt>
jmp    141a <net_get_netdev_from_hwaddress+0x26a>
movl   $0x0,-0x44(%rbp)
mov    -0x20(%rbp),%rcx
movslq -0x44(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rcx
xor    %eax,%eax
cmpq   $0x0,0x8(%rcx)
mov    %al,-0x79(%rbp)
je     128b <net_get_netdev_from_hwaddress+0xdb>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    129b <net_get_netdev_from_hwaddress+0xeb>
jmp    1412 <net_get_netdev_from_hwaddress+0x262>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    (%rax),%rsi
mov    0x2d08(%rip),%rax
mov    (%rax),%edx
call   10a0 <strlcpy@plt>
mov    -0x40(%rbp),%edi
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    12fd <net_get_netdev_from_hwaddress+0x14d>
mov    -0x10(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <log_error@plt>
jmp    1404 <net_get_netdev_from_hwaddress+0x254>
cmpl   $0x1,-0x30(%rbp)
je     130c <net_get_netdev_from_hwaddress+0x15c>
jmp    1404 <net_get_netdev_from_hwaddress+0x254>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    (%rax),%dl
mov    -0x50(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x50(%rbp),%rax
mov    0x2(%rax),%r8b
mov    -0x50(%rbp),%rax
mov    0x3(%rax),%r9b
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x50(%rbp),%rax
lea    0xd27(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r10b,%r10d
mov    %r10d,(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x8(%rsp)
call   10c0 <sprintf@plt>
lea    -0x70(%rbp),%rdx
mov    $0x4,%edi
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   1050 <log_debug@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    13ff <net_get_netdev_from_hwaddress+0x24f>
mov    -0x10(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    (%rax),%rcx
mov    $0x4,%edi
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   1050 <log_debug@plt>
mov    -0x18(%rbp),%rdi
mov    0x2bf7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    (%rax),%rsi
mov    0x2bdc(%rip),%rax
mov    (%rax),%edx
call   10a0 <strlcpy@plt>
movl   $0x1,-0x3c(%rbp)
jmp    1412 <net_get_netdev_from_hwaddress+0x262>
jmp    1404 <net_get_netdev_from_hwaddress+0x254>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1253 <net_get_netdev_from_hwaddress+0xa3>
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <if_freenameindex@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    143e <net_get_netdev_from_hwaddress+0x28e>
mov    0x2b84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1445 <net_get_netdev_from_hwaddress+0x295>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_get_netdev_from_hwaddress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <if_nameindex@plt>
test   %rax,%rax
je     1352 <net_get_netdev_from_hwaddress+0x1a2>
mov    %rax,%rbx
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     137e <net_get_netdev_from_hwaddress+0x1ce>
mov    %eax,%r13d
mov    %rbp,0x10(%rsp)
mov    %rbx,(%rsp)
cmpq   $0x0,0x8(%rbx)
je     1370 <net_get_netdev_from_hwaddress+0x1c0>
mov    0x2db2(%rip),%r12
mov    0x2db3(%rip),%rbp
lea    0x18(%rsp),%rbx
mov    (%rsp),%r15
mov    %r13d,0xc(%rsp)
jmp    1250 <net_get_netdev_from_hwaddress+0xa0>
nopl   (%rax)
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <log_error@plt>
cmpq   $0x0,0x18(%r15)
lea    0x10(%r15),%r15
je     1370 <net_get_netdev_from_hwaddress+0x1c0>
mov    (%r15),%rsi
test   %rsi,%rsi
je     1370 <net_get_netdev_from_hwaddress+0x1c0>
mov    0x18(%rsp),%rdi
mov    (%r12),%edx
call   10a0 <strlcpy@plt>
mov    0x0(%rbp),%esi
mov    %r13d,%edi
mov    %rbx,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1230 <net_get_netdev_from_hwaddress+0x80>
cmpl   $0x1,0x20(%rsp)
jne    1241 <net_get_netdev_from_hwaddress+0x91>
mov    0x28(%rsp),%rbx
lea    0x30(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1060 <memset@plt>
movzbl (%rbx),%edx
movzbl 0x1(%rbx),%ecx
movzbl 0x2(%rbx),%r8d
movzbl 0x3(%rbx),%r9d
movzbl 0x4(%rbx),%eax
movzbl 0x5(%rbx),%ebx
mov    %r13,%rdi
lea    0xdbf(%rip),%rsi
push   %rbx
lea    0x20(%rsp),%rbx
mov    0x14(%rsp),%r13d
push   %rax
call   10c0 <sprintf@plt>
add    $0x10,%rsp
mov    $0x4,%edi
lea    0xdc2(%rip),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1050 <log_debug@plt>
lea    0x30(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    1241 <net_get_netdev_from_hwaddress+0x91>
mov    (%r15),%rcx
lea    0xdb1(%rip),%rsi
xor    %ebx,%ebx
mov    $0x4,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <log_debug@plt>
mov    (%r12),%edx
mov    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    (%r15),%rsi
mov    (%r12),%edx
mov    %r14,%rdi
call   10a0 <strlcpy@plt>
mov    %r13d,%edi
call   1080 <close@plt>
mov    (%rsp),%rdi
call   10b0 <if_freenameindex@plt>
jmp    139d <net_get_netdev_from_hwaddress+0x1ed>
mov    0x2c67(%rip),%rbx
mov    (%rbx),%edx
lea    0xc9e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <log_error@plt>
mov    (%rbx),%ebx
jmp    139d <net_get_netdev_from_hwaddress+0x1ed>
mov    %r13d,%edi
call   1080 <close@plt>
mov    (%rsp),%rdi
jmp    138f <net_get_netdev_from_hwaddress+0x1df>
lea    0xcb8(%rip),%rdi
xor    %eax,%eax
call   1040 <log_error@plt>
mov    %rbx,%rdi
call   10b0 <if_freenameindex@plt>
mov    0x2c1d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.if_nameindex = type { i64, i64 }
%struct.ifreq = type { i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i64 }
@.str = [61 x i8] c"Could not match hwaddress %s to netdev. getifaddrs failed %d\00"
@errno = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [33 x i8] c"Could not open socket for ioctl.\00"
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [33 x i8] c"Could not match %s to netdevice.\00"
@.str.3 = [36 x i8] c"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\00"
@.str.4 = [26 x i8] c"Found hardware address %s\00"
@.str.5 = [17 x i8] c"Matches %s to %s\00"
@ENODEV = global i32 0
define i32 @net_get_netdev_from_hwaddress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.if_nameindex*
%7 = alloca %struct.ifreq
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [18 x i8]
%13 = alloca %struct.if_nameindex*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %8
store i32 0, i32* %10
%14 = call %struct.if_nameindex* (...) @if_nameindex()
store %struct.if_nameindex* %14, %struct.if_nameindex** %6
%15 = load %struct.if_nameindex*, %struct.if_nameindex** %6
%16 = icmp eq %struct.if_nameindex* %15, null
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = load i32, i32* @errno
%20 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19)
%21 = load i32, i32* @errno
store i32 %21, i32* %3
br label %137
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %129
30: ; preds = %22
store i32 0, i32* %10
br label %31
31: ; preds = %123, %30
%32 = load %struct.if_nameindex*, %struct.if_nameindex** %6
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %32, i64 %34
%36 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %31
%40 = load %struct.if_nameindex*, %struct.if_nameindex** %6
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %40, i64 %42
%44 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %43, i32 0, i32 0
%45 = load i64, i64* %44
%46 = icmp ne i64 %45, 0
br label %47
47: ; preds = %39, %31
%48 = phi i1 [ false, %31 ], [ %46, %39 ]
br i1 %48, label %49, label %126
49: ; preds = %47
%50 = load %struct.if_nameindex*, %struct.if_nameindex** %6
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %50, i64 %52
store %struct.if_nameindex* %53, %struct.if_nameindex** %13
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = load %struct.if_nameindex*, %struct.if_nameindex** %13
%57 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %56, i32 0, i32 0
%58 = load i64, i64* %57
%59 = load i32, i32* @IFNAMSIZ
%60 = call i32 @strlcpy(i8* %55, i64 %58, i32 %59)
%61 = load i32, i32* %9
%62 = load i32, i32* @SIOCGIFHWADDR
%63 = call i64 @ioctl(i32 %61, i32 %62, %struct.ifreq* %7)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %49
%66 = load i8*, i8** %4
%67 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %66)
br label %123
68: ; preds = %49
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%70 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = icmp ne i32 %71, 1
br i1 %72, label %73, label %74
73: ; preds = %68
br label %123
74: ; preds = %68
%75 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%76 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %75, i32 0, i32 1
%77 = load i64, i64* %76
%78 = inttoptr i64 %77 to i8*
store i8* %78, i8** %11
%79 = getelementptr inbounds [18 x i8], [18 x i8]* %12, i64 0, i64 0
%80 = call i32 @memset(i8* %79, i32 0, i32 18)
%81 = getelementptr inbounds [18 x i8], [18 x i8]* %12, i64 0, i64 0
%82 = load i8*, i8** %11
%83 = getelementptr inbounds i8, i8* %82, i64 0
%84 = load i8, i8* %83
%85 = load i8*, i8** %11
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8, i8* %86
%88 = load i8*, i8** %11
%89 = getelementptr inbounds i8, i8* %88, i64 2
%90 = load i8, i8* %89
%91 = load i8*, i8** %11
%92 = getelementptr inbounds i8, i8* %91, i64 3
%93 = load i8, i8* %92
%94 = load i8*, i8** %11
%95 = getelementptr inbounds i8, i8* %94, i64 4
%96 = load i8, i8* %95
%97 = load i8*, i8** %11
%98 = getelementptr inbounds i8, i8* %97, i64 5
%99 = load i8, i8* %98
%100 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %84, i8 zeroext %87, i8 zeroext %90, i8 zeroext %93, i8 zeroext %96, i8 zeroext %99)
%101 = getelementptr inbounds [18 x i8], [18 x i8]* %12, i64 0, i64 0
%102 = call i32 (i32, i8*, i8*, ...) @log_debug(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %101)
%103 = getelementptr inbounds [18 x i8], [18 x i8]* %12, i64 0, i64 0
%104 = load i8*, i8** %4
%105 = call i32 @strcasecmp(i8* %103, i8* %104)
%106 = icmp ne i32 %105, 0
br i1 %106, label %122, label %107
107: ; preds = %74
%108 = load i8*, i8** %4
%109 = load %struct.if_nameindex*, %struct.if_nameindex** %13
%110 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %109, i32 0, i32 0
%111 = load i64, i64* %110
%112 = call i32 (i32, i8*, i8*, ...) @log_debug(i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %108, i64 %111)
%113 = load i8*, i8** %5
%114 = load i32, i32* @IFNAMSIZ
%115 = call i32 @memset(i8* %113, i32 0, i32 %114)
%116 = load i8*, i8** %5
%117 = load %struct.if_nameindex*, %struct.if_nameindex** %13
%118 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %117, i32 0, i32 0
%119 = load i64, i64* %118
%120 = load i32, i32* @IFNAMSIZ
%121 = call i32 @strlcpy(i8* %116, i64 %119, i32 %120)
store i32 1, i32* %8
br label %126
122: ; preds = %74
br label %123
123: ; preds = %122, %73, %65
%124 = load i32, i32* %10
%125 = add nsw i32 %124, 1
store i32 %125, i32* %10
br label %31
126: ; preds = %107, %47
%127 = load i32, i32* %9
%128 = call i32 @close(i32 %127)
br label %129
129: ; preds = %126, %28
%130 = load %struct.if_nameindex*, %struct.if_nameindex** %6
%131 = call i32 @if_freenameindex(%struct.if_nameindex* %130)
%132 = load i32, i32* %8
%133 = icmp ne i32 %132, 0
br i1 %133, label %136, label %134
134: ; preds = %129
%135 = load i32, i32* @ENODEV
store i32 %135, i32* %3
br label %137
136: ; preds = %129
store i32 0, i32* %3
br label %137
137: ; preds = %136, %134, %17
%138 = load i32, i32* %3
ret i32 %138
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i64 }
%struct.if_nameindex = type { i64, i64 }
@.str = [61 x i8] c"Could not match hwaddress %s to netdev. getifaddrs failed %d\00"
@errno = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [33 x i8] c"Could not open socket for ioctl.\00"
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [33 x i8] c"Could not match %s to netdevice.\00"
@.str.3 = [36 x i8] c"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\00"
@.str.4 = [26 x i8] c"Found hardware address %s\00"
@.str.5 = [17 x i8] c"Matches %s to %s\00"
@ENODEV = global i32 0
define i32 @net_get_netdev_from_hwaddress(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = alloca [18 x i8]
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
%7 = tail call %struct.if_nameindex* (...) @if_nameindex()
%8 = icmp eq %struct.if_nameindex* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %10)
%12 = load i32, i32* @errno
br label %88
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %7, i64 0, i32 1
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %83, label %22
22: ; preds = %18
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1, i32 0
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1, i32 1
br label %29
26: ; preds = %13
%27 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @if_freenameindex(%struct.if_nameindex* %7)
br label %86
29: ; preds = %22, %75
%30 = phi i64 [ 0, %22 ], [ %76, %75 ]
%31 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %7, i64 %30, i32 0
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %80, label %34
34: ; preds = %29
%35 = load i8*, i8** %23
%36 = load i32, i32* @IFNAMSIZ
%37 = call i32 @strlcpy(i8* %35, i64 %32, i32 %36)
%38 = load i32, i32* @SIOCGIFHWADDR
%39 = call i64 @ioctl(i32 %16, i32 %38, %struct.ifreq* %3)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %75
43: ; preds = %34
%44 = load i32, i32* %24
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %75
46: ; preds = %43
%47 = load i64, i64* %25
%48 = inttoptr i64 %47 to i8*
%49 = call i32 @memset(i8* %6, i32 0, i32 18)
%50 = load i8, i8* %48
%51 = getelementptr inbounds i8, i8* %48, i64 1
%52 = load i8, i8* %51
%53 = getelementptr inbounds i8, i8* %48, i64 2
%54 = load i8, i8* %53
%55 = getelementptr inbounds i8, i8* %48, i64 3
%56 = load i8, i8* %55
%57 = getelementptr inbounds i8, i8* %48, i64 4
%58 = load i8, i8* %57
%59 = getelementptr inbounds i8, i8* %48, i64 5
%60 = load i8, i8* %59
%61 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %50, i8 zeroext %52, i8 zeroext %54, i8 zeroext %56, i8 zeroext %58, i8 zeroext %60)
%62 = call i32 (i32, i8*, i8*, ...) @log_debug(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%63 = call i32 @strcasecmp(i8* %6, i8* %0)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %75
65: ; preds = %46
%66 = load i64, i64* %31
%67 = call i32 (i32, i8*, i8*, ...) @log_debug(i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %0, i64 %66)
%68 = load i32, i32* @IFNAMSIZ
%69 = call i32 @memset(i8* %1, i32 0, i32 %68)
%70 = load i64, i64* %31
%71 = load i32, i32* @IFNAMSIZ
%72 = call i32 @strlcpy(i8* %1, i64 %70, i32 %71)
%73 = call i32 @close(i32 %16)
%74 = call i32 @if_freenameindex(%struct.if_nameindex* %7)
br label %88
75: ; preds = %41, %43, %46
%76 = add nuw i64 %30, 1
%77 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %7, i64 %76, i32 1
%78 = load i64, i64* %77
%79 = icmp eq i64 %78, 0
br i1 %79, label %83, label %29
80: ; preds = %29
%81 = call i32 @close(i32 %16)
%82 = call i32 @if_freenameindex(%struct.if_nameindex* %7)
br label %86
83: ; preds = %75, %18
%84 = call i32 @close(i32 %16)
%85 = call i32 @if_freenameindex(%struct.if_nameindex* %7)
br label %86
86: ; preds = %83, %80, %26
%87 = load i32, i32* @ENODEV
br label %88
88: ; preds = %65, %86, %9
%89 = phi i32 [ %12, %9 ], [ %87, %86 ], [ 0, %65 ]
ret i32 %89
}