#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 sockaddr_in {
  int /*<<< orphan*/ sin_port;
};
struct TYPE_2__ {
  scalar_t__ sa_family;
};
struct ifreq {
  int ifr_flags;
  TYPE_1__ ifr_addr;
};
struct ifconf {
  int ifc_len;
  int /*<<< orphan*/ ifc_buf;
  struct ifreq *ifc_req;
};

/* Variables and functions */
scalar_t__ AF_INET;
int IFF_LOOPBACK;
int IFF_UP;
int /*<<< orphan*/ PMAPPORT;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _RPC_close(int);
int /*<<< orphan*/ free(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
size_t ifreqSize(struct ifreq *);
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ malloc(int);
int /*<<< orphan*/ memmove(struct ifreq *, char *, size_t const);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int get_myaddress(struct sockaddr_in *addr) {
  int s;
  struct ifconf ifc;
  struct ifreq ifreq, *ifr;
  int loopback = 0, gotit = 0;
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    return (-1);
  }
again:
  ifc.ifc_len = sizeof(struct ifreq) * 8u;
  ifc.ifc_buf = malloc(ifc.ifc_len);
  if (!ifc.ifc_buf) {
    _RPC_close(s);
    return -1;
  }
  if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
    _RPC_close(s);
    free(ifc.ifc_buf);
    return (-1);
  }
  ifr = ifc.ifc_req;
  while (ifc.ifc_len >= ifreqSize(ifr)) {
    ifreq = *ifr;
    if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
      _RPC_close(s);
      free(ifc.ifc_buf);
      return (-1);
    }
    if (((ifreq.ifr_flags & IFF_UP) && ifr->ifr_addr.sa_family == AF_INET &&
         !(ifreq.ifr_flags & IFF_LOOPBACK)) ||
        (loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK) &&
         (ifr->ifr_addr.sa_family == AF_INET) && (ifreq.ifr_flags & IFF_UP))) {
      *addr = *((struct sockaddr_in *)&ifr->ifr_addr);
      addr->sin_port = htons(PMAPPORT);
      gotit = 1;
      break;
    }
    const size_t len = ifreqSize(ifr);
    ifc.ifc_len -= len;
    memmove(ifr, len + (char *)ifr, ifc.ifc_len);
  }
  if (gotit == 0 && loopback == 0) {
    free(ifc.ifc_buf);
    loopback = 1;
    goto again;
  }
  (void)_RPC_close(s);
  free(ifc.ifc_buf);
  return (gotit ? 0 : -1);
}


x86 assembly (clang, -O0):
<get_myaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11cc <get_myaddress+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <get_myaddress+0x273>
jmp    11d1 <get_myaddress+0x51>
movl   $0x80,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <malloc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1201 <get_myaddress+0x81>
mov    -0x14(%rbp),%edi
call   1060 <_RPC_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <get_myaddress+0x273>
mov    -0x14(%rbp),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    123c <get_myaddress+0xbc>
mov    -0x14(%rbp),%edi
call   1060 <_RPC_close@plt>
mov    -0x24(%rbp),%edi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <get_myaddress+0x273>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
movslq -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <ifreqSize@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jb     13a8 <get_myaddress+0x228>
mov    -0x40(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x38(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    12b3 <get_myaddress+0x133>
mov    -0x14(%rbp),%edi
call   1060 <_RPC_close@plt>
mov    -0x24(%rbp),%edi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <get_myaddress+0x273>
mov    -0x38(%rbp),%eax
mov    0x2d1b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12f5 <get_myaddress+0x175>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%rax
jne    12f5 <get_myaddress+0x175>
mov    -0x38(%rbp),%eax
mov    0x2d0e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1341 <get_myaddress+0x1c1>
cmpl   $0x1,-0x44(%rbp)
jne    1370 <get_myaddress+0x1f0>
mov    -0x38(%rbp),%eax
mov    0x2cef(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1370 <get_myaddress+0x1f0>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2cbd(%rip),%rcx
cmp    (%rcx),%rax
jne    1370 <get_myaddress+0x1f0>
mov    -0x38(%rbp),%eax
mov    0x2ca2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1370 <get_myaddress+0x1f0>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    0x8(%rcx),%ecx
mov    %ecx,(%rax)
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x48(%rbp)
jmp    13a8 <get_myaddress+0x228>
mov    -0x40(%rbp),%rdi
call   1070 <ifreqSize@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
movslq -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rsi
add    %rax,%rsi
movslq -0x28(%rbp),%rdx
call   1090 <memmove@plt>
jmp    1244 <get_myaddress+0xc4>
cmpl   $0x0,-0x48(%rbp)
jne    13d0 <get_myaddress+0x250>
cmpl   $0x0,-0x44(%rbp)
jne    13d0 <get_myaddress+0x250>
mov    -0x24(%rbp),%edi
call   1030 <free@plt>
movl   $0x1,-0x44(%rbp)
jmp    11d1 <get_myaddress+0x51>
mov    -0x14(%rbp),%edi
call   1060 <_RPC_close@plt>
mov    -0x24(%rbp),%edi
call   1030 <free@plt>
mov    -0x48(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_myaddress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbp
mov    0x2e48(%rip),%rax
mov    (%rax),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1439 <get_myaddress+0x2b9>
mov    %eax,%r13d
movl   $0x80,(%rsp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
je     133b <get_myaddress+0x1bb>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r13d,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1348 <get_myaddress+0x1c8>
mov    %rbp,0x20(%rsp)
mov    0x8(%rsp),%rbx
movslq (%rsp),%r14
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
cmp    %r14,%rax
jbe    135e <get_myaddress+0x1de>
mov    0x4(%rsp),%edi
call   1030 <free@plt>
movl   $0x80,(%rsp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
mov    $0xffffffff,%ebx
je     133b <get_myaddress+0x1bb>
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r13d,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1348 <get_myaddress+0x1c8>
mov    0x8(%rsp),%rbx
movslq (%rsp),%r14
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
mov    $0xffffffff,%r15d
cmp    %r14,%rax
ja     140d <get_myaddress+0x28d>
mov    0x2d3d(%rip),%r14
mov    0x2d6e(%rip),%r12
jmp    12c4 <get_myaddress+0x144>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
mov    (%rsp),%ecx
sub    %eax,%ecx
mov    %ecx,(%rsp)
lea    (%rax,%rbx,1),%rsi
movslq %ecx,%rdx
mov    %rbx,%rdi
call   1090 <memmove@plt>
movslq (%rsp),%rbp
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
cmp    %rbp,%rax
ja     140d <get_myaddress+0x28d>
movups (%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
mov    (%r14),%esi
mov    %r13d,%edi
lea    0x10(%rsp),%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1423 <get_myaddress+0x2a3>
mov    0x10(%rsp),%ecx
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
test   %ecx,%edx
je     1310 <get_myaddress+0x190>
mov    0x8(%rbx),%rax
mov    0x2cdf(%rip),%rsi
cmp    (%rsi),%rax
jne    1310 <get_myaddress+0x190>
test   %ecx,(%r12)
je     13f3 <get_myaddress+0x273>
test   %ecx,(%r12)
je     1290 <get_myaddress+0x110>
mov    0x8(%rbx),%rax
mov    0x2cbb(%rip),%rsi
cmp    (%rsi),%rax
jne    1290 <get_myaddress+0x110>
and    %ecx,%edx
je     1290 <get_myaddress+0x110>
jmp    13f3 <get_myaddress+0x273>
mov    %r13d,%edi
call   1060 <_RPC_close@plt>
jmp    1439 <get_myaddress+0x2b9>
mov    %r13d,%edi
call   1060 <_RPC_close@plt>
mov    0x4(%rsp),%edi
call   1030 <free@plt>
jmp    1439 <get_myaddress+0x2b9>
mov    0x2c5b(%rip),%r14
lea    0x10(%rsp),%r12
mov    0x2c67(%rip),%rbp
jmp    13b4 <get_myaddress+0x234>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
mov    (%rsp),%ecx
sub    %eax,%ecx
mov    %ecx,(%rsp)
lea    (%rax,%rbx,1),%rsi
movslq %ecx,%rdx
mov    %rbx,%rdi
call   1090 <memmove@plt>
movslq (%rsp),%r15
mov    %rbx,%rdi
call   1070 <ifreqSize@plt>
cmp    %r15,%rax
ja     1214 <get_myaddress+0x94>
movups (%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
mov    (%r14),%esi
mov    %r13d,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1423 <get_myaddress+0x2a3>
mov    0x10(%rsp),%ecx
test   %ecx,0x0(%rbp)
je     1380 <get_myaddress+0x200>
mov    0x8(%rbx),%rax
mov    0x2bfd(%rip),%rdx
cmp    (%rdx),%rax
jne    1380 <get_myaddress+0x200>
mov    0x2c09(%rip),%rdx
test   %ecx,(%rdx)
jne    1380 <get_myaddress+0x200>
mov    0x20(%rsp),%rbx
mov    %eax,(%rbx)
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %eax,(%rbx)
xor    %r15d,%r15d
mov    %r13d,%edi
call   1060 <_RPC_close@plt>
mov    0x4(%rsp),%edi
call   1030 <free@plt>
mov    %r15d,%ebx
jmp    1439 <get_myaddress+0x2b9>
mov    %r13d,%edi
call   1060 <_RPC_close@plt>
mov    0x4(%rsp),%edi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.ifconf = type { i32, i32, %struct.ifreq* }
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@SOCK_DGRAM = global i32 0
@SIOCGIFCONF = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_LOOPBACK = global i32 0
@PMAPPORT = global i32 0
define i32 @get_myaddress(%struct.sockaddr_in* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in*
%4 = alloca i32
%5 = alloca %struct.ifconf
%6 = alloca %struct.ifreq
%7 = alloca %struct.ifreq*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i64, i64* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i64 %11, i32 %12, i32 0)
store i32 %13, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %156
16: ; preds = %1
br label %17
17: ; preds = %142, %16
%18 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 0
store i32 128, i32* %18
%19 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @malloc(i32 %20)
%22 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %17
%27 = load i32, i32* %4
%28 = call i32 @_RPC_close(i32 %27)
store i32 -1, i32* %2
br label %156
29: ; preds = %17
%30 = load i32, i32* %4
%31 = load i32, i32* @SIOCGIFCONF
%32 = bitcast %struct.ifconf* %5 to i8*
%33 = call i64 @ioctl(i32 %30, i32 %31, i8* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* %4
%37 = call i32 @_RPC_close(i32 %36)
%38 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
%39 = load i32, i32* %38
%40 = call i32 @free(i32 %39)
store i32 -1, i32* %2
br label %156
41: ; preds = %29
%42 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 2
%43 = load %struct.ifreq*, %struct.ifreq** %42
store %struct.ifreq* %43, %struct.ifreq** %7
br label %44
44: ; preds = %118, %41
%45 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 0
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = load %struct.ifreq*, %struct.ifreq** %7
%49 = call i64 @ifreqSize(%struct.ifreq* %48)
%50 = icmp uge i64 %47, %49
br i1 %50, label %51, label %136
51: ; preds = %44
%52 = load %struct.ifreq*, %struct.ifreq** %7
%53 = bitcast %struct.ifreq* %6 to i8*
%54 = bitcast %struct.ifreq* %52 to i8*
%55 = load i32, i32* %4
%56 = load i32, i32* @SIOCGIFFLAGS
%57 = bitcast %struct.ifreq* %6 to i8*
%58 = call i64 @ioctl(i32 %55, i32 %56, i8* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %51
%61 = load i32, i32* %4
%62 = call i32 @_RPC_close(i32 %61)
%63 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 @free(i32 %64)
store i32 -1, i32* %2
br label %156
66: ; preds = %51
%67 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%68 = load i32, i32* %67
%69 = load i32, i32* @IFF_UP
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %85
72: ; preds = %66
%73 = load %struct.ifreq*, %struct.ifreq** %7
%74 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %73, i32 0, i32 1
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
%76 = load i64, i64* %75
%77 = load i64, i64* @AF_INET
%78 = icmp eq i64 %76, %77
br i1 %78, label %79, label %85
79: ; preds = %72
%80 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%81 = load i32, i32* %80
%82 = load i32, i32* @IFF_LOOPBACK
%83 = and i32 %81, %82
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %107
85: ; preds = %79, %72, %66
%86 = load i32, i32* %8
%87 = icmp eq i32 %86, 1
br i1 %87, label %88, label %118
88: ; preds = %85
%89 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%90 = load i32, i32* %89
%91 = load i32, i32* @IFF_LOOPBACK
%92 = and i32 %90, %91
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %118
94: ; preds = %88
%95 = load %struct.ifreq*, %struct.ifreq** %7
%96 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %95, i32 0, i32 1
%97 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %96, i32 0, i32 0
%98 = load i64, i64* %97
%99 = load i64, i64* @AF_INET
%100 = icmp eq i64 %98, %99
br i1 %100, label %101, label %118
101: ; preds = %94
%102 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%103 = load i32, i32* %102
%104 = load i32, i32* @IFF_UP
%105 = and i32 %103, %104
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %118
107: ; preds = %101, %79
%108 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%109 = load %struct.ifreq*, %struct.ifreq** %7
%110 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %109, i32 0, i32 1
%111 = bitcast %struct.TYPE_2__* %110 to %struct.sockaddr_in*
%112 = bitcast %struct.sockaddr_in* %108 to i8*
%113 = bitcast %struct.sockaddr_in* %111 to i8*
%114 = load i32, i32* @PMAPPORT
%115 = call i32 @htons(i32 %114)
%116 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%117 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %116, i32 0, i32 0
store i32 %115, i32* %117
store i32 1, i32* %9
br label %136
118: ; preds = %101, %94, %88, %85
%119 = load %struct.ifreq*, %struct.ifreq** %7
%120 = call i64 @ifreqSize(%struct.ifreq* %119)
store i64 %120, i64* %10
%121 = load i64, i64* %10
%122 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 0
%123 = load i32, i32* %122
%124 = sext i32 %123 to i64
%125 = sub i64 %124, %121
%126 = trunc i64 %125 to i32
store i32 %126, i32* %122
%127 = load %struct.ifreq*, %struct.ifreq** %7
%128 = load i64, i64* %10
%129 = load %struct.ifreq*, %struct.ifreq** %7
%130 = bitcast %struct.ifreq* %129 to i8*
%131 = getelementptr inbounds i8, i8* %130, i64 %128
%132 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 0
%133 = load i32, i32* %132
%134 = sext i32 %133 to i64
%135 = call i32 @memmove(%struct.ifreq* %127, i8* %131, i64 %134)
br label %44
136: ; preds = %107, %44
%137 = load i32, i32* %9
%138 = icmp eq i32 %137, 0
br i1 %138, label %139, label %146
139: ; preds = %136
%140 = load i32, i32* %8
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %146
142: ; preds = %139
%143 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
%144 = load i32, i32* %143
%145 = call i32 @free(i32 %144)
store i32 1, i32* %8
br label %17
146: ; preds = %139, %136
%147 = load i32, i32* %4
%148 = call i32 @_RPC_close(i32 %147)
%149 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i32 0, i32 1
%150 = load i32, i32* %149
%151 = call i32 @free(i32 %150)
%152 = load i32, i32* %9
%153 = icmp ne i32 %152, 0
%154 = zext i1 %153 to i64
%155 = select i1 %153, i32 0, i32 -1
store i32 %155, i32* %2
br label %156
156: ; preds = %146, %60, %35, %26, %15
%157 = load i32, i32* %2
ret i32 %157
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.ifconf = type { i32, i32, %struct.ifreq* }
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@SOCK_DGRAM = global i32 0
@SIOCGIFCONF = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_LOOPBACK = global i32 0
@PMAPPORT = global i32 0
define i32 @get_myaddress(%struct.sockaddr_in* 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 i64, i64* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i64 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %136, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 0
store i32 128, i32* %11
%12 = call i32 @malloc(i32 128)
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 1
store i32 %12, i32* %13
%14 = icmp eq i32 %12, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 2
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%18 = load i32, i32* @SIOCGIFCONF
%19 = call i64 @ioctl(i32 %8, i32 %18, i8* %4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %23, label %27
21: ; preds = %75, %10
%22 = call i32 @_RPC_close(i32 %8)
br label %136
23: ; preds = %80, %15
%24 = call i32 @_RPC_close(i32 %8)
%25 = load i32, i32* %13
%26 = call i32 @free(i32 %25)
br label %136
27: ; preds = %15
%28 = load %struct.ifreq*, %struct.ifreq** %16
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = call i64 @ifreqSize(%struct.ifreq* %28)
%32 = icmp ugt i64 %31, %30
br i1 %32, label %75, label %33
33: ; preds = %27
%34 = bitcast %struct.ifreq* %28 to i8*
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %28, i64 0, i32 1, i32 0
br label %36
36: ; preds = %33, %63
%37 = load i32, i32* @SIOCGIFFLAGS
%38 = call i64 @ioctl(i32 %8, i32 %37, i8* %5)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %93, %36
%41 = call i32 @_RPC_close(i32 %8)
%42 = load i32, i32* %13
%43 = call i32 @free(i32 %42)
br label %136
44: ; preds = %36
%45 = load i32, i32* %17
%46 = load i32, i32* @IFF_UP
%47 = and i32 %46, %45
%48 = icmp eq i32 %47, 0
br i1 %48, label %63, label %49
49: ; preds = %44
%50 = load i64, i64* %35
%51 = load i64, i64* @AF_INET
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %63
53: ; preds = %49
%54 = load i32, i32* @IFF_LOOPBACK
%55 = and i32 %54, %45
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %114, %106, %53
%58 = phi i64 [ %50, %53 ], [ %115, %114 ], [ %103, %106 ]
%59 = trunc i64 %58 to i32
%60 = getelementptr %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i32 %59, i32* %60
%61 = load i32, i32* @PMAPPORT
%62 = call i32 @htons(i32 %61)
store i32 %62, i32* %60
br label %131
63: ; preds = %44, %49, %53
%64 = call i64 @ifreqSize(%struct.ifreq* %28)
%65 = load i32, i32* %11
%66 = trunc i64 %64 to i32
%67 = sub i32 %65, %66
store i32 %67, i32* %11
%68 = getelementptr inbounds i8, i8* %34, i64 %64
%69 = sext i32 %67 to i64
%70 = call i32 @memmove(%struct.ifreq* %28, i8* %68, i64 %69)
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = call i64 @ifreqSize(%struct.ifreq* %28)
%74 = icmp ugt i64 %73, %72
br i1 %74, label %75, label %36
75: ; preds = %27, %63
%76 = load i32, i32* %13
%77 = call i32 @free(i32 %76)
store i32 128, i32* %11
%78 = call i32 @malloc(i32 128)
store i32 %78, i32* %13
%79 = icmp eq i32 %78, 0
br i1 %79, label %21, label %80
80: ; preds = %75
%81 = load i32, i32* @SIOCGIFCONF
%82 = call i64 @ioctl(i32 %8, i32 %81, i8* %4)
%83 = icmp slt i64 %82, 0
br i1 %83, label %23, label %84
84: ; preds = %80
%85 = load %struct.ifreq*, %struct.ifreq** %16
%86 = load i32, i32* %11
%87 = sext i32 %86 to i64
%88 = call i64 @ifreqSize(%struct.ifreq* %85)
%89 = icmp ugt i64 %88, %87
br i1 %89, label %131, label %90
90: ; preds = %84
%91 = bitcast %struct.ifreq* %85 to i8*
%92 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %85, i64 0, i32 1, i32 0
br label %93
93: ; preds = %119, %90
%94 = load i32, i32* @SIOCGIFFLAGS
%95 = call i64 @ioctl(i32 %8, i32 %94, i8* %5)
%96 = icmp slt i64 %95, 0
br i1 %96, label %40, label %97
97: ; preds = %93
%98 = load i32, i32* %17
%99 = load i32, i32* @IFF_UP
%100 = and i32 %99, %98
%101 = icmp eq i32 %100, 0
br i1 %101, label %110, label %102
102: ; preds = %97
%103 = load i64, i64* %92
%104 = load i64, i64* @AF_INET
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %110
106: ; preds = %102
%107 = load i32, i32* @IFF_LOOPBACK
%108 = and i32 %107, %98
%109 = icmp eq i32 %108, 0
br i1 %109, label %57, label %110
110: ; preds = %97, %102, %106
%111 = load i32, i32* @IFF_LOOPBACK
%112 = and i32 %111, %98
%113 = icmp eq i32 %112, 0
br i1 %113, label %119, label %114
114: ; preds = %110
%115 = load i64, i64* %92
%116 = load i64, i64* @AF_INET
%117 = icmp ne i64 %115, %116
%118 = select i1 %117, i1 true, i1 %101
br i1 %118, label %119, label %57
119: ; preds = %114, %110
%120 = call i64 @ifreqSize(%struct.ifreq* %85)
%121 = load i32, i32* %11
%122 = trunc i64 %120 to i32
%123 = sub i32 %121, %122
store i32 %123, i32* %11
%124 = getelementptr inbounds i8, i8* %91, i64 %120
%125 = sext i32 %123 to i64
%126 = call i32 @memmove(%struct.ifreq* %85, i8* %124, i64 %125)
%127 = load i32, i32* %11
%128 = sext i32 %127 to i64
%129 = call i64 @ifreqSize(%struct.ifreq* %85)
%130 = icmp ugt i64 %129, %128
br i1 %130, label %131, label %93
131: ; preds = %119, %84, %57
%132 = phi i32 [ 0, %57 ], [ -1, %84 ], [ -1, %119 ]
%133 = call i32 @_RPC_close(i32 %8)
%134 = load i32, i32* %13
%135 = call i32 @free(i32 %134)
br label %136
136: ; preds = %1, %131, %40, %23, %21
%137 = phi i32 [ -1, %23 ], [ -1, %40 ], [ %132, %131 ], [ -1, %21 ], [ -1, %1 ]
ret i32 %137
}