#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_int32_t;
struct TYPE_6__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_3__ sin_addr;
};
struct TYPE_5__ {
  int /*<<< orphan*/ sa_data;
};
struct TYPE_4__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  char *ifr_name;
  int ifr_ifindex;
  TYPE_2__ ifr_hwaddr;
  TYPE_1__ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
char *inet_ntoa(TYPE_3__);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int read_interface(char *interface, int *ifindex, u_int32_t *addr,
                   unsigned char *arp) {
  int fd;
  struct ifreq ifr;
  struct sockaddr_in *our_ip;
  memset(&ifr, 0, sizeof(struct ifreq));
  if ((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) {
    ifr.ifr_addr.sa_family = AF_INET;
    strcpy(ifr.ifr_name, interface);
    if (addr) {
      if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
        our_ip = (struct sockaddr_in *)&ifr.ifr_addr;
        *addr = our_ip->sin_addr.s_addr;
        do {
          printf("%s, ", "info");
          printf("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
          printf("\n");
        } while (0);
      } else {
        do {
          printf("%s, ", "error");
          printf("SIOCGIFADDR failed, is the interface up and configured?: %s",
                 strerror(errno));
          printf("\n");
        } while (0);
        return -1;
      }
    }
    if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
      do {
        printf("%s, ", "info");
        printf("adapter index %d", ifr.ifr_ifindex);
        printf("\n");
      } while (0);
      *ifindex = ifr.ifr_ifindex;
    } else {
      do {
        printf("%s, ", "error");
        printf("SIOCGIFINDEX failed!: %s", strerror(errno));
        printf("\n");
      } while (0);
      return -1;
    }
    if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
      memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
      do {
        printf("%s, ", "info");
        printf("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", arp[0],
               arp[1], arp[2], arp[3], arp[4], arp[5]);
        printf("\n");
      } while (0);
    } else {
      do {
        printf("%s, ", "error");
        printf("SIOCGIFHWADDR failed!: %s", strerror(errno));
        printf("\n");
      } while (0);
      return -1;
    }
  } else {
    do {
      printf("%s, ", "error");
      printf("socket failed!: %s", strerror(errno));
      printf("\n");
    } while (0);
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<read_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jl     1492 <read_interface+0x302>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     12e7 <read_interface+0x157>
mov    -0x2c(%rbp),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jne    128f <read_interface+0xff>
lea    -0x48(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    0xdba(%rip),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e2 <read_interface+0x152>
jmp    1294 <read_interface+0x104>
lea    0xd65(%rip),%rdi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f4 <read_interface+0x364>
jmp    12e7 <read_interface+0x157>
mov    -0x2c(%rbp),%edi
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jne    134d <read_interface+0x1bd>
jmp    130b <read_interface+0x17b>
lea    0xcee(%rip),%rdi
lea    0xcec(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    13a0 <read_interface+0x210>
jmp    1352 <read_interface+0x1c2>
lea    0xca7(%rip),%rdi
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f4 <read_interface+0x364>
mov    -0x2c(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jne    143a <read_interface+0x2aa>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    $0x6,%edx
call   1090 <memcpy@plt>
lea    0xc29(%rip),%rdi
lea    0xc27(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%ecx
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%r8d
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%r9d
mov    -0x28(%rbp),%rax
movzbl 0x5(%rax),%eax
lea    0xc6c(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbed(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    148d <read_interface+0x2fd>
jmp    143f <read_interface+0x2af>
lea    0xbba(%rip),%rdi
lea    0xbd0(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b65(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xba1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f4 <read_interface+0x364>
jmp    14e5 <read_interface+0x355>
jmp    1497 <read_interface+0x307>
lea    0xb62(%rip),%rdi
lea    0xb78(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xc16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f4 <read_interface+0x364>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_interface>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2e0e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1258 <read_interface+0xb8>
mov    %eax,%r12d
mov    (%rbx),%eax
mov    %eax,0x20(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
test   %r13,%r13
je     12d0 <read_interface+0x130>
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r12d,%edi
call   1080 <ioctl@plt>
test   %rax,%rax
je     1287 <read_interface+0xe7>
lea    0xdd0(%rip),%rdi
lea    0xde4(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdce(%rip),%rdi
jmp    138f <read_interface+0x1ef>
lea    0xda1(%rip),%rdi
lea    0xdb5(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe56(%rip),%rdi
jmp    138f <read_interface+0x1ef>
mov    0x20(%rsp),%eax
mov    %eax,0x0(%r13)
lea    0xd6a(%rip),%rdi
lea    0xd68(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rbx
mov    0x20(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xd51(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r12d,%edi
call   1080 <ioctl@plt>
lea    0xd13(%rip),%rdi
test   %rax,%rax
je     1317 <read_interface+0x177>
lea    0xd22(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd59(%rip),%rdi
jmp    138f <read_interface+0x1ef>
lea    0xce7(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rsp),%esi
lea    0xd2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%eax
mov    %eax,(%r15)
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r12d,%edi
call   1080 <ioctl@plt>
test   %rax,%rax
je     13b9 <read_interface+0x219>
lea    0xc94(%rip),%rdi
lea    0xca8(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd2f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x1c(%rsp),%esi
mov    %r14,%rdi
mov    $0x6,%edx
call   10a0 <memcpy@plt>
lea    0xc2f(%rip),%rdi
lea    0xc2d(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%r14),%esi
movzbl 0x1(%r14),%edx
movzbl 0x2(%r14),%ecx
movzbl 0x3(%r14),%r8d
movzbl 0x4(%r14),%r9d
movzbl 0x5(%r14),%eax
mov    %eax,(%rsp)
lea    0xc81(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12d,%edi
call   1090 <close@plt>
jmp    13a8 <read_interface+0x208>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32, %struct.TYPE_5__, %struct.TYPE_4__ }
%struct.TYPE_5__ = type { i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@SIOCGIFADDR = global i32 0
@.str = [5 x i8] c"%s, \00"
@.str.1 = [5 x i8] c"info\00"
@.str.2 = [17 x i8] c"%s (our ip) = %s\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [6 x i8] c"error\00"
@.str.5 = [60 x i8] c"SIOCGIFADDR failed, is the interface up and configured?: %s\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.6 = [17 x i8] c"adapter index %d\00"
@.str.7 = [25 x i8] c"SIOCGIFINDEX failed!: %s\00"
@SIOCGIFHWADDR = global i32 0
@.str.8 = [55 x i8] c"adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x\00"
@.str.9 = [26 x i8] c"SIOCGIFHWADDR failed!: %s\00"
@.str.10 = [19 x i8] c"socket failed!: %s\00"
define i32 @read_interface(i8* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.ifreq
%12 = alloca %struct.sockaddr_in*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%13 = call i32 @memset(%struct.ifreq* %11, i32 0, i32 24)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_RAW
%16 = load i32, i32* @IPPROTO_RAW
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %10
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %136
19: ; preds = %4
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 3
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8*, i8** %6
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i32*, i32** %8
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %63
29: ; preds = %19
%30 = load i32, i32* %10
%31 = load i32, i32* @SIOCGIFADDR
%32 = call i64 @ioctl(i32 %30, i32 %31, %struct.ifreq* %11)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %54
34: ; preds = %29
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 3
%36 = bitcast %struct.TYPE_4__* %35 to %struct.sockaddr_in*
store %struct.sockaddr_in* %36, %struct.sockaddr_in** %12
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %12
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32*, i32** %8
store i32 %40, i32* %41
br label %42
42: ; preds = %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = load %struct.sockaddr_in*, %struct.sockaddr_in** %12
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %46, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @inet_ntoa(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %42
br label %62
54: ; preds = %29
br label %55
55: ; preds = %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %55
store i32 -1, i32* %5
br label %147
62: ; preds = %53
br label %63
63: ; preds = %62, %19
%64 = load i32, i32* %10
%65 = load i32, i32* @SIOCGIFINDEX
%66 = call i64 @ioctl(i32 %64, i32 %65, %struct.ifreq* %11)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %79
68: ; preds = %63
br label %69
69: ; preds = %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%71 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 1
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %69
%76 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 1
%77 = load i32, i32* %76
%78 = load i32*, i32** %7
store i32 %77, i32* %78
br label %87
79: ; preds = %63
br label %80
80: ; preds = %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %80
store i32 -1, i32* %5
br label %147
87: ; preds = %75
%88 = load i32, i32* %10
%89 = load i32, i32* @SIOCGIFHWADDR
%90 = call i64 @ioctl(i32 %88, i32 %89, %struct.ifreq* %11)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %127
92: ; preds = %87
%93 = load i8*, i8** %9
%94 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 2
%95 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %94, i32 0, i32 0
%96 = load i32, i32* %95
%97 = call i32 @memcpy(i8* %93, i32 %96, i32 6)
br label %98
98: ; preds = %92
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%100 = load i8*, i8** %9
%101 = getelementptr inbounds i8, i8* %100, i64 0
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = load i8*, i8** %9
%105 = getelementptr inbounds i8, i8* %104, i64 1
%106 = load i8, i8* %105
%107 = zext i8 %106 to i32
%108 = load i8*, i8** %9
%109 = getelementptr inbounds i8, i8* %108, i64 2
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = load i8*, i8** %9
%113 = getelementptr inbounds i8, i8* %112, i64 3
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = load i8*, i8** %9
%117 = getelementptr inbounds i8, i8* %116, i64 4
%118 = load i8, i8* %117
%119 = zext i8 %118 to i32
%120 = load i8*, i8** %9
%121 = getelementptr inbounds i8, i8* %120, i64 5
%122 = load i8, i8* %121
%123 = zext i8 %122 to i32
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %103, i32 %107, i32 %111, i32 %115, i32 %119, i32 %123)
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %126
126: ; preds = %98
br label %135
127: ; preds = %87
br label %128
128: ; preds = %127
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%130 = load i32, i32* @errno
%131 = call i8* @strerror(i32 %130)
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %131)
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %134
134: ; preds = %128
store i32 -1, i32* %5
br label %147
135: ; preds = %126
br label %144
136: ; preds = %4
br label %137
137: ; preds = %136
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%139 = load i32, i32* @errno
%140 = call i8* @strerror(i32 %139)
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %140)
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %143
143: ; preds = %137
store i32 -1, i32* %5
br label %147
144: ; preds = %135
%145 = load i32, i32* %10
%146 = call i32 @close(i32 %145)
store i32 0, i32* %5
br label %147
147: ; preds = %144, %143, %134, %86, %61
%148 = load i32, i32* %5
ret i32 %148
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, i32, %struct.TYPE_5__, %struct.TYPE_4__ }
%struct.TYPE_5__ = type { i32 }
%struct.TYPE_4__ = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@SIOCGIFADDR = global i32 0
@.str = [5 x i8] c"%s, \00"
@.str.1 = [5 x i8] c"info\00"
@.str.2 = [17 x i8] c"%s (our ip) = %s\00"
@.str.4 = [6 x i8] c"error\00"
@.str.5 = [60 x i8] c"SIOCGIFADDR failed, is the interface up and configured?: %s\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.6 = [17 x i8] c"adapter index %d\00"
@.str.7 = [25 x i8] c"SIOCGIFINDEX failed!: %s\00"
@SIOCGIFHWADDR = global i32 0
@.str.8 = [55 x i8] c"adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x\00"
@.str.9 = [26 x i8] c"SIOCGIFHWADDR failed!: %s\00"
@.str.10 = [19 x i8] c"socket failed!: %s\00"
define i32 @read_interface(i8* %0, i32* nocapture writeonly %1, i32* writeonly %2, i8* %3) {
%5 = alloca %struct.ifreq
%6 = bitcast %struct.ifreq* %5 to i8*
%7 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 24)
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_RAW
%10 = load i32, i32* @IPPROTO_RAW
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %89
13: ; preds = %4
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 3, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %17, i8* %0)
%19 = icmp eq i32* %2, null
br i1 %19, label %38, label %20
20: ; preds = %13
%21 = load i32, i32* @SIOCGIFADDR
%22 = call i64 @ioctl(i32 %11, i32 %21, %struct.ifreq* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %15
store i32 %25, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %16
%28 = load i32, i32* %15
%29 = call i8* @inet_ntoa(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @putchar(i32 10)
br label %38
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = call i32 @putchar(i32 10)
br label %95
38: ; preds = %24, %13
%39 = load i32, i32* @SIOCGIFINDEX
%40 = call i64 @ioctl(i32 %11, i32 %39, %struct.ifreq* %5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = call i32 @putchar(i32 10)
%48 = load i32, i32* %44
store i32 %48, i32* %1
%49 = load i32, i32* @SIOCGIFHWADDR
%50 = call i64 @ioctl(i32 %11, i32 %49, %struct.ifreq* %5)
%51 = icmp eq i64 %50, 0
br i1 %51, label %58, label %83
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %55)
%57 = call i32 @putchar(i32 10)
br label %95
58: ; preds = %42
%59 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 2, i32 0
%60 = load i32, i32* %59
%61 = call i32 @memcpy(i8* %3, i32 %60, i32 6)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%63 = load i8, i8* %3
%64 = zext i8 %63 to i32
%65 = getelementptr inbounds i8, i8* %3, i64 1
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = getelementptr inbounds i8, i8* %3, i64 2
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = getelementptr inbounds i8, i8* %3, i64 3
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = getelementptr inbounds i8, i8* %3, i64 4
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = getelementptr inbounds i8, i8* %3, i64 5
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %64, i32 %67, i32 %70, i32 %73, i32 %76, i32 %79)
%81 = call i32 @putchar(i32 10)
%82 = call i32 @close(i32 %11)
br label %95
83: ; preds = %42
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %86)
%88 = call i32 @putchar(i32 10)
br label %95
89: ; preds = %4
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%91 = load i32, i32* @errno
%92 = call i8* @strerror(i32 %91)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %92)
%94 = call i32 @putchar(i32 10)
br label %95
95: ; preds = %58, %89, %83, %52, %32
%96 = phi i32 [ 0, %58 ], [ -1, %83 ], [ -1, %52 ], [ -1, %32 ], [ -1, %89 ]
ret i32 %96
}