#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 */

/* Type definitions */
struct ifreq {
  char *ifr_name;
  int ifr_flags;
};
struct ifconf {
  unsigned int ifc_len;
  char *ifc_buf;
};
typedef int /*<<< orphan*/ device;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINVAL;
scalar_t__ ENXIO;
int IFF_UP;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(scalar_t__);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *utils_malloc(unsigned int);
char *generic_lookupdev(char **errbuf) {
  register int fd, minunit, n;
  register char *cp;
  register struct ifreq *ifrp, *ifend, *ifnext, *mp;
  struct ifconf ifc;
  char *buf;
  struct ifreq ifr;
  static char device[sizeof(ifrp->ifr_name) + 1];
  unsigned buf_size;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd < 0) {
    *errbuf = strerror(errno);
    return NULL;
  }
  buf_size = 8192;
  for (;;) {
    buf = utils_malloc(buf_size);
    if (buf == NULL) {
      close(fd);
      *errbuf = "out of memory";
      return NULL;
    }
    ifc.ifc_len = buf_size;
    ifc.ifc_buf = buf;
    memset(buf, 0, buf_size);
    if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 && errno != EINVAL) {
      free(buf);
      *errbuf = strerror(errno);
      close(fd);
      return NULL;
    }
    if (ifc.ifc_len < buf_size)
      break;
    free(buf);
    buf_size *= 2;
  }
  ifrp = (struct ifreq *)buf;
  ifend = (struct ifreq *)(buf + ifc.ifc_len);
  mp = NULL;
  minunit = 666;
  for (; ifrp < ifend; ifrp = ifnext) {
    const char *endcp;
    ifnext = ifrp + 1;
    strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
    if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
      if (errno == ENXIO)
        continue;
      *errbuf = strerror(errno);
      close(fd);
      free(buf);
      return NULL;
    }
    if ((ifr.ifr_flags & IFF_UP) == 0 ||
        ((&ifr)->ifr_name[0] == 'l' && (&ifr)->ifr_name[1] == 'o' &&
         (isdigit((&ifr)->ifr_name[2]) || (&ifr)->ifr_name[2] == '\0')))
      continue;
    endcp = ifrp->ifr_name + strlen(ifrp->ifr_name);
    for (cp = ifrp->ifr_name; cp < endcp && !isdigit(*cp); ++cp)
      continue;
    if (isdigit(*cp)) {
      n = atoi(cp);
    } else {
      n = 0;
    }
    if (n < minunit) {
      minunit = n;
      mp = ifrp;
    }
  }
  (void)close(fd);
  if (mp == NULL) {
    *errbuf = strerror(errno);
    free(buf);
    return NULL;
  }
  (strncpy((device), (mp->ifr_name), (sizeof(device))),
   ((sizeof(device)) <= 0 ? 0 : ((device)[(sizeof(device)) - 1] = '\0')),
   strlen((mp->ifr_name)));
  free(buf);
  return (device);
}


x86 assembly (clang, -O0):
<generic_lookupdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120b <generic_lookupdev+0x5b>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1599 <generic_lookupdev+0x3e9>
movl   $0x2000,-0x74(%rbp)
mov    -0x74(%rbp),%edi
call   10a0 <utils_malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    124c <generic_lookupdev+0x9c>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x10(%rbp),%rax
lea    0xdc4(%rip),%rcx
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1599 <generic_lookupdev+0x3e9>
mov    -0x74(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x74(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
jge    12d8 <generic_lookupdev+0x128>
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%rax
je     12d8 <generic_lookupdev+0x128>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1599 <generic_lookupdev+0x3e9>
mov    -0x58(%rbp),%eax
cmp    -0x74(%rbp),%eax
jae    12e9 <generic_lookupdev+0x139>
jmp    1300 <generic_lookupdev+0x150>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x74(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1212 <generic_lookupdev+0x62>
mov    -0x60(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x58(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x29a,-0x18(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1518 <generic_lookupdev+0x368>
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x40(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2c72(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
jge    13c9 <generic_lookupdev+0x219>
mov    0x2c46(%rip),%rax
mov    (%rax),%rax
mov    0x2c34(%rip),%rcx
cmp    (%rcx),%rax
jne    1392 <generic_lookupdev+0x1e2>
jmp    150b <generic_lookupdev+0x35b>
mov    0x2c27(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1599 <generic_lookupdev+0x3e9>
mov    -0x68(%rbp),%eax
mov    0x2c0d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1427 <generic_lookupdev+0x277>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6c,%eax
jne    142c <generic_lookupdev+0x27c>
mov    -0x70(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6f,%eax
jne    142c <generic_lookupdev+0x27c>
mov    -0x70(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%rax
jne    1427 <generic_lookupdev+0x277>
mov    -0x70(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    142c <generic_lookupdev+0x27c>
jmp    150b <generic_lookupdev+0x35b>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x80(%rbp),%rcx
mov    %al,-0x89(%rbp)
jae    1495 <generic_lookupdev+0x2e5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    14a8 <generic_lookupdev+0x2f8>
jmp    14be <generic_lookupdev+0x30e>
jmp    14ad <generic_lookupdev+0x2fd>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1464 <generic_lookupdev+0x2b4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%rax
je     14e5 <generic_lookupdev+0x335>
mov    -0x28(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    14ec <generic_lookupdev+0x33c>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1506 <generic_lookupdev+0x356>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    150b <generic_lookupdev+0x35b>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1325 <generic_lookupdev+0x175>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
cmpq   $0x0,-0x48(%rbp)
jne    155a <generic_lookupdev+0x3aa>
mov    0x2a8e(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1599 <generic_lookupdev+0x3e9>
mov    -0x48(%rbp),%rax
mov    (%rax),%rsi
lea    0x2b18(%rip),%rdi
mov    $0x9,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x2b0f(%rip)
mov    -0x48(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
lea    0x2aeb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_lookupdev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     1291 <generic_lookupdev+0xe1>
mov    %eax,%r12d
mov    %rbx,0x8(%rsp)
mov    $0x2000,%ebp
mov    $0x2000,%edi
call   10a0 <utils_malloc@plt>
test   %rax,%rax
je     1275 <generic_lookupdev+0xc5>
mov    %rax,%rbx
mov    0x2da0(%rip),%r14
lea    0x28(%rsp),%r15
nopl   (%rax)
mov    %ebp,0x28(%rsp)
mov    %rbx,0x30(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
mov    (%r14),%esi
mov    %r12d,%edi
mov    %r15,%rdx
call   1080 <ioctl@plt>
test   %rax,%rax
jns    1252 <generic_lookupdev+0xa2>
mov    0x2d81(%rip),%rax
mov    (%rax),%rax
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%rax
jne    1415 <generic_lookupdev+0x265>
mov    0x28(%rsp),%r13d
cmp    %ebp,%r13d
jb     12a8 <generic_lookupdev+0xf8>
mov    %rbx,%rdi
call   1030 <free@plt>
add    %ebp,%ebp
mov    %ebp,%edi
call   10a0 <utils_malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <generic_lookupdev+0x60>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xd7c(%rip),%rax
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
jmp    147c <generic_lookupdev+0x2cc>
mov    0x2d28(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,(%rbx)
jmp    147c <generic_lookupdev+0x2cc>
test   %r13,%r13
je     143e <generic_lookupdev+0x28e>
add    %rbx,%r13
mov    $0x29a,%ebp
xor    %r15d,%r15d
mov    %rbx,%r14
jmp    12f7 <generic_lookupdev+0x147>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2ce9(%rip),%rax
mov    (%rax),%rdi
mov    0x2cd7(%rip),%rax
cmp    (%rax),%rdi
jne    145f <generic_lookupdev+0x2af>
add    $0x10,%r14
cmp    %r13,%r14
jae    13d8 <generic_lookupdev+0x228>
mov    0x18(%rsp),%rdi
mov    (%r14),%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
lea    0x18(%rsp),%rdx
call   1080 <ioctl@plt>
test   %rax,%rax
js     12d0 <generic_lookupdev+0x120>
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
test   %eax,0x20(%rsp)
je     12ea <generic_lookupdev+0x13a>
mov    0x18(%rsp),%rax
cmpb   $0x6c,(%rax)
jne    1360 <generic_lookupdev+0x1b0>
cmpb   $0x6f,0x1(%rax)
jne    1360 <generic_lookupdev+0x1b0>
movsbl 0x2(%rax),%edi
call   1050 <isdigit@plt>
test   %rax,%rax
jne    12ea <generic_lookupdev+0x13a>
mov    0x18(%rsp),%rax
cmpb   $0x0,0x2(%rax)
je     12ea <generic_lookupdev+0x13a>
nopl   0x0(%rax)
mov    %ebp,0x4(%rsp)
mov    %r15,0x10(%rsp)
mov    (%r14),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
movslq %eax,%r15
add    %rbp,%r15
mov    (%r14),%rbp
cmp    %r15,%rbp
jae    13a7 <generic_lookupdev+0x1f7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x0(%rbp),%edi
call   1050 <isdigit@plt>
test   %rax,%rax
jne    13a7 <generic_lookupdev+0x1f7>
add    $0x1,%rbp
cmp    %r15,%rbp
jb     1390 <generic_lookupdev+0x1e0>
movsbl 0x0(%rbp),%edi
call   1050 <isdigit@plt>
test   %rax,%rax
je     13bf <generic_lookupdev+0x20f>
mov    %rbp,%rdi
call   10b0 <atoi@plt>
jmp    13c1 <generic_lookupdev+0x211>
xor    %eax,%eax
mov    0x10(%rsp),%r15
mov    0x4(%rsp),%ebp
cmp    %ebp,%eax
cmovl  %r14,%r15
cmovl  %eax,%ebp
jmp    12ea <generic_lookupdev+0x13a>
mov    %r12d,%edi
call   1090 <close@plt>
test   %r15,%r15
je     1446 <generic_lookupdev+0x296>
mov    (%r15),%rsi
lea    0x2c91(%rip),%rbp
mov    %rbp,%rdi
mov    $0x9,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x2c85(%rip)
mov    (%r15),%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    147e <generic_lookupdev+0x2ce>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12d,%edi
call   1090 <close@plt>
jmp    147c <generic_lookupdev+0x2cc>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x2b73(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
jmp    1474 <generic_lookupdev+0x2c4>
call   10c0 <strerror@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12d,%edi
call   1090 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32 }
%struct.ifconf = type { i32, i8* }
@generic_lookupdev.device = internal global [9 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@.str = [14 x i8] c"out of memory\00"
@SIOCGIFCONF = global i32 0
@EINVAL = global i64 0
@SIOCGIFFLAGS = global i32 0
@ENXIO = global i64 0
@IFF_UP = global i32 0
define i8* @generic_lookupdev(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.ifreq*
%9 = alloca %struct.ifreq*
%10 = alloca %struct.ifreq*
%11 = alloca %struct.ifreq*
%12 = alloca %struct.ifconf
%13 = alloca i8*
%14 = alloca %struct.ifreq
%15 = alloca i32
%16 = alloca i8*
store i8** %0, i8*** %3
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %1
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
store i8* null, i8** %2
br label %217
26: ; preds = %1
store i32 8192, i32* %15
br label %27
27: ; preds = %67, %26
%28 = load i32, i32* %15
%29 = call i8* @utils_malloc(i32 %28)
store i8* %29, i8** %13
%30 = load i8*, i8** %13
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* %4
%34 = call i32 @close(i32 %33)
%35 = load i8**, i8*** %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %35
store i8* null, i8** %2
br label %217
36: ; preds = %27
%37 = load i32, i32* %15
%38 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %12, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i8*, i8** %13
%40 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %12, i32 0, i32 1
store i8* %39, i8** %40
%41 = load i8*, i8** %13
%42 = load i32, i32* %15
%43 = call i32 @memset(i8* %41, i32 0, i32 %42)
%44 = load i32, i32* %4
%45 = load i32, i32* @SIOCGIFCONF
%46 = bitcast %struct.ifconf* %12 to i8*
%47 = call i64 @ioctl(i32 %44, i32 %45, i8* %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %36
%50 = load i64, i64* @errno
%51 = load i64, i64* @EINVAL
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i8*, i8** %13
%55 = call i32 @free(i8* %54)
%56 = load i64, i64* @errno
%57 = call i8* @strerror(i64 %56)
%58 = load i8**, i8*** %3
store i8* %57, i8** %58
%59 = load i32, i32* %4
%60 = call i32 @close(i32 %59)
store i8* null, i8** %2
br label %217
61: ; preds = %49, %36
%62 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %12, i32 0, i32 0
%63 = load i32, i32* %62
%64 = load i32, i32* %15
%65 = icmp ult i32 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %61
br label %72
67: ; preds = %61
%68 = load i8*, i8** %13
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %15
%71 = mul i32 %70, 2
store i32 %71, i32* %15
br label %27
72: ; preds = %66
%73 = load i8*, i8** %13
%74 = bitcast i8* %73 to %struct.ifreq*
store %struct.ifreq* %74, %struct.ifreq** %8
%75 = load i8*, i8** %13
%76 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %12, i32 0, i32 0
%77 = load i32, i32* %76
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %75, i64 %78
%80 = bitcast i8* %79 to %struct.ifreq*
store %struct.ifreq* %80, %struct.ifreq** %9
store %struct.ifreq* null, %struct.ifreq** %11
store i32 666, i32* %5
br label %81
81: ; preds = %193, %72
%82 = load %struct.ifreq*, %struct.ifreq** %8
%83 = load %struct.ifreq*, %struct.ifreq** %9
%84 = icmp ult %struct.ifreq* %82, %83
br i1 %84, label %85, label %195
85: ; preds = %81
%86 = load %struct.ifreq*, %struct.ifreq** %8
%87 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %86, i64 1
store %struct.ifreq* %87, %struct.ifreq** %10
%88 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%89 = load i8*, i8** %88
%90 = load %struct.ifreq*, %struct.ifreq** %8
%91 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %90, i32 0, i32 0
%92 = load i8*, i8** %91
%93 = call i32 @strncpy(i8* %89, i8* %92, i32 8)
%94 = load i32, i32* %4
%95 = load i32, i32* @SIOCGIFFLAGS
%96 = bitcast %struct.ifreq* %14 to i8*
%97 = call i64 @ioctl(i32 %94, i32 %95, i8* %96)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %112
99: ; preds = %85
%100 = load i64, i64* @errno
%101 = load i64, i64* @ENXIO
%102 = icmp eq i64 %100, %101
br i1 %102, label %103, label %104
103: ; preds = %99
br label %193
104: ; preds = %99
%105 = load i64, i64* @errno
%106 = call i8* @strerror(i64 %105)
%107 = load i8**, i8*** %3
store i8* %106, i8** %107
%108 = load i32, i32* %4
%109 = call i32 @close(i32 %108)
%110 = load i8*, i8** %13
%111 = call i32 @free(i8* %110)
store i8* null, i8** %2
br label %217
112: ; preds = %85
%113 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 1
%114 = load i32, i32* %113
%115 = load i32, i32* @IFF_UP
%116 = and i32 %114, %115
%117 = icmp eq i32 %116, 0
br i1 %117, label %146, label %118
118: ; preds = %112
%119 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%120 = load i8*, i8** %119
%121 = getelementptr inbounds i8, i8* %120, i64 0
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp eq i32 %123, 108
br i1 %124, label %125, label %147
125: ; preds = %118
%126 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%127 = load i8*, i8** %126
%128 = getelementptr inbounds i8, i8* %127, i64 1
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 111
br i1 %131, label %132, label %147
132: ; preds = %125
%133 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%134 = load i8*, i8** %133
%135 = getelementptr inbounds i8, i8* %134, i64 2
%136 = load i8, i8* %135
%137 = call i64 @isdigit(i8 signext %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %146, label %139
139: ; preds = %132
%140 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%141 = load i8*, i8** %140
%142 = getelementptr inbounds i8, i8* %141, i64 2
%143 = load i8, i8* %142
%144 = sext i8 %143 to i32
%145 = icmp eq i32 %144, 0
br i1 %145, label %146, label %147
146: ; preds = %139, %132, %112
br label %193
147: ; preds = %139, %125, %118
%148 = load %struct.ifreq*, %struct.ifreq** %8
%149 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %148, i32 0, i32 0
%150 = load i8*, i8** %149
%151 = load %struct.ifreq*, %struct.ifreq** %8
%152 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %151, i32 0, i32 0
%153 = load i8*, i8** %152
%154 = call i32 @strlen(i8* %153)
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i8, i8* %150, i64 %155
store i8* %156, i8** %16
%157 = load %struct.ifreq*, %struct.ifreq** %8
%158 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %157, i32 0, i32 0
%159 = load i8*, i8** %158
store i8* %159, i8** %7
br label %160
160: ; preds = %173, %147
%161 = load i8*, i8** %7
%162 = load i8*, i8** %16
%163 = icmp ult i8* %161, %162
br i1 %163, label %164, label %170
164: ; preds = %160
%165 = load i8*, i8** %7
%166 = load i8, i8* %165
%167 = call i64 @isdigit(i8 signext %166)
%168 = icmp ne i64 %167, 0
%169 = xor i1 %168, true
br label %170
170: ; preds = %164, %160
%171 = phi i1 [ false, %160 ], [ %169, %164 ]
br i1 %171, label %172, label %176
172: ; preds = %170
br label %173
173: ; preds = %172
%174 = load i8*, i8** %7
%175 = getelementptr inbounds i8, i8* %174, i32 1
store i8* %175, i8** %7
br label %160
176: ; preds = %170
%177 = load i8*, i8** %7
%178 = load i8, i8* %177
%179 = call i64 @isdigit(i8 signext %178)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %184
181: ; preds = %176
%182 = load i8*, i8** %7
%183 = call i32 @atoi(i8* %182)
store i32 %183, i32* %6
br label %185
184: ; preds = %176
store i32 0, i32* %6
br label %185
185: ; preds = %184, %181
%186 = load i32, i32* %6
%187 = load i32, i32* %5
%188 = icmp slt i32 %186, %187
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i32, i32* %6
store i32 %190, i32* %5
%191 = load %struct.ifreq*, %struct.ifreq** %8
store %struct.ifreq* %191, %struct.ifreq** %11
br label %192
192: ; preds = %189, %185
br label %193
193: ; preds = %192, %146, %103
%194 = load %struct.ifreq*, %struct.ifreq** %10
store %struct.ifreq* %194, %struct.ifreq** %8
br label %81
195: ; preds = %81
%196 = load i32, i32* %4
%197 = call i32 @close(i32 %196)
%198 = load %struct.ifreq*, %struct.ifreq** %11
%199 = icmp eq %struct.ifreq* %198, null
br i1 %199, label %200, label %206
200: ; preds = %195
%201 = load i64, i64* @errno
%202 = call i8* @strerror(i64 %201)
%203 = load i8**, i8*** %3
store i8* %202, i8** %203
%204 = load i8*, i8** %13
%205 = call i32 @free(i8* %204)
store i8* null, i8** %2
br label %217
206: ; preds = %195
%207 = load %struct.ifreq*, %struct.ifreq** %11
%208 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %207, i32 0, i32 0
%209 = load i8*, i8** %208
%210 = call i32 @strncpy(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 0), i8* %209, i32 9)
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 8)
%211 = load %struct.ifreq*, %struct.ifreq** %11
%212 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %211, i32 0, i32 0
%213 = load i8*, i8** %212
%214 = call i32 @strlen(i8* %213)
%215 = load i8*, i8** %13
%216 = call i32 @free(i8* %215)
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 0), i8** %2
br label %217
217: ; preds = %206, %200, %104, %53, %32, %22
%218 = load i8*, i8** %2
ret i8* %218
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i8*, i32 }
@generic_lookupdev.device = internal global [9 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@.str = [14 x i8] c"out of memory\00"
@SIOCGIFCONF = global i32 0
@EINVAL = global i64 0
@SIOCGIFFLAGS = global i32 0
@ENXIO = global i64 0
@IFF_UP = global i32 0
define i8* @generic_lookupdev(i8** nocapture writeonly %0) {
%2 = alloca %struct.ifconf
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifconf* %2 to i8*
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = call i8* @utils_malloc(i32 8192)
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 0
%15 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 1
br label %21
16: ; preds = %1
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
store i8* %18, i8** %0
br label %144
19: ; preds = %40, %10
%20 = call i32 @close(i32 %8)
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %0
br label %144
21: ; preds = %13, %40
%22 = phi i8* [ %11, %13 ], [ %43, %40 ]
%23 = phi i32 [ 8192, %13 ], [ %42, %40 ]
store i32 %23, i32* %14
store i8* %22, i8** %15
%24 = call i32 @memset(i8* %22, i32 0, i32 %23)
%25 = load i32, i32* @SIOCGIFCONF
%26 = call i64 @ioctl(i32 %8, i32 %25, i8* %4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i64, i64* @errno
%30 = load i64, i64* @EINVAL
%31 = icmp eq i64 %29, %30
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = call i32 @free(i8* %22)
%34 = load i64, i64* @errno
%35 = call i8* @strerror(i64 %34)
store i8* %35, i8** %0
%36 = call i32 @close(i32 %8)
br label %144
37: ; preds = %28, %21
%38 = load i32, i32* %14
%39 = icmp ult i32 %38, %23
br i1 %39, label %45, label %40
40: ; preds = %37
%41 = call i32 @free(i8* %22)
%42 = shl i32 %23, 1
%43 = call i8* @utils_malloc(i32 %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %19, label %21
45: ; preds = %37
%46 = zext i32 %38 to i64
%47 = getelementptr inbounds i8, i8* %22, i64 %46
%48 = bitcast i8* %47 to %struct.ifreq*
%49 = icmp eq i32 %38, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @close(i32 %8)
br label %133
52: ; preds = %45
%53 = bitcast i8* %22 to %struct.ifreq*
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%55 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
br label %56
56: ; preds = %52, %126
%57 = phi i32 [ 666, %52 ], [ %128, %126 ]
%58 = phi %struct.ifreq* [ null, %52 ], [ %127, %126 ]
%59 = phi %struct.ifreq* [ %53, %52 ], [ %60, %126 ]
%60 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %59, i64 1
%61 = load i8*, i8** %54
%62 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %59, i64 0, i32 0
%63 = load i8*, i8** %62
%64 = call i32 @strncpy(i8* %61, i8* %63, i32 8)
%65 = load i32, i32* @SIOCGIFFLAGS
%66 = call i64 @ioctl(i32 %8, i32 %65, i8* %5)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %56
%69 = load i64, i64* @errno
%70 = load i64, i64* @ENXIO
%71 = icmp eq i64 %69, %70
br i1 %71, label %126, label %122
72: ; preds = %56
%73 = load i32, i32* %55
%74 = load i32, i32* @IFF_UP
%75 = and i32 %74, %73
%76 = icmp eq i32 %75, 0
br i1 %76, label %126, label %77
77: ; preds = %72
%78 = load i8*, i8** %54
%79 = load i8, i8* %78
%80 = icmp eq i8 %79, 108
br i1 %80, label %81, label %95
81: ; preds = %77
%82 = getelementptr inbounds i8, i8* %78, i64 1
%83 = load i8, i8* %82
%84 = icmp eq i8 %83, 111
br i1 %84, label %85, label %95
85: ; preds = %81
%86 = getelementptr inbounds i8, i8* %78, i64 2
%87 = load i8, i8* %86
%88 = call i64 @isdigit(i8 signext %87)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %126
90: ; preds = %85
%91 = load i8*, i8** %54
%92 = getelementptr inbounds i8, i8* %91, i64 2
%93 = load i8, i8* %92
%94 = icmp eq i8 %93, 0
br i1 %94, label %126, label %95
95: ; preds = %90, %81, %77
%96 = load i8*, i8** %62
%97 = call i32 @strlen(i8* %96)
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = load i8*, i8** %62
%101 = icmp ult i8* %100, %99
br i1 %101, label %102, label %110
102: ; preds = %95, %107
%103 = phi i8* [ %108, %107 ], [ %100, %95 ]
%104 = load i8, i8* %103
%105 = call i64 @isdigit(i8 signext %104)
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %102
%108 = getelementptr inbounds i8, i8* %103, i64 1
%109 = icmp ult i8* %108, %99
br i1 %109, label %102, label %110
110: ; preds = %102, %107, %95
%111 = phi i8* [ %100, %95 ], [ %108, %107 ], [ %103, %102 ]
%112 = load i8, i8* %111
%113 = call i64 @isdigit(i8 signext %112)
%114 = icmp eq i64 %113, 0
br i1 %114, label %117, label %115
115: ; preds = %110
%116 = call i32 @atoi(i8* %111)
br label %117
117: ; preds = %110, %115
%118 = phi i32 [ %116, %115 ], [ 0, %110 ]
%119 = icmp slt i32 %118, %57
%120 = select i1 %119, %struct.ifreq* %59, %struct.ifreq* %58
%121 = select i1 %119, i32 %118, i32 %57
br label %126
122: ; preds = %68
%123 = call i8* @strerror(i64 %69)
store i8* %123, i8** %0
%124 = call i32 @close(i32 %8)
%125 = call i32 @free(i8* %22)
br label %144
126: ; preds = %117, %68, %90, %85, %72
%127 = phi %struct.ifreq* [ %58, %72 ], [ %58, %85 ], [ %58, %90 ], [ %58, %68 ], [ %120, %117 ]
%128 = phi i32 [ %57, %72 ], [ %57, %85 ], [ %57, %90 ], [ %57, %68 ], [ %121, %117 ]
%129 = icmp ult %struct.ifreq* %60, %48
br i1 %129, label %56, label %130
130: ; preds = %126
%131 = call i32 @close(i32 %8)
%132 = icmp eq %struct.ifreq* %127, null
br i1 %132, label %133, label %137
133: ; preds = %50, %130
%134 = load i64, i64* @errno
%135 = call i8* @strerror(i64 %134)
store i8* %135, i8** %0
%136 = call i32 @free(i8* %22)
br label %144
137: ; preds = %130
%138 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %127, i64 0, i32 0
%139 = load i8*, i8** %138
%140 = call i32 @strncpy(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 0), i8* %139, i32 9)
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 8)
%141 = load i8*, i8** %138
%142 = call i32 @strlen(i8* %141)
%143 = call i32 @free(i8* %22)
br label %144
144: ; preds = %122, %137, %133, %32, %19, %16
%145 = phi i8* [ null, %16 ], [ null, %19 ], [ null, %32 ], [ null, %122 ], [ null, %133 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @generic_lookupdev.device, i64 0, i64 0), %137 ]
ret i8* %145
}