#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_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
struct ifaddrs {
  TYPE_1__ *ifa_addr;
  struct ifaddrs *ifa_next;
};
struct TYPE_2__ {
  int sa_family;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int getnameinfo(TYPE_1__ *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
char **malloc(int);
char **realloc(char **, int);
char *zstrdup(char *);
char **getLocalIpAddrs(void) {
  struct ifaddrs *ifaddr, *ifa;
  int family, s;
  char ip[NI_MAXHOST];
  char **addrs;
  int count, size = 5;
  if (getifaddrs(&ifaddr) == -1)
    return NULL;
  addrs = malloc(sizeof(char *) * (size + 1));
  count = 0;
  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    if (ifa->ifa_addr == NULL)
      continue;
    family = ifa->ifa_addr->sa_family;
    if (family == AF_INET || family == AF_INET6) {
      s = getnameinfo(ifa->ifa_addr,
                      (family == AF_INET) ? sizeof(struct sockaddr_in)
                                          : sizeof(struct sockaddr_in6),
                      ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
      if (s != 0) {
        continue;
      }
      if (size <= count) {
        size *= 2;
        addrs = realloc(addrs, sizeof(char *) * size + 1);
      }
      addrs[count++] = zstrdup(ip);
    }
  }
  freeifaddrs(ifaddr);
  if (count == 0) {
    free(addrs);
    return NULL;
  }
  addrs[count] = NULL;
  return addrs;
}


x86 assembly (clang, -O0):
<getLocalIpAddrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x5,-0x40(%rbp)
lea    -0x10(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    11d1 <getLocalIpAddrs+0x61>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    135a <getLocalIpAddrs+0x1ea>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     130b <getLocalIpAddrs+0x19b>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1215 <getLocalIpAddrs+0xa5>
jmp    12fa <getLocalIpAddrs+0x18a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
je     1245 <getLocalIpAddrs+0xd5>
mov    -0x1c(%rbp),%eax
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%eax
jne    12f5 <getLocalIpAddrs+0x185>
mov    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%ecx
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2d58(%rip),%rax
mov    (%rax),%ecx
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12a3 <getLocalIpAddrs+0x133>
jmp    12fa <getLocalIpAddrs+0x18a>
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jg     12d3 <getLocalIpAddrs+0x163>
mov    -0x40(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x3,%rax
add    $0x1,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
call   1090 <zstrdup@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x3c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    12fa <getLocalIpAddrs+0x18a>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11f7 <getLocalIpAddrs+0x87>
mov    -0x10(%rbp),%rdi
call   1080 <freeifaddrs@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    133b <getLocalIpAddrs+0x1cb>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    135a <getLocalIpAddrs+0x1ea>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLocalIpAddrs>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r14
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x48(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     12e1 <getLocalIpAddrs+0x171>
mov    $0x30,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    -0x48(%rbp),%r13
test   %r13,%r13
je     12cc <getLocalIpAddrs+0x15c>
mov    %r15,-0x30(%rbp)
mov    %r14,-0x50(%rbp)
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
mov    $0x5,%r15d
mov    0x2e03(%rip),%r14
mov    0x2ddc(%rip),%rbx
jmp    1229 <getLocalIpAddrs+0xb9>
xchg   %ax,%ax
mov    (%rbx),%ecx
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    $0x4,%esi
mov    %r12,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1246 <getLocalIpAddrs+0xd6>
nopl   0x0(%rax,%rax,1)
mov    0x8(%r13),%r13
test   %r13,%r13
je     12a6 <getLocalIpAddrs+0x136>
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     1220 <getLocalIpAddrs+0xb0>
mov    (%rdi),%eax
cmp    (%r14),%eax
je     11f0 <getLocalIpAddrs+0x80>
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
jne    1220 <getLocalIpAddrs+0xb0>
jmp    11f0 <getLocalIpAddrs+0x80>
mov    -0x38(%rbp),%rbx
cmp    %ebx,%r15d
jle    1255 <getLocalIpAddrs+0xe5>
mov    -0x30(%rbp),%r14
jmp    1279 <getLocalIpAddrs+0x109>
lea    (%r15,%r15,1),%eax
mov    %eax,-0x3c(%rbp)
shl    $0x4,%r15d
or     $0x1,%r15d
mov    -0x30(%rbp),%rdi
mov    %r15d,%esi
call   1070 <realloc@plt>
mov    %rax,%r14
mov    -0x3c(%rbp),%eax
mov    %eax,%r15d
mov    %r12,%rdi
call   1090 <zstrdup@plt>
movslq %ebx,%rcx
add    $0x1,%ebx
mov    %rbx,-0x38(%rbp)
mov    %r14,-0x30(%rbp)
mov    %rax,(%r14,%rcx,8)
mov    0x2d2e(%rip),%rbx
mov    0x2d47(%rip),%r14
jmp    1220 <getLocalIpAddrs+0xb0>
mov    -0x48(%rbp),%rdi
call   1080 <freeifaddrs@plt>
mov    -0x38(%rbp),%rax
test   %eax,%eax
mov    -0x50(%rbp),%r14
je     12d5 <getLocalIpAddrs+0x165>
movslq %eax,%rcx
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax,%rcx,8)
jmp    12e3 <getLocalIpAddrs+0x173>
xor    %edi,%edi
call   1080 <freeifaddrs@plt>
jmp    12d9 <getLocalIpAddrs+0x169>
mov    -0x30(%rbp),%r15
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@NI_MAXHOST = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
define i8** @getLocalIpAddrs() {
%1 = alloca i8**
%2 = alloca %struct.ifaddrs*
%3 = alloca %struct.ifaddrs*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = load i32, i32* @NI_MAXHOST
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
store i32 5, i32* %10
%16 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %0
store i8** null, i8*** %1
store i32 1, i32* %11
br label %105
19: ; preds = %0
%20 = load i32, i32* %10
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = trunc i64 %23 to i32
%25 = call i8** @malloc(i32 %24)
store i8** %25, i8*** %8
store i32 0, i32* %9
%26 = load %struct.ifaddrs*, %struct.ifaddrs** %2
store %struct.ifaddrs* %26, %struct.ifaddrs** %3
br label %27
27: ; preds = %87, %19
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%29 = icmp ne %struct.ifaddrs* %28, null
br i1 %29, label %30, label %91
30: ; preds = %27
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%32 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %31, i32 0, i32 0
%33 = load %struct.TYPE_2__*, %struct.TYPE_2__** %32
%34 = icmp eq %struct.TYPE_2__* %33, null
br i1 %34, label %35, label %36
35: ; preds = %30
br label %87
36: ; preds = %30
%37 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%38 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %37, i32 0, i32 0
%39 = load %struct.TYPE_2__*, %struct.TYPE_2__** %38
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
%41 = load i32, i32* %40
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = load i32, i32* @AF_INET
%44 = icmp eq i32 %42, %43
br i1 %44, label %49, label %45
45: ; preds = %36
%46 = load i32, i32* %4
%47 = load i32, i32* @AF_INET6
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %86
49: ; preds = %45, %36
%50 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%51 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %50, i32 0, i32 0
%52 = load %struct.TYPE_2__*, %struct.TYPE_2__** %51
%53 = load i32, i32* %4
%54 = load i32, i32* @AF_INET
%55 = icmp eq i32 %53, %54
%56 = zext i1 %55 to i64
%57 = select i1 %55, i64 4, i64 4
%58 = trunc i64 %57 to i32
%59 = load i32, i32* @NI_MAXHOST
%60 = load i32, i32* @NI_NUMERICHOST
%61 = call i32 @getnameinfo(%struct.TYPE_2__* %52, i32 %58, i8* %15, i32 %59, i32* null, i32 0, i32 %60)
store i32 %61, i32* %5
%62 = load i32, i32* %5
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %49
br label %87
65: ; preds = %49
%66 = load i32, i32* %10
%67 = load i32, i32* %9
%68 = icmp sle i32 %66, %67
br i1 %68, label %69, label %79
69: ; preds = %65
%70 = load i32, i32* %10
%71 = mul nsw i32 %70, 2
store i32 %71, i32* %10
%72 = load i8**, i8*** %8
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = mul i64 8, %74
%76 = add i64 %75, 1
%77 = trunc i64 %76 to i32
%78 = call i8** @realloc(i8** %72, i32 %77)
store i8** %78, i8*** %8
br label %79
79: ; preds = %69, %65
%80 = call i8* @zstrdup(i8* %15)
%81 = load i8**, i8*** %8
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i8*, i8** %81, i64 %84
store i8* %80, i8** %85
br label %86
86: ; preds = %79, %45
br label %87
87: ; preds = %86, %64, %35
%88 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%89 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %88, i32 0, i32 1
%90 = load %struct.ifaddrs*, %struct.ifaddrs** %89
store %struct.ifaddrs* %90, %struct.ifaddrs** %3
br label %27
91: ; preds = %27
%92 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%93 = call i32 @freeifaddrs(%struct.ifaddrs* %92)
%94 = load i32, i32* %9
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i8**, i8*** %8
%98 = call i32 @free(i8** %97)
store i8** null, i8*** %1
store i32 1, i32* %11
br label %105
99: ; preds = %91
%100 = load i8**, i8*** %8
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
store i8* null, i8** %103
%104 = load i8**, i8*** %8
store i8** %104, i8*** %1
store i32 1, i32* %11
br label %105
105: ; preds = %99, %96, %18
%106 = load i8*, i8** %6
%107 = load i8**, i8*** %1
ret i8** %107
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@NI_MAXHOST = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
define i8** @getLocalIpAddrs() {
%1 = alloca %struct.ifaddrs*
%2 = bitcast %struct.ifaddrs** %1 to i8*
%3 = load i32, i32* @NI_MAXHOST
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca i8, i64 %4
%7 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %67, label %9
9: ; preds = %0
%10 = call i8** @malloc(i32 48)
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%12 = icmp eq %struct.ifaddrs* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @freeifaddrs(%struct.ifaddrs* null)
br label %61
15: ; preds = %9, %50
%16 = phi %struct.ifaddrs* [ %55, %50 ], [ %11, %9 ]
%17 = phi i32 [ %53, %50 ], [ 5, %9 ]
%18 = phi i32 [ %52, %50 ], [ 0, %9 ]
%19 = phi i8** [ %51, %50 ], [ %10, %9 ]
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i64 0, i32 0
%21 = load %struct.TYPE_2__*, %struct.TYPE_2__** %20
%22 = icmp eq %struct.TYPE_2__* %21, null
br i1 %22, label %50, label %23
23: ; preds = %15
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i64 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @AF_INET
%27 = icmp eq i32 %25, %26
%28 = load i32, i32* @AF_INET6
%29 = icmp eq i32 %25, %28
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %31, label %50
31: ; preds = %23
%32 = load i32, i32* @NI_MAXHOST
%33 = load i32, i32* @NI_NUMERICHOST
%34 = call i32 @getnameinfo(%struct.TYPE_2__* %21, i32 4, i8* %6, i32 %32, i32* null, i32 0, i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %50
36: ; preds = %31
%37 = icmp sgt i32 %17, %18
br i1 %37, label %43, label %38
38: ; preds = %36
%39 = shl nsw i32 %17, 1
%40 = shl i32 %17, 4
%41 = or i32 %40, 1
%42 = call i8** @realloc(i8** %19, i32 %41)
br label %43
43: ; preds = %38, %36
%44 = phi i8** [ %42, %38 ], [ %19, %36 ]
%45 = phi i32 [ %39, %38 ], [ %17, %36 ]
%46 = call i8* @zstrdup(i8* %6)
%47 = add nsw i32 %18, 1
%48 = sext i32 %18 to i64
%49 = getelementptr inbounds i8*, i8** %44, i64 %48
store i8* %46, i8** %49
br label %50
50: ; preds = %23, %43, %31, %15
%51 = phi i8** [ %19, %15 ], [ %19, %31 ], [ %44, %43 ], [ %19, %23 ]
%52 = phi i32 [ %18, %15 ], [ %18, %31 ], [ %47, %43 ], [ %18, %23 ]
%53 = phi i32 [ %17, %15 ], [ %17, %31 ], [ %45, %43 ], [ %17, %23 ]
%54 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i64 0, i32 1
%55 = load %struct.ifaddrs*, %struct.ifaddrs** %54
%56 = icmp eq %struct.ifaddrs* %55, null
br i1 %56, label %57, label %15
57: ; preds = %50
%58 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%59 = call i32 @freeifaddrs(%struct.ifaddrs* %58)
%60 = icmp eq i32 %52, 0
br i1 %60, label %61, label %64
61: ; preds = %13, %57
%62 = phi i8** [ %10, %13 ], [ %51, %57 ]
%63 = call i32 @free(i8** %62)
br label %67
64: ; preds = %57
%65 = sext i32 %52 to i64
%66 = getelementptr inbounds i8*, i8** %51, i64 %65
store i8* null, i8** %66
br label %67
67: ; preds = %0, %64, %61
%68 = phi i8** [ null, %61 ], [ %51, %64 ], [ null, %0 ]
ret i8** %68
}