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

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
char *gai_strerror(int);
int getifaddrs(struct ifaddrs **);
int getnameinfo(TYPE_1__ *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  struct ifaddrs *ifaddr, *ifa;
  int family, s;
  char host[NI_MAXHOST];
  if (getifaddrs(&ifaddr) == -1) {
    perror("getifaddrs");
    exit(EXIT_FAILURE);
  }
  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    family = ifa->ifa_addr->sa_family;
    printf("%s  address family: %d%s\n", ifa->ifa_name, family,
           (family == AF_INET)    ? " (AF_INET)"
           : (family == AF_INET6) ? " (AF_INET6)"
                                  : "");
    if (family == AF_INET || family == AF_INET6) {
      s = getnameinfo(ifa->ifa_addr,
                      (family == AF_INET) ? sizeof(struct sockaddr_in)
                                          : sizeof(struct sockaddr_in6),
                      host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
      if (s != 0) {
        printf("getnameinfo() failed: %s\n", gai_strerror(s));
        exit(EXIT_FAILURE);
      }
      printf("\taddress: <%s>\n", host);
    }
  }
  freeifaddrs(ifaddr);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x6e>
lea    0xe35(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     133b <main+0x1cb>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%eax
jne    1231 <main+0xc1>
lea    0xdfd(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1255 <main+0xe5>
mov    -0x24(%rbp),%edx
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rax
lea    0xde5(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x44(%rbp),%edx
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rcx
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
je     1292 <main+0x122>
mov    -0x24(%rbp),%eax
mov    0x2d56(%rip),%rcx
cmp    (%rcx),%eax
jne    1325 <main+0x1b5>
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x24(%rbp),%ecx
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2cfa(%rip),%rax
mov    (%rax),%ecx
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1313 <main+0x1a3>
mov    -0x28(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rsi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    132a <main+0x1ba>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11e6 <main+0x76>
mov    -0x18(%rbp),%rdi
call   1070 <freeifaddrs@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x30(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
lea    0xe53(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
jne    11d0 <main+0x60>
xor    %edi,%edi
jmp    129c <main+0x12c>
mov    0x2e11(%rip),%r15
mov    (%r15),%eax
mov    0x2dff(%rip),%r14
mov    (%r14),%ecx
jmp    11fd <main+0x8d>
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%r13),%r13
test   %r13,%r13
je     1298 <main+0x128>
mov    0x8(%r13),%rdx
mov    (%rdx),%ebx
cmp    %ecx,%ebx
lea    0xe59(%rip),%rcx
lea    0xe1d(%rip),%rdx
cmove  %rdx,%rcx
mov    0x0(%r13),%rsi
cmp    %eax,%ebx
lea    0xe01(%rip),%rax
cmove  %rax,%rcx
lea    0xddc(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%eax
cmp    %eax,%ebx
je     1246 <main+0xd6>
mov    (%r14),%ecx
cmp    %ecx,%ebx
jne    11f0 <main+0x80>
mov    0x8(%r13),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%ecx
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    $0x4,%esi
mov    %r12,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    12af <main+0x13f>
lea    0xdd3(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%eax
mov    (%r14),%ecx
jmp    11f0 <main+0x80>
mov    -0x30(%rbp),%rdi
call   1070 <freeifaddrs@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xd7f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b2 <main+0x42>

LLVM IR (-O0):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [11 x i8] c"getifaddrs\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"%s address family: %d%s\0A\00"
@AF_INET = global i32 0
@.str.2 = [11 x i8] c" (AF_INET)\00"
@AF_INET6 = global i32 0
@.str.3 = [12 x i8] c" (AF_INET6)\00"
@.str.4 = [1 x i8] zeroinitializer
@NI_NUMERICHOST = global i32 0
@.str.5 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.6 = [16 x i8] c"\09address: <%s>\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifaddrs*
%7 = alloca %struct.ifaddrs*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @NI_MAXHOST
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %10
%15 = alloca i8, i64 %13
store i64 %13, i64* %11
%16 = call i32 @getifaddrs(%struct.ifaddrs** %6)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %6
store %struct.ifaddrs* %23, %struct.ifaddrs** %7
br label %24
24: ; preds = %81, %22
%25 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%26 = icmp ne %struct.ifaddrs* %25, null
br i1 %26, label %27, label %85
27: ; preds = %24
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 1
%30 = load %struct.TYPE_2__*, %struct.TYPE_2__** %29
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
%32 = load i32, i32* %31
store i32 %32, i32* %8
%33 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%34 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = load i32, i32* %8
%37 = load i32, i32* %8
%38 = load i32, i32* @AF_INET
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %27
br label %47
41: ; preds = %27
%42 = load i32, i32* %8
%43 = load i32, i32* @AF_INET6
%44 = icmp eq i32 %42, %43
%45 = zext i1 %44 to i64
%46 = select i1 %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
br label %47
47: ; preds = %41, %40
%48 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %40 ], [ %46, %41 ]
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32 %36, i8* %48)
%50 = load i32, i32* %8
%51 = load i32, i32* @AF_INET
%52 = icmp eq i32 %50, %51
br i1 %52, label %57, label %53
53: ; preds = %47
%54 = load i32, i32* %8
%55 = load i32, i32* @AF_INET6
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %80
57: ; preds = %53, %47
%58 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%59 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %58, i32 0, i32 1
%60 = load %struct.TYPE_2__*, %struct.TYPE_2__** %59
%61 = load i32, i32* %8
%62 = load i32, i32* @AF_INET
%63 = icmp eq i32 %61, %62
%64 = zext i1 %63 to i64
%65 = select i1 %63, i64 4, i64 4
%66 = trunc i64 %65 to i32
%67 = load i32, i32* @NI_MAXHOST
%68 = load i32, i32* @NI_NUMERICHOST
%69 = call i32 @getnameinfo(%struct.TYPE_2__* %60, i32 %66, i8* %15, i32 %67, i32* null, i32 0, i32 %68)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %57
%73 = load i32, i32* %9
%74 = call i8* @gai_strerror(i32 %73)
%75 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %57
%79 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %15)
br label %80
80: ; preds = %78, %53
br label %81
81: ; preds = %80
%82 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%83 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %82, i32 0, i32 2
%84 = load %struct.ifaddrs*, %struct.ifaddrs** %83
store %struct.ifaddrs* %84, %struct.ifaddrs** %7
br label %24
85: ; preds = %24
%86 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%87 = call i32 @freeifaddrs(%struct.ifaddrs* %86)
%88 = load i32, i32* @EXIT_SUCCESS
%89 = call i32 @exit(i32 %88)
unreachable
}

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [11 x i8] c"getifaddrs\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"%s address family: %d%s\0A\00"
@AF_INET = global i32 0
@.str.2 = [11 x i8] c" (AF_INET)\00"
@AF_INET6 = global i32 0
@.str.3 = [12 x i8] c" (AF_INET6)\00"
@.str.4 = [1 x i8] zeroinitializer
@NI_NUMERICHOST = global i32 0
@.str.5 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.6 = [16 x i8] c"\09address: <%s>\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.ifaddrs*
%4 = bitcast %struct.ifaddrs** %3 to i8*
%5 = load i32, i32* @NI_MAXHOST
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%12 = icmp eq %struct.ifaddrs* %11, null
br i1 %12, label %63, label %13
13: ; preds = %10
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @AF_INET6
br label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %13, %55
%21 = phi i32 [ %56, %55 ], [ %15, %13 ]
%22 = phi i32 [ %57, %55 ], [ %14, %13 ]
%23 = phi %struct.ifaddrs* [ %59, %55 ], [ %11, %13 ]
%24 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %23, i64 0, i32 1
%25 = load %struct.TYPE_2__*, %struct.TYPE_2__** %24
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i64 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %23, i64 0, i32 0
%29 = load i8*, i8** %28
%30 = icmp eq i32 %27, %22
%31 = icmp eq i32 %27, %21
%32 = select i1 %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%33 = select i1 %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %32
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %27, i8* %33)
%35 = load i32, i32* @AF_INET
%36 = icmp eq i32 %27, %35
%37 = load i32, i32* @AF_INET6
%38 = icmp eq i32 %27, %37
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %40, label %55
40: ; preds = %20
%41 = load %struct.TYPE_2__*, %struct.TYPE_2__** %24
%42 = load i32, i32* @NI_MAXHOST
%43 = load i32, i32* @NI_NUMERICHOST
%44 = call i32 @getnameinfo(%struct.TYPE_2__* %41, i32 4, i8* %7, i32 %42, i32* null, i32 0, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %40
%47 = call i8* @gai_strerror(i32 %44)
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %40
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%53 = load i32, i32* @AF_INET
%54 = load i32, i32* @AF_INET6
br label %55
55: ; preds = %20, %51
%56 = phi i32 [ %37, %20 ], [ %54, %51 ]
%57 = phi i32 [ %35, %20 ], [ %53, %51 ]
%58 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %23, i64 0, i32 2
%59 = load %struct.ifaddrs*, %struct.ifaddrs** %58
%60 = icmp eq %struct.ifaddrs* %59, null
br i1 %60, label %61, label %20
61: ; preds = %55
%62 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br label %63
63: ; preds = %61, %10
%64 = phi %struct.ifaddrs* [ %62, %61 ], [ null, %10 ]
%65 = call i32 @freeifaddrs(%struct.ifaddrs* %64)
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}