#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 /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct ifreq {
  int /*<<< orphan*/ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SIOCGIFBRDADDR;
int /*<<< orphan*/ SIOCGIFNETMASK;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ ifconfig_ioctl(int, char const *, int /*<<< orphan*/,
                          struct ifreq *);
void *ip_cnv(char const *);
unsigned long ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int ifconfig_print(const char *ifname, const char *addrstr, const char *maskstr,
                   const char *bcaststr) {
  int ret = -1;
  int skfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (skfd != -1) {
    struct ifreq ifr;
    struct {
      unsigned long addr;
      unsigned long mask;
    } solved = {0, 0};
    if (addrstr != NULL && addrstr[0] != '\0') {
      printf("ADDR=%s\n", addrstr);
      solved.addr = ip_cnv(addrstr);
    } else if (ifconfig_ioctl(skfd, ifname, SIOCGIFADDR, &ifr) >= 0) {
      struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
      unsigned long addr = ntohl(sin->sin_addr.s_addr);
      printf("ADDR=%lu.%lu.%lu.%lu\n", (addr >> 24) & 0xff, (addr >> 16) & 0xff,
             (addr >> 8) & 0xff, addr & 0xff);
      solved.addr = addr;
      ret = 0;
    } else {
      perror("ifspec: ioctl(SIOCGIFADDR)");
    }
    if (maskstr != NULL && maskstr[0] != '\0') {
      printf("NETMASK=%s\n", maskstr);
      solved.mask = ip_cnv(maskstr);
    } else if (ifconfig_ioctl(skfd, ifname, SIOCGIFNETMASK, &ifr) >= 0) {
      struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
      unsigned long addr = ntohl(sin->sin_addr.s_addr);
      printf("NETMASK=%lu.%lu.%lu.%lu\n", (addr >> 24) & 0xff,
             (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
      solved.mask = addr;
      ret = 0;
    } else {
      perror("ifspec: ioctl(SIOCGIFNETMASK)");
    }
    if (bcaststr != NULL && bcaststr[0] != '\0') {
      printf("BCAST=%s\n", bcaststr);
    } else if (ifconfig_ioctl(skfd, ifname, SIOCGIFBRDADDR, &ifr) >= 0) {
      struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
      unsigned long addr = ntohl(sin->sin_addr.s_addr);
      printf("BCAST=%lu.%lu.%lu.%lu\n", (addr >> 24) & 0xff,
             (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
      ret = 0;
    } else if (solved.addr != 0 && solved.mask != 0) {
      unsigned long addr = (solved.addr & solved.mask) | ~solved.mask;
      printf("BCAST=%lu.%lu.%lu.%lu\n", (addr >> 24) & 0xff,
             (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
    }
    close(skfd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<ifconfig_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     14e3 <ifconfig_print+0x363>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     1217 <ifconfig_print+0x97>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1217 <ifconfig_print+0x97>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ip_cnv@plt>
mov    %rax,-0x40(%rbp)
jmp    12bc <ifconfig_print+0x13c>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <ifconfig_ioctl@plt>
cmp    $0x0,%rax
jl     12ab <ifconfig_print+0x12b>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
call   1090 <ntohl@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
shr    $0x18,%rsi
and    $0xff,%rsi
mov    -0x50(%rbp),%rdx
shr    $0x10,%rdx
and    $0xff,%rdx
mov    -0x50(%rbp),%rcx
shr    $0x8,%rcx
and    $0xff,%rcx
mov    -0x50(%rbp),%r8
and    $0xff,%r8
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    12b7 <ifconfig_print+0x137>
lea    0xd6d(%rip),%rdi
call   1080 <perror@plt>
jmp    12bc <ifconfig_print+0x13c>
cmpq   $0x0,-0x18(%rbp)
je     12fb <ifconfig_print+0x17b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12fb <ifconfig_print+0x17b>
mov    -0x18(%rbp),%rsi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ip_cnv@plt>
mov    %rax,-0x38(%rbp)
jmp    13a0 <ifconfig_print+0x220>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2ccf(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <ifconfig_ioctl@plt>
cmp    $0x0,%rax
jl     138f <ifconfig_print+0x20f>
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%edi
call   1090 <ntohl@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
shr    $0x18,%rsi
and    $0xff,%rsi
mov    -0x60(%rbp),%rdx
shr    $0x10,%rdx
and    $0xff,%rdx
mov    -0x60(%rbp),%rcx
shr    $0x8,%rcx
and    $0xff,%rcx
mov    -0x60(%rbp),%r8
and    $0xff,%r8
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    139b <ifconfig_print+0x21b>
lea    0xcc9(%rip),%rdi
call   1080 <perror@plt>
jmp    13a0 <ifconfig_print+0x220>
cmpq   $0x0,-0x20(%rbp)
je     13d2 <ifconfig_print+0x252>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13d2 <ifconfig_print+0x252>
mov    -0x20(%rbp),%rsi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    14db <ifconfig_print+0x35b>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2be0(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <ifconfig_ioctl@plt>
cmp    $0x0,%rax
jl     145e <ifconfig_print+0x2de>
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%edi
call   1090 <ntohl@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rsi
shr    $0x18,%rsi
and    $0xff,%rsi
mov    -0x70(%rbp),%rdx
shr    $0x10,%rdx
and    $0xff,%rdx
mov    -0x70(%rbp),%rcx
shr    $0x8,%rcx
and    $0xff,%rcx
mov    -0x70(%rbp),%r8
and    $0xff,%r8
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    14d6 <ifconfig_print+0x356>
cmpq   $0x0,-0x40(%rbp)
je     14d1 <ifconfig_print+0x351>
cmpq   $0x0,-0x38(%rbp)
je     14d1 <ifconfig_print+0x351>
mov    -0x40(%rbp),%rax
and    -0x38(%rbp),%rax
mov    -0x38(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
or     %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
shr    $0x18,%rsi
and    $0xff,%rsi
mov    -0x78(%rbp),%rdx
shr    $0x10,%rdx
and    $0xff,%rdx
mov    -0x78(%rbp),%rcx
shr    $0x8,%rcx
and    $0xff,%rcx
mov    -0x78(%rbp),%r8
and    $0xff,%r8
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    14d6 <ifconfig_print+0x356>
jmp    14db <ifconfig_print+0x35b>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifconfig_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     126d <ifconfig_print+0xfd>
mov    %eax,%r12d
test   %rbx,%rbx
je     11e7 <ifconfig_print+0x77>
cmpb   $0x0,(%rbx)
je     11e7 <ifconfig_print+0x77>
lea    0xe40(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <ip_cnv@plt>
mov    %rax,0x10(%rsp)
mov    $0xffffffff,%r13d
test   %rbp,%rbp
jne    123d <ifconfig_print+0xcd>
jmp    1296 <ifconfig_print+0x126>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %r12d,%edi
mov    %r15,%rsi
call   1050 <ifconfig_ioctl@plt>
test   %rax,%rax
js     1278 <ifconfig_print+0x108>
mov    0x8(%rsp),%edi
call   1080 <ntohl@plt>
mov    %eax,%esi
shr    $0x18,%esi
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%edx
movzbl %ah,%ecx
mov    %rax,0x10(%rsp)
movzbl %al,%r8d
lea    0xddb(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <printf@plt>
test   %rbp,%rbp
je     1296 <ifconfig_print+0x126>
cmpb   $0x0,0x0(%rbp)
je     1296 <ifconfig_print+0x126>
lea    0xdf0(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbp,%rdi
call   1060 <ip_cnv@plt>
mov    %rax,%rbx
test   %r14,%r14
jne    12e8 <ifconfig_print+0x178>
jmp    1317 <ifconfig_print+0x1a7>
mov    $0xffffffff,%r13d
jmp    13a3 <ifconfig_print+0x233>
lea    0xda0(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r13d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
test   %rbp,%rbp
jne    123d <ifconfig_print+0xcd>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %r12d,%edi
mov    %r15,%rsi
call   1050 <ifconfig_ioctl@plt>
test   %rax,%rax
js     1304 <ifconfig_print+0x194>
mov    0x8(%rsp),%edi
call   1080 <ntohl@plt>
mov    %rax,%rbx
mov    %ebx,%esi
shr    $0x18,%esi
shr    $0x10,%eax
movzbl %al,%edx
movzbl %bh,%ecx
movzbl %bl,%r8d
lea    0xd6d(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14,%r14
je     1317 <ifconfig_print+0x1a7>
cmpb   $0x0,(%r14)
je     1317 <ifconfig_print+0x1a7>
lea    0xd88(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    139b <ifconfig_print+0x22b>
lea    0xd54(%rip),%rdi
call   1070 <perror@plt>
xor    %ebx,%ebx
test   %r14,%r14
jne    12e8 <ifconfig_print+0x178>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %r12d,%edi
mov    %r15,%rsi
call   1050 <ifconfig_ioctl@plt>
test   %rax,%rax
js     135e <ifconfig_print+0x1ee>
mov    0x8(%rsp),%edi
call   1080 <ntohl@plt>
mov    %eax,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
mov    %eax,%esi
shr    $0x18,%esi
shr    $0x10,%edx
movzbl %dl,%edx
lea    0xd2e(%rip),%rdi
xor    %r13d,%r13d
jmp    1394 <ifconfig_print+0x224>
cmpq   $0x0,0x10(%rsp)
je     139b <ifconfig_print+0x22b>
test   %rbx,%rbx
je     139b <ifconfig_print+0x22b>
not    %rbx
mov    0x10(%rsp),%rdx
or     %rbx,%rdx
mov    %edx,%esi
shr    $0x18,%esi
mov    %edx,%eax
shr    $0x10,%eax
movzbl %al,%eax
movzbl %dh,%ecx
movzbl %dl,%r8d
lea    0xcf6(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32 }
%struct.anon = type { i64, i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [9 x i8] c"ADDR=%s\0A\00"
@SIOCGIFADDR = global i32 0
@.str.1 = [22 x i8] c"ADDR=%lu.%lu.%lu.%lu\0A\00"
@.str.2 = [27 x i8] c"ifspec: ioctl(SIOCGIFADDR)\00"
@.str.3 = [12 x i8] c"NETMASK=%s\0A\00"
@SIOCGIFNETMASK = global i32 0
@.str.4 = [25 x i8] c"NETMASK=%lu.%lu.%lu.%lu\0A\00"
@.str.5 = [30 x i8] c"ifspec: ioctl(SIOCGIFNETMASK)\00"
@.str.6 = [10 x i8] c"BCAST=%s\0A\00"
@SIOCGIFBRDADDR = global i32 0
@.str.7 = [23 x i8] c"BCAST=%lu.%lu.%lu.%lu\0A\00"
define i32 @ifconfig_print(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.ifreq
%12 = alloca %struct.anon
%13 = alloca %struct.sockaddr_in*
%14 = alloca i64
%15 = alloca %struct.sockaddr_in*
%16 = alloca i64
%17 = alloca %struct.sockaddr_in*
%18 = alloca i64
%19 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 -1, i32* %9
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %193
25: ; preds = %4
%26 = bitcast %struct.anon* %12 to i8*
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %6
%39 = call i8* @ip_cnv(i8* %38)
%40 = ptrtoint i8* %39 to i64
%41 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
store i64 %40, i64* %41
br label %73
42: ; preds = %29, %25
%43 = load i32, i32* %10
%44 = load i8*, i8** %5
%45 = load i32, i32* @SIOCGIFADDR
%46 = call i64 @ifconfig_ioctl(i32 %43, i8* %44, i32 %45, %struct.ifreq* %11)
%47 = icmp sge i64 %46, 0
br i1 %47, label %48, label %70
48: ; preds = %42
%49 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%50 = bitcast i32* %49 to %struct.sockaddr_in*
store %struct.sockaddr_in* %50, %struct.sockaddr_in** %13
%51 = load %struct.sockaddr_in*, %struct.sockaddr_in** %13
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %51, i32 0, i32 0
%53 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i64 @ntohl(i32 %54)
store i64 %55, i64* %14
%56 = load i64, i64* %14
%57 = lshr i64 %56, 24
%58 = and i64 %57, 255
%59 = load i64, i64* %14
%60 = lshr i64 %59, 16
%61 = and i64 %60, 255
%62 = load i64, i64* %14
%63 = lshr i64 %62, 8
%64 = and i64 %63, 255
%65 = load i64, i64* %14
%66 = and i64 %65, 255
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %58, i64 %61, i64 %64, i64 %66)
%68 = load i64, i64* %14
%69 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
store i64 %68, i64* %69
store i32 0, i32* %9
br label %72
70: ; preds = %42
%71 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %72
72: ; preds = %70, %48
br label %73
73: ; preds = %72, %35
%74 = load i8*, i8** %7
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %89
76: ; preds = %73
%77 = load i8*, i8** %7
%78 = getelementptr inbounds i8, i8* %77, i64 0
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %89
82: ; preds = %76
%83 = load i8*, i8** %7
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %83)
%85 = load i8*, i8** %7
%86 = call i8* @ip_cnv(i8* %85)
%87 = ptrtoint i8* %86 to i64
%88 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 1
store i64 %87, i64* %88
br label %120
89: ; preds = %76, %73
%90 = load i32, i32* %10
%91 = load i8*, i8** %5
%92 = load i32, i32* @SIOCGIFNETMASK
%93 = call i64 @ifconfig_ioctl(i32 %90, i8* %91, i32 %92, %struct.ifreq* %11)
%94 = icmp sge i64 %93, 0
br i1 %94, label %95, label %117
95: ; preds = %89
%96 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%97 = bitcast i32* %96 to %struct.sockaddr_in*
store %struct.sockaddr_in* %97, %struct.sockaddr_in** %15
%98 = load %struct.sockaddr_in*, %struct.sockaddr_in** %15
%99 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %98, i32 0, i32 0
%100 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = call i64 @ntohl(i32 %101)
store i64 %102, i64* %16
%103 = load i64, i64* %16
%104 = lshr i64 %103, 24
%105 = and i64 %104, 255
%106 = load i64, i64* %16
%107 = lshr i64 %106, 16
%108 = and i64 %107, 255
%109 = load i64, i64* %16
%110 = lshr i64 %109, 8
%111 = and i64 %110, 255
%112 = load i64, i64* %16
%113 = and i64 %112, 255
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i64 %105, i64 %108, i64 %111, i64 %113)
%115 = load i64, i64* %16
%116 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 1
store i64 %115, i64* %116
store i32 0, i32* %9
br label %119
117: ; preds = %89
%118 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %119
119: ; preds = %117, %95
br label %120
120: ; preds = %119, %82
%121 = load i8*, i8** %8
%122 = icmp ne i8* %121, null
br i1 %122, label %123, label %132
123: ; preds = %120
%124 = load i8*, i8** %8
%125 = getelementptr inbounds i8, i8* %124, i64 0
%126 = load i8, i8* %125
%127 = sext i8 %126 to i32
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %123
%130 = load i8*, i8** %8
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %130)
br label %190
132: ; preds = %123, %120
%133 = load i32, i32* %10
%134 = load i8*, i8** %5
%135 = load i32, i32* @SIOCGIFBRDADDR
%136 = call i64 @ifconfig_ioctl(i32 %133, i8* %134, i32 %135, %struct.ifreq* %11)
%137 = icmp sge i64 %136, 0
br i1 %137, label %138, label %158
138: ; preds = %132
%139 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%140 = bitcast i32* %139 to %struct.sockaddr_in*
store %struct.sockaddr_in* %140, %struct.sockaddr_in** %17
%141 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%142 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %141, i32 0, i32 0
%143 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %142, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i64 @ntohl(i32 %144)
store i64 %145, i64* %18
%146 = load i64, i64* %18
%147 = lshr i64 %146, 24
%148 = and i64 %147, 255
%149 = load i64, i64* %18
%150 = lshr i64 %149, 16
%151 = and i64 %150, 255
%152 = load i64, i64* %18
%153 = lshr i64 %152, 8
%154 = and i64 %153, 255
%155 = load i64, i64* %18
%156 = and i64 %155, 255
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 %148, i64 %151, i64 %154, i64 %156)
store i32 0, i32* %9
br label %189
158: ; preds = %132
%159 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
%160 = load i64, i64* %159
%161 = icmp ne i64 %160, 0
br i1 %161, label %162, label %188
162: ; preds = %158
%163 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 1
%164 = load i64, i64* %163
%165 = icmp ne i64 %164, 0
br i1 %165, label %166, label %188
166: ; preds = %162
%167 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
%168 = load i64, i64* %167
%169 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 1
%170 = load i64, i64* %169
%171 = and i64 %168, %170
%172 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 1
%173 = load i64, i64* %172
%174 = xor i64 %173, -1
%175 = or i64 %171, %174
store i64 %175, i64* %19
%176 = load i64, i64* %19
%177 = lshr i64 %176, 24
%178 = and i64 %177, 255
%179 = load i64, i64* %19
%180 = lshr i64 %179, 16
%181 = and i64 %180, 255
%182 = load i64, i64* %19
%183 = lshr i64 %182, 8
%184 = and i64 %183, 255
%185 = load i64, i64* %19
%186 = and i64 %185, 255
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 %178, i64 %181, i64 %184, i64 %186)
br label %188
188: ; preds = %166, %162, %158
br label %189
189: ; preds = %188, %138
br label %190
190: ; preds = %189, %129
%191 = load i32, i32* %10
%192 = call i32 @close(i32 %191)
br label %193
193: ; preds = %190, %4
%194 = load i32, i32* %9
ret i32 %194
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [9 x i8] c"ADDR=%s\0A\00"
@SIOCGIFADDR = global i32 0
@.str.1 = [22 x i8] c"ADDR=%lu.%lu.%lu.%lu\0A\00"
@.str.2 = [27 x i8] c"ifspec: ioctl(SIOCGIFADDR)\00"
@.str.3 = [12 x i8] c"NETMASK=%s\0A\00"
@SIOCGIFNETMASK = global i32 0
@.str.4 = [25 x i8] c"NETMASK=%lu.%lu.%lu.%lu\0A\00"
@.str.5 = [30 x i8] c"ifspec: ioctl(SIOCGIFNETMASK)\00"
@.str.6 = [10 x i8] c"BCAST=%s\0A\00"
@SIOCGIFBRDADDR = global i32 0
@.str.7 = [23 x i8] c"BCAST=%lu.%lu.%lu.%lu\0A\00"
define i32 @ifconfig_print(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.ifreq
%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 eq i32 %8, -1
br i1 %9, label %110, label %10
10: ; preds = %4
%11 = bitcast %struct.ifreq* %5 to i8*
%12 = icmp eq i8* %1, null
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = load i8, i8* %1
%15 = icmp eq i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1)
%18 = tail call i8* @ip_cnv(i8* %1)
%19 = ptrtoint i8* %18 to i64
br label %38
20: ; preds = %13, %10
%21 = load i32, i32* @SIOCGIFADDR
%22 = call i64 @ifconfig_ioctl(i32 %8, i8* %0, i32 %21, %struct.ifreq* %5)
%23 = icmp sgt i64 %22, -1
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @ntohl(i32 %26)
%28 = lshr i64 %27, 24
%29 = and i64 %28, 255
%30 = lshr i64 %27, 16
%31 = and i64 %30, 255
%32 = lshr i64 %27, 8
%33 = and i64 %32, 255
%34 = and i64 %27, 255
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %29, i64 %31, i64 %33, i64 %34)
br label %38
36: ; preds = %20
%37 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %24, %36, %16
%39 = phi i64 [ %19, %16 ], [ %27, %24 ], [ 0, %36 ]
%40 = phi i32 [ -1, %16 ], [ 0, %24 ], [ -1, %36 ]
%41 = icmp eq i8* %2, null
br i1 %41, label %49, label %42
42: ; preds = %38
%43 = load i8, i8* %2
%44 = icmp eq i8 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%47 = call i8* @ip_cnv(i8* %2)
%48 = ptrtoint i8* %47 to i64
br label %67
49: ; preds = %42, %38
%50 = load i32, i32* @SIOCGIFNETMASK
%51 = call i64 @ifconfig_ioctl(i32 %8, i8* %0, i32 %50, %struct.ifreq* %5)
%52 = icmp sgt i64 %51, -1
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
%55 = load i32, i32* %54
%56 = call i64 @ntohl(i32 %55)
%57 = lshr i64 %56, 24
%58 = and i64 %57, 255
%59 = lshr i64 %56, 16
%60 = and i64 %59, 255
%61 = lshr i64 %56, 8
%62 = and i64 %61, 255
%63 = and i64 %56, 255
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i64 %58, i64 %60, i64 %62, i64 %63)
br label %67
65: ; preds = %49
%66 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %53, %65, %45
%68 = phi i64 [ %48, %45 ], [ %56, %53 ], [ 0, %65 ]
%69 = phi i32 [ %40, %45 ], [ 0, %53 ], [ %40, %65 ]
%70 = icmp eq i8* %3, null
br i1 %70, label %76, label %71
71: ; preds = %67
%72 = load i8, i8* %3
%73 = icmp eq i8 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %3)
br label %107
76: ; preds = %71, %67
%77 = load i32, i32* @SIOCGIFBRDADDR
%78 = call i64 @ifconfig_ioctl(i32 %8, i8* %0, i32 %77, %struct.ifreq* %5)
%79 = icmp sgt i64 %78, -1
br i1 %79, label %80, label %92
80: ; preds = %76
%81 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
%82 = load i32, i32* %81
%83 = call i64 @ntohl(i32 %82)
%84 = lshr i64 %83, 24
%85 = and i64 %84, 255
%86 = lshr i64 %83, 16
%87 = and i64 %86, 255
%88 = lshr i64 %83, 8
%89 = and i64 %88, 255
%90 = and i64 %83, 255
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 %85, i64 %87, i64 %89, i64 %90)
br label %107
92: ; preds = %76
%93 = icmp ne i64 %39, 0
%94 = icmp ne i64 %68, 0
%95 = select i1 %93, i1 %94, i1 false
br i1 %95, label %96, label %107
96: ; preds = %92
%97 = xor i64 %68, -1
%98 = or i64 %39, %97
%99 = lshr i64 %98, 24
%100 = and i64 %99, 255
%101 = lshr i64 %98, 16
%102 = and i64 %101, 255
%103 = lshr i64 %98, 8
%104 = and i64 %103, 255
%105 = and i64 %98, 255
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 %100, i64 %102, i64 %104, i64 %105)
br label %107
107: ; preds = %80, %96, %92, %74
%108 = phi i32 [ %69, %74 ], [ 0, %80 ], [ %69, %96 ], [ %69, %92 ]
%109 = call i32 @close(i32 %8)
br label %110
110: ; preds = %107, %4
%111 = phi i32 [ %108, %107 ], [ -1, %4 ]
ret i32 %111
}