#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  unsigned int *s6_addr32;
};
struct sockaddr_in6 {
  TYPE_1__ sin6_addr;
};
struct ifaddrs {
  struct ifaddrs *ifa_next;
  TYPE_2__ *ifa_addr;
  TYPE_2__ *ifa_netmask;
  int /*<<< orphan*/ ifa_name;
};
struct hv_kvp_ipaddr_value {
  scalar_t__ sub_net;
  int /*<<< orphan*/ addr_family;
  scalar_t__ ip_addr;
};
struct TYPE_4__ {
  int sa_family;
};

/* Variables and functions */
int /*<<< orphan*/ ADDR_FAMILY_IPV4;
int /*<<< orphan*/ ADDR_FAMILY_IPV6;
int AF_INET;
int AF_INET6;
int HV_E_FAIL;
int KVP_OP_ENUMERATE;
int KVP_OP_GET_IP_INFO;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
scalar_t__ hweight32(unsigned int *);
int /*<<< orphan*/ kvp_get_ipconfig_info(char *, struct hv_kvp_ipaddr_value *);
int kvp_process_ip_address(TYPE_2__ *, int, char *, int, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int);
int kvp_get_ip_info(int family, char *if_name, int op, void *out_buffer,
                    int length) {
  struct ifaddrs *ifap;
  struct ifaddrs *curp;
  int offset = 0;
  int sn_offset = 0;
  int error = 0;
  char *buffer;
  struct hv_kvp_ipaddr_value *ip_buffer;
  char cidr_mask[5];
  int weight;
  int i;
  unsigned int *w;
  char *sn_str;
  struct sockaddr_in6 *addr6;
  if (op == KVP_OP_ENUMERATE) {
    buffer = out_buffer;
  } else {
    ip_buffer = out_buffer;
    buffer = (char *)ip_buffer->ip_addr;
    ip_buffer->addr_family = 0;
  }
  if (getifaddrs(&ifap)) {
    strcpy(buffer, "getifaddrs failed\n");
    return HV_E_FAIL;
  }
  curp = ifap;
  while (curp != NULL) {
    if (curp->ifa_addr == NULL) {
      curp = curp->ifa_next;
      continue;
    }
    if ((if_name != NULL) &&
        (strncmp(curp->ifa_name, if_name, strlen(if_name)))) {
      curp = curp->ifa_next;
      continue;
    }
    if ((family != 0) && (curp->ifa_addr->sa_family != family)) {
      curp = curp->ifa_next;
      continue;
    }
    if ((curp->ifa_addr->sa_family != AF_INET) &&
        (curp->ifa_addr->sa_family != AF_INET6)) {
      curp = curp->ifa_next;
      continue;
    }
    if (op == KVP_OP_GET_IP_INFO) {
      if (curp->ifa_addr->sa_family == AF_INET) {
        ip_buffer->addr_family |= ADDR_FAMILY_IPV4;
        error = kvp_process_ip_address(curp->ifa_netmask, AF_INET,
                                       (char *)ip_buffer->sub_net, length,
                                       &sn_offset);
        if (error)
          goto gather_ipaddr;
      } else {
        ip_buffer->addr_family |= ADDR_FAMILY_IPV6;
        weight = 0;
        sn_str = (char *)ip_buffer->sub_net;
        addr6 = (struct sockaddr_in6 *)curp->ifa_netmask;
        w = addr6->sin6_addr.s6_addr32;
        for (i = 0; i < 4; i++)
          weight += hweight32(&w[i]);
        sprintf(cidr_mask, "/%d", weight);
        if ((length - sn_offset) < (strlen(cidr_mask) + 1))
          goto gather_ipaddr;
        if (sn_offset == 0)
          strcpy(sn_str, cidr_mask);
        else
          strcat(sn_str, cidr_mask);
        strcat((char *)ip_buffer->sub_net, ";");
        sn_offset += strlen(sn_str) + 1;
      }
      kvp_get_ipconfig_info(if_name, ip_buffer);
    }
  gather_ipaddr:
    error = kvp_process_ip_address(curp->ifa_addr, curp->ifa_addr->sa_family,
                                   buffer, length, &offset);
    if (error)
      goto getaddr_done;
    curp = curp->ifa_next;
  }
getaddr_done:
  freeifaddrs(ifap);
  return error;
}


x86 assembly (clang, -O0):
<kvp_get_ip_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <kvp_get_ip_info+0x51>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1210 <kvp_get_ip_info+0x70>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rax
movl   $0x0,0x8(%rax)
lea    -0x30(%rbp),%rdi
call   1080 <getifaddrs@plt>
cmp    $0x0,%rax
je     1244 <kvp_get_ip_info+0xa4>
mov    -0x50(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    152c <kvp_get_ip_info+0x38c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1518 <kvp_get_ip_info+0x378>
mov    -0x38(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1276 <kvp_get_ip_info+0xd6>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124c <kvp_get_ip_info+0xac>
cmpq   $0x0,-0x10(%rbp)
je     12d0 <kvp_get_ip_info+0x130>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12d0 <kvp_get_ip_info+0x130>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124c <kvp_get_ip_info+0xac>
cmpl   $0x0,-0x8(%rbp)
je     12fd <kvp_get_ip_info+0x15d>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     12fd <kvp_get_ip_info+0x15d>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124c <kvp_get_ip_info+0xac>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    0x2cda(%rip),%rcx
cmp    (%rcx),%eax
je     133f <kvp_get_ip_info+0x19f>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    0x2ca1(%rip),%rcx
cmp    (%rcx),%eax
je     133f <kvp_get_ip_info+0x19f>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124c <kvp_get_ip_info+0xac>
mov    -0x14(%rbp),%eax
mov    0x2c67(%rip),%rcx
cmp    (%rcx),%eax
jne    14cf <kvp_get_ip_info+0x32f>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    0x2c86(%rip),%rcx
cmp    (%rcx),%eax
jne    13b8 <kvp_get_ip_info+0x218>
mov    0x2c67(%rip),%rax
mov    (%rax),%ecx
mov    -0x58(%rbp),%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c5c(%rip),%rax
mov    (%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
mov    -0x24(%rbp),%ecx
lea    -0x40(%rbp),%r8
call   1060 <kvp_process_ip_address@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     13b3 <kvp_get_ip_info+0x213>
jmp    14d4 <kvp_get_ip_info+0x334>
jmp    14c2 <kvp_get_ip_info+0x322>
mov    0x2c11(%rip),%rax
mov    (%rax),%ecx
mov    -0x58(%rbp),%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
movl   $0x0,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x4,-0x68(%rbp)
jge    1434 <kvp_get_ip_info+0x294>
mov    -0x70(%rbp),%rdi
movslq -0x68(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1070 <hweight32@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x64(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    13fb <kvp_get_ip_info+0x25b>
lea    -0x5d(%rbp),%rdi
mov    -0x64(%rbp),%edx
lea    0xbd1(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x24(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,-0x90(%rbp)
lea    -0x5d(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1474 <kvp_get_ip_info+0x2d4>
jmp    14d4 <kvp_get_ip_info+0x334>
cmpl   $0x0,-0x40(%rbp)
jne    1490 <kvp_get_ip_info+0x2f0>
mov    -0x78(%rbp),%rdi
lea    -0x5d(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    149d <kvp_get_ip_info+0x2fd>
mov    -0x78(%rbp),%rdi
lea    -0x5d(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xb6c(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x78(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   10a0 <kvp_get_ipconfig_info@plt>
jmp    14d4 <kvp_get_ip_info+0x334>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x50(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    -0x3c(%rbp),%r8
call   1060 <kvp_process_ip_address@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1508 <kvp_get_ip_info+0x368>
jmp    151d <kvp_get_ip_info+0x37d>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124c <kvp_get_ip_info+0xac>
jmp    151d <kvp_get_ip_info+0x37d>
mov    -0x30(%rbp),%rdi
call   1090 <freeifaddrs@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvp_get_ip_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%r13d
mov    %rcx,%r12
mov    %rsi,%rbp
mov    %edi,%r14d
movl   $0x0,0x24(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x2e0f(%rip),%rax
mov    %edx,0x20(%rsp)
cmp    %edx,(%rax)
jne    11db <kvp_get_ip_info+0x3b>
jmp    11f1 <kvp_get_ip_info+0x51>
mov    %r12,0x10(%rsp)
mov    0x10(%r12),%rax
movl   $0x0,0x8(%r12)
mov    %rax,%r12
lea    0x30(%rsp),%rdi
call   1080 <getifaddrs@plt>
test   %rax,%rax
je     121d <kvp_get_ip_info+0x7d>
lea    0xdf9(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%ebx
jmp    1400 <kvp_get_ip_info+0x260>
mov    0x30(%rsp),%r15
test   %r15,%r15
jne    12ac <kvp_get_ip_info+0x10c>
xor    %edi,%edi
xor    %ebx,%ebx
jmp    13fb <kvp_get_ip_info+0x25b>
mov    0x28(%rsp),%rbx
mov    %rbx,%rdi
lea    0xb(%rsp),%rsi
call   10b0 <strcat@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rdi
lea    0xdc2(%rip),%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0x4(%rsp),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
call   10a0 <kvp_get_ipconfig_info@plt>
mov    0x8(%r15),%rdi
mov    (%rdi),%esi
mov    %r12,%rdx
mov    %r13d,%ecx
lea    0x24(%rsp),%r8
call   1060 <kvp_process_ip_address@plt>
test   %eax,%eax
jne    1411 <kvp_get_ip_info+0x271>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%r15
test   %r15,%r15
je     13f4 <kvp_get_ip_info+0x254>
cmpq   $0x0,0x8(%r15)
je     12a0 <kvp_get_ip_info+0x100>
test   %rbp,%rbp
je     12d5 <kvp_get_ip_info+0x135>
mov    0x18(%r15),%ebx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    12a0 <kvp_get_ip_info+0x100>
mov    0x8(%r15),%rax
mov    (%rax),%esi
test   %r14d,%r14d
je     12e8 <kvp_get_ip_info+0x148>
cmp    %r14d,%esi
mov    %r14d,%esi
jne    12a0 <kvp_get_ip_info+0x100>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%esi
je     1300 <kvp_get_ip_info+0x160>
mov    0x2ccc(%rip),%rcx
cmp    (%rcx),%esi
jne    12a0 <kvp_get_ip_info+0x100>
mov    0x20(%rsp),%ecx
mov    0x2ca5(%rip),%rdx
cmp    %ecx,(%rdx)
jne    127c <kvp_get_ip_info+0xdc>
cmp    %eax,%esi
jne    1349 <kvp_get_ip_info+0x1a9>
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
mov    0x10(%rsp),%rcx
or     %eax,0x8(%rcx)
mov    0x10(%r15),%rdi
mov    (%rcx),%rdx
mov    %r13d,%ecx
lea    0x4(%rsp),%r8
call   1060 <kvp_process_ip_address@plt>
test   %eax,%eax
jne    127c <kvp_get_ip_info+0xdc>
jmp    126f <kvp_get_ip_info+0xcf>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    0x10(%rsp),%rcx
or     %eax,0x8(%rcx)
mov    (%rcx),%rax
mov    %rax,0x28(%rsp)
mov    0x10(%r15),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1070 <hweight32@plt>
mov    %r13d,0x1c(%rsp)
mov    %rax,%r13
lea    0x4(%rbx),%rdi
call   1070 <hweight32@plt>
add    %eax,%r13d
lea    0x8(%rbx),%rdi
call   1070 <hweight32@plt>
add    %eax,%r13d
add    $0xc,%rbx
mov    %rbx,%rdi
call   1070 <hweight32@plt>
add    %eax,%r13d
lea    0xb(%rsp),%rdi
lea    0xc67(%rip),%rsi
mov    %r13d,%edx
mov    0x1c(%rsp),%r13d
call   10c0 <sprintf@plt>
mov    %r13d,%ebx
sub    0x4(%rsp),%ebx
lea    0xb(%rsp),%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
jle    127c <kvp_get_ip_info+0xdc>
cmpl   $0x0,0x4(%rsp)
jne    1234 <kvp_get_ip_info+0x94>
mov    0x28(%rsp),%rbx
mov    %rbx,%rdi
lea    0xb(%rsp),%rsi
call   1040 <strcpy@plt>
jmp    1246 <kvp_get_ip_info+0xa6>
xor    %ebx,%ebx
mov    0x30(%rsp),%rdi
call   1090 <freeifaddrs@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
jmp    13f6 <kvp_get_ip_info+0x256>

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.ifaddrs*, %struct.TYPE_4__*, %struct.TYPE_4__*, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.hv_kvp_ipaddr_value = type { i64, i32, i64 }
%struct.sockaddr_in6 = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32* }
@KVP_OP_ENUMERATE = global i32 0
@.str = [19 x i8] c"getifaddrs failed\0A\00"
@HV_E_FAIL = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@KVP_OP_GET_IP_INFO = global i32 0
@ADDR_FAMILY_IPV4 = global i32 0
@ADDR_FAMILY_IPV6 = global i32 0
@.str.1 = [4 x i8] c"/%d\00"
@.str.2 = [2 x i8] c";\00"
define i32 @kvp_get_ip_info(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.ifaddrs*
%13 = alloca %struct.ifaddrs*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca %struct.hv_kvp_ipaddr_value*
%19 = alloca [5 x i8]
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i8*
%24 = alloca %struct.sockaddr_in6*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
%25 = load i32, i32* %9
%26 = load i32, i32* @KVP_OP_ENUMERATE
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %5
%29 = load i8*, i8** %10
store i8* %29, i8** %17
br label %39
30: ; preds = %5
%31 = load i8*, i8** %10
%32 = bitcast i8* %31 to %struct.hv_kvp_ipaddr_value*
store %struct.hv_kvp_ipaddr_value* %32, %struct.hv_kvp_ipaddr_value** %18
%33 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%34 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %33, i32 0, i32 2
%35 = load i64, i64* %34
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %17
%37 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%38 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %37, i32 0, i32 1
store i32 0, i32* %38
br label %39
39: ; preds = %30, %28
%40 = call i64 @getifaddrs(%struct.ifaddrs** %12)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i8*, i8** %17
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* @HV_E_FAIL
store i32 %45, i32* %6
br label %240
46: ; preds = %39
%47 = load %struct.ifaddrs*, %struct.ifaddrs** %12
store %struct.ifaddrs* %47, %struct.ifaddrs** %13
br label %48
48: ; preds = %231, %107, %87, %72, %56, %46
%49 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%50 = icmp ne %struct.ifaddrs* %49, null
br i1 %50, label %51, label %235
51: ; preds = %48
%52 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%53 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %52, i32 0, i32 1
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %53
%55 = icmp eq %struct.TYPE_4__* %54, null
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%58 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %57, i32 0, i32 0
%59 = load %struct.ifaddrs*, %struct.ifaddrs** %58
store %struct.ifaddrs* %59, %struct.ifaddrs** %13
br label %48
60: ; preds = %51
%61 = load i8*, i8** %8
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %76
63: ; preds = %60
%64 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%65 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %64, i32 0, i32 3
%66 = load i32, i32* %65
%67 = load i8*, i8** %8
%68 = load i8*, i8** %8
%69 = call i32 @strlen(i8* %68)
%70 = call i64 @strncmp(i32 %66, i8* %67, i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %63
%73 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%74 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %73, i32 0, i32 0
%75 = load %struct.ifaddrs*, %struct.ifaddrs** %74
store %struct.ifaddrs* %75, %struct.ifaddrs** %13
br label %48
76: ; preds = %63, %60
%77 = load i32, i32* %7
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %91
79: ; preds = %76
%80 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%81 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %80, i32 0, i32 1
%82 = load %struct.TYPE_4__*, %struct.TYPE_4__** %81
%83 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = load i32, i32* %7
%86 = icmp ne i32 %84, %85
br i1 %86, label %87, label %91
87: ; preds = %79
%88 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%89 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %88, i32 0, i32 0
%90 = load %struct.ifaddrs*, %struct.ifaddrs** %89
store %struct.ifaddrs* %90, %struct.ifaddrs** %13
br label %48
91: ; preds = %79, %76
%92 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%93 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %92, i32 0, i32 1
%94 = load %struct.TYPE_4__*, %struct.TYPE_4__** %93
%95 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %94, i32 0, i32 0
%96 = load i32, i32* %95
%97 = load i32, i32* @AF_INET
%98 = icmp ne i32 %96, %97
br i1 %98, label %99, label %111
99: ; preds = %91
%100 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%101 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %100, i32 0, i32 1
%102 = load %struct.TYPE_4__*, %struct.TYPE_4__** %101
%103 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %102, i32 0, i32 0
%104 = load i32, i32* %103
%105 = load i32, i32* @AF_INET6
%106 = icmp ne i32 %104, %105
br i1 %106, label %107, label %111
107: ; preds = %99
%108 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%109 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %108, i32 0, i32 0
%110 = load %struct.ifaddrs*, %struct.ifaddrs** %109
store %struct.ifaddrs* %110, %struct.ifaddrs** %13
br label %48
111: ; preds = %99, %91
%112 = load i32, i32* %9
%113 = load i32, i32* @KVP_OP_GET_IP_INFO
%114 = icmp eq i32 %112, %113
br i1 %114, label %115, label %215
115: ; preds = %111
%116 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%117 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %116, i32 0, i32 1
%118 = load %struct.TYPE_4__*, %struct.TYPE_4__** %117
%119 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %118, i32 0, i32 0
%120 = load i32, i32* %119
%121 = load i32, i32* @AF_INET
%122 = icmp eq i32 %120, %121
br i1 %122, label %123, label %143
123: ; preds = %115
%124 = load i32, i32* @ADDR_FAMILY_IPV4
%125 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%126 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %125, i32 0, i32 1
%127 = load i32, i32* %126
%128 = or i32 %127, %124
store i32 %128, i32* %126
%129 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%130 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %129, i32 0, i32 2
%131 = load %struct.TYPE_4__*, %struct.TYPE_4__** %130
%132 = load i32, i32* @AF_INET
%133 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%134 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %133, i32 0, i32 0
%135 = load i64, i64* %134
%136 = inttoptr i64 %135 to i8*
%137 = load i32, i32* %11
%138 = call i32 @kvp_process_ip_address(%struct.TYPE_4__* %131, i32 %132, i8* %136, i32 %137, i32* %15)
store i32 %138, i32* %16
%139 = load i32, i32* %16
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %123
br label %216
142: ; preds = %123
br label %211
143: ; preds = %115
%144 = load i32, i32* @ADDR_FAMILY_IPV6
%145 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%146 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %145, i32 0, i32 1
%147 = load i32, i32* %146
%148 = or i32 %147, %144
store i32 %148, i32* %146
store i32 0, i32* %20
%149 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%150 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %149, i32 0, i32 0
%151 = load i64, i64* %150
%152 = inttoptr i64 %151 to i8*
store i8* %152, i8** %23
%153 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%154 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %153, i32 0, i32 2
%155 = load %struct.TYPE_4__*, %struct.TYPE_4__** %154
%156 = bitcast %struct.TYPE_4__* %155 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %156, %struct.sockaddr_in6** %24
%157 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %24
%158 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %157, i32 0, i32 0
%159 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %158, i32 0, i32 0
%160 = load i32*, i32** %159
store i32* %160, i32** %22
store i32 0, i32* %21
br label %161
161: ; preds = %174, %143
%162 = load i32, i32* %21
%163 = icmp slt i32 %162, 4
br i1 %163, label %164, label %177
164: ; preds = %161
%165 = load i32*, i32** %22
%166 = load i32, i32* %21
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i32, i32* %165, i64 %167
%169 = call i64 @hweight32(i32* %168)
%170 = load i32, i32* %20
%171 = sext i32 %170 to i64
%172 = add nsw i64 %171, %169
%173 = trunc i64 %172 to i32
store i32 %173, i32* %20
br label %174
174: ; preds = %164
%175 = load i32, i32* %21
%176 = add nsw i32 %175, 1
store i32 %176, i32* %21
br label %161
177: ; preds = %161
%178 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%179 = load i32, i32* %20
%180 = call i32 @sprintf(i8* %178, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %179)
%181 = load i32, i32* %11
%182 = load i32, i32* %15
%183 = sub nsw i32 %181, %182
%184 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%185 = call i32 @strlen(i8* %184)
%186 = add nsw i32 %185, 1
%187 = icmp slt i32 %183, %186
br i1 %187, label %188, label %189
188: ; preds = %177
br label %216
189: ; preds = %177
%190 = load i32, i32* %15
%191 = icmp eq i32 %190, 0
br i1 %191, label %192, label %196
192: ; preds = %189
%193 = load i8*, i8** %23
%194 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%195 = call i32 @strcpy(i8* %193, i8* %194)
br label %200
196: ; preds = %189
%197 = load i8*, i8** %23
%198 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%199 = call i32 @strcat(i8* %197, i8* %198)
br label %200
200: ; preds = %196, %192
%201 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%202 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %201, i32 0, i32 0
%203 = load i64, i64* %202
%204 = inttoptr i64 %203 to i8*
%205 = call i32 @strcat(i8* %204, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%206 = load i8*, i8** %23
%207 = call i32 @strlen(i8* %206)
%208 = add nsw i32 %207, 1
%209 = load i32, i32* %15
%210 = add nsw i32 %209, %208
store i32 %210, i32* %15
br label %211
211: ; preds = %200, %142
%212 = load i8*, i8** %8
%213 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %18
%214 = call i32 @kvp_get_ipconfig_info(i8* %212, %struct.hv_kvp_ipaddr_value* %213)
br label %215
215: ; preds = %211, %111
br label %216
216: ; preds = %215, %188, %141
%217 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%218 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %217, i32 0, i32 1
%219 = load %struct.TYPE_4__*, %struct.TYPE_4__** %218
%220 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%221 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %220, i32 0, i32 1
%222 = load %struct.TYPE_4__*, %struct.TYPE_4__** %221
%223 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %222, i32 0, i32 0
%224 = load i32, i32* %223
%225 = load i8*, i8** %17
%226 = load i32, i32* %11
%227 = call i32 @kvp_process_ip_address(%struct.TYPE_4__* %219, i32 %224, i8* %225, i32 %226, i32* %14)
store i32 %227, i32* %16
%228 = load i32, i32* %16
%229 = icmp ne i32 %228, 0
br i1 %229, label %230, label %231
230: ; preds = %216
br label %236
231: ; preds = %216
%232 = load %struct.ifaddrs*, %struct.ifaddrs** %13
%233 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %232, i32 0, i32 0
%234 = load %struct.ifaddrs*, %struct.ifaddrs** %233
store %struct.ifaddrs* %234, %struct.ifaddrs** %13
br label %48
235: ; preds = %48
br label %236
236: ; preds = %235, %230
%237 = load %struct.ifaddrs*, %struct.ifaddrs** %12
%238 = call i32 @freeifaddrs(%struct.ifaddrs* %237)
%239 = load i32, i32* %16
store i32 %239, i32* %6
br label %240
240: ; preds = %236, %42
%241 = load i32, i32* %6
ret i32 %241
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.ifaddrs*, %struct.TYPE_4__*, %struct.TYPE_4__*, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.hv_kvp_ipaddr_value = type { i64, i32, i64 }
%struct.sockaddr_in6 = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32* }
@KVP_OP_ENUMERATE = global i32 0
@.str = [19 x i8] c"getifaddrs failed\0A\00"
@HV_E_FAIL = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@KVP_OP_GET_IP_INFO = global i32 0
@ADDR_FAMILY_IPV4 = global i32 0
@ADDR_FAMILY_IPV6 = global i32 0
@.str.1 = [4 x i8] c"/%d\00"
@.str.2 = [2 x i8] c";\00"
define i32 @kvp_get_ip_info(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca %struct.ifaddrs*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [5 x i8]
%10 = bitcast %struct.ifaddrs** %6 to i8*
%11 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%12 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%14 = load i32, i32* @KVP_OP_ENUMERATE
%15 = icmp eq i32 %14, %2
br i1 %15, label %24, label %16
16: ; preds = %5
%17 = bitcast i8* %3 to %struct.hv_kvp_ipaddr_value*
%18 = getelementptr inbounds i8, i8* %3, i64 16
%19 = bitcast i8* %18 to i64*
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i8*
%22 = getelementptr inbounds i8, i8* %3, i64 8
%23 = bitcast i8* %22 to i32*
store i32 0, i32* %23
br label %24
24: ; preds = %5, %16
%25 = phi i8* [ %21, %16 ], [ %3, %5 ]
%26 = phi %struct.hv_kvp_ipaddr_value* [ %17, %16 ], [ undef, %5 ]
%27 = call i64 @getifaddrs(%struct.ifaddrs** %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%31 = icmp eq %struct.ifaddrs* %30, null
br i1 %31, label %139, label %32
32: ; preds = %29
%33 = icmp eq i8* %1, null
%34 = icmp eq i32 %0, 0
%35 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %26, i64 0, i32 1
%36 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %26, i64 0, i32 0
br label %40
37: ; preds = %24
%38 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @HV_E_FAIL
br label %143
40: ; preds = %32, %45
%41 = phi %struct.ifaddrs* [ %30, %32 ], [ %47, %45 ]
%42 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %41, i64 0, i32 1
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %42
%44 = icmp eq %struct.TYPE_4__* %43, null
br i1 %44, label %45, label %49
45: ; preds = %130, %62, %60, %50, %40
%46 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %41, i64 0, i32 0
%47 = load %struct.ifaddrs*, %struct.ifaddrs** %46
%48 = icmp eq %struct.ifaddrs* %47, null
br i1 %48, label %136, label %40
49: ; preds = %40
br i1 %33, label %56, label %50
50: ; preds = %49
%51 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %41, i64 0, i32 3
%52 = load i32, i32* %51
%53 = call i32 @strlen(i8* %1)
%54 = call i64 @strncmp(i32 %52, i8* %1, i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %45
56: ; preds = %50, %49
%57 = load %struct.TYPE_4__*, %struct.TYPE_4__** %42
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i64 0, i32 0
%59 = load i32, i32* %58
br i1 %34, label %62, label %60
60: ; preds = %56
%61 = icmp eq i32 %59, %0
br i1 %61, label %62, label %45
62: ; preds = %56, %60
%63 = phi i32 [ %0, %60 ], [ %59, %56 ]
%64 = load i32, i32* @AF_INET
%65 = icmp eq i32 %63, %64
%66 = load i32, i32* @AF_INET6
%67 = icmp eq i32 %63, %66
%68 = select i1 %65, i1 true, i1 %67
br i1 %68, label %69, label %45
69: ; preds = %62
%70 = load i32, i32* @KVP_OP_GET_IP_INFO
%71 = icmp eq i32 %70, %2
br i1 %71, label %72, label %130
72: ; preds = %69
br i1 %65, label %73, label %83
73: ; preds = %72
%74 = load i32, i32* @ADDR_FAMILY_IPV4
%75 = load i32, i32* %35
%76 = or i32 %75, %74
store i32 %76, i32* %35
%77 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %41, i64 0, i32 2
%78 = load %struct.TYPE_4__*, %struct.TYPE_4__** %77
%79 = load i64, i64* %36
%80 = inttoptr i64 %79 to i8*
%81 = call i32 @kvp_process_ip_address(%struct.TYPE_4__* %78, i32 %63, i8* %80, i32 %4, i32* %8)
%82 = icmp eq i32 %81, 0
br i1 %82, label %128, label %130
83: ; preds = %72
%84 = load i32, i32* @ADDR_FAMILY_IPV6
%85 = load i32, i32* %35
%86 = or i32 %85, %84
store i32 %86, i32* %35
%87 = load i64, i64* %36
%88 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %41, i64 0, i32 2
%89 = bitcast %struct.TYPE_4__** %88 to %struct.sockaddr_in6**
%90 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %89
%91 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %90, i64 0, i32 0, i32 0
%92 = load i32*, i32** %91
%93 = call i64 @hweight32(i32* %92)
%94 = trunc i64 %93 to i32
%95 = getelementptr inbounds i32, i32* %92, i64 1
%96 = call i64 @hweight32(i32* %95)
%97 = trunc i64 %96 to i32
%98 = add i32 %94, %97
%99 = getelementptr inbounds i32, i32* %92, i64 2
%100 = call i64 @hweight32(i32* %99)
%101 = trunc i64 %100 to i32
%102 = add i32 %98, %101
%103 = getelementptr inbounds i32, i32* %92, i64 3
%104 = call i64 @hweight32(i32* %103)
%105 = trunc i64 %104 to i32
%106 = add i32 %102, %105
%107 = inttoptr i64 %87 to i8*
%108 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %106)
%109 = load i32, i32* %8
%110 = sub nsw i32 %4, %109
%111 = call i32 @strlen(i8* %13)
%112 = icmp sgt i32 %110, %111
br i1 %112, label %113, label %130
113: ; preds = %83
%114 = load i32, i32* %8
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %113
%117 = call i32 @strcpy(i8* %107, i8* %13)
br label %120
118: ; preds = %113
%119 = call i32 @strcat(i8* %107, i8* %13)
br label %120
120: ; preds = %118, %116
%121 = load i64, i64* %36
%122 = inttoptr i64 %121 to i8*
%123 = call i32 @strcat(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%124 = call i32 @strlen(i8* %107)
%125 = add nsw i32 %124, 1
%126 = load i32, i32* %8
%127 = add nsw i32 %125, %126
store i32 %127, i32* %8
br label %128
128: ; preds = %73, %120
%129 = call i32 @kvp_get_ipconfig_info(i8* %1, %struct.hv_kvp_ipaddr_value* %26)
br label %130
130: ; preds = %69, %128, %83, %73
%131 = load %struct.TYPE_4__*, %struct.TYPE_4__** %42
%132 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %131, i64 0, i32 0
%133 = load i32, i32* %132
%134 = call i32 @kvp_process_ip_address(%struct.TYPE_4__* %131, i32 %133, i8* %25, i32 %4, i32* %7)
%135 = icmp eq i32 %134, 0
br i1 %135, label %45, label %136
136: ; preds = %45, %130
%137 = phi i32 [ %134, %130 ], [ 0, %45 ]
%138 = load %struct.ifaddrs*, %struct.ifaddrs** %6
br label %139
139: ; preds = %136, %29
%140 = phi %struct.ifaddrs* [ null, %29 ], [ %138, %136 ]
%141 = phi i32 [ 0, %29 ], [ %137, %136 ]
%142 = call i32 @freeifaddrs(%struct.ifaddrs* %140)
br label %143
143: ; preds = %139, %37
%144 = phi i32 [ %39, %37 ], [ %141, %139 ]
ret i32 %144
}