#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 AF_PACKET;
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) {
    if (ifa->ifa_addr == NULL)
      continue;
    family = ifa->ifa_addr->sa_family;
    printf("%s  address family: %d%s\n", ifa->ifa_name, family,
           (family == AF_PACKET)  ? " (AF_PACKET)"
           : (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    0x2e23(%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    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1379 <main+0x209>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1205 <main+0x95>
jmp    1368 <main+0x1f8>
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    0x2da3(%rip),%rcx
cmp    (%rcx),%eax
jne    1245 <main+0xd5>
lea    0xde9(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1293 <main+0x123>
mov    -0x24(%rbp),%eax
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%eax
jne    1267 <main+0xf7>
lea    0xdd4(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    128b <main+0x11b>
mov    -0x24(%rbp),%edx
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rax
lea    0xdbc(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x44(%rbp),%edx
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rcx
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%eax
je     12d0 <main+0x160>
mov    -0x24(%rbp),%eax
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%eax
jne    1363 <main+0x1f3>
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x24(%rbp),%ecx
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2cb4(%rip),%rax
mov    (%rax),%ecx
mov    0x2cc3(%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     1351 <main+0x1e1>
mov    -0x28(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rsi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1368 <main+0x1f8>
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    0x2c2f(%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    0x2e2b(%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    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
jne    11d0 <main+0x60>
xor    %edi,%edi
jmp    129e <main+0x12e>
mov    0x2e11(%rip),%r15
mov    0x2e02(%rip),%r14
jmp    11ed <main+0x7d>
mov    0x10(%r13),%r13
test   %r13,%r13
je     129a <main+0x12a>
mov    0x8(%r13),%rax
test   %rax,%rax
je     11e0 <main+0x70>
mov    (%rax),%ebx
lea    0xe26(%rip),%rcx
mov    0x2dca(%rip),%rax
cmp    (%rax),%ebx
je     1230 <main+0xc0>
lea    0xe21(%rip),%rcx
cmp    (%r15),%ebx
je     1230 <main+0xc0>
lea    0xe20(%rip),%rcx
cmp    (%r14),%ebx
je     1230 <main+0xc0>
lea    0xe49(%rip),%rcx
nopl   0x0(%rax)
mov    0x0(%r13),%rsi
lea    0xdd0(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    (%r15),%ebx
je     124e <main+0xde>
cmp    (%r14),%ebx
jne    11e0 <main+0x70>
mov    0x8(%r13),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%ecx
mov    0x2d66(%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    12b1 <main+0x141>
lea    0xdd8(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11e0 <main+0x70>
mov    -0x30(%rbp),%rdi
call   1070 <freeifaddrs@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xd8a(%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_PACKET = global i32 0
@.str.2 = [13 x i8] c" (AF_PACKET)\00"
@AF_INET = global i32 0
@.str.3 = [11 x i8] c" (AF_INET)\00"
@AF_INET6 = global i32 0
@.str.4 = [12 x i8] c" (AF_INET6)\00"
@.str.5 = [1 x i8] zeroinitializer
@NI_NUMERICHOST = global i32 0
@.str.6 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.7 = [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 = %94, %22
%25 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%26 = icmp ne %struct.ifaddrs* %25, null
br i1 %26, label %27, label %98
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 = icmp eq %struct.TYPE_2__* %30, null
br i1 %31, label %32, label %33
32: ; preds = %27
br label %94
33: ; preds = %27
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%35 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %34, i32 0, i32 1
%36 = load %struct.TYPE_2__*, %struct.TYPE_2__** %35
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
%38 = load i32, i32* %37
store i32 %38, i32* %8
%39 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%40 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = load i32, i32* %8
%43 = load i32, i32* %8
%44 = load i32, i32* @AF_PACKET
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %33
br label %60
47: ; preds = %33
%48 = load i32, i32* %8
%49 = load i32, i32* @AF_INET
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47
br label %58
52: ; preds = %47
%53 = load i32, i32* %8
%54 = load i32, i32* @AF_INET6
%55 = icmp eq i32 %53, %54
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
br label %58
58: ; preds = %52, %51
%59 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %51 ], [ %57, %52 ]
br label %60
60: ; preds = %58, %46
%61 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %46 ], [ %59, %58 ]
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32 %42, i8* %61)
%63 = load i32, i32* %8
%64 = load i32, i32* @AF_INET
%65 = icmp eq i32 %63, %64
br i1 %65, label %70, label %66
66: ; preds = %60
%67 = load i32, i32* %8
%68 = load i32, i32* @AF_INET6
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %93
70: ; preds = %66, %60
%71 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%72 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %71, i32 0, i32 1
%73 = load %struct.TYPE_2__*, %struct.TYPE_2__** %72
%74 = load i32, i32* %8
%75 = load i32, i32* @AF_INET
%76 = icmp eq i32 %74, %75
%77 = zext i1 %76 to i64
%78 = select i1 %76, i64 4, i64 4
%79 = trunc i64 %78 to i32
%80 = load i32, i32* @NI_MAXHOST
%81 = load i32, i32* @NI_NUMERICHOST
%82 = call i32 @getnameinfo(%struct.TYPE_2__* %73, i32 %79, i8* %15, i32 %80, i32* null, i32 0, i32 %81)
store i32 %82, i32* %9
%83 = load i32, i32* %9
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %91
85: ; preds = %70
%86 = load i32, i32* %9
%87 = call i8* @gai_strerror(i32 %86)
%88 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %87)
%89 = load i32, i32* @EXIT_FAILURE
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %70
%92 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %15)
br label %93
93: ; preds = %91, %66
br label %94
94: ; preds = %93, %32
%95 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%96 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %95, i32 0, i32 2
%97 = load %struct.ifaddrs*, %struct.ifaddrs** %96
store %struct.ifaddrs* %97, %struct.ifaddrs** %7
br label %24
98: ; preds = %24
%99 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%100 = call i32 @freeifaddrs(%struct.ifaddrs* %99)
%101 = load i32, i32* @EXIT_SUCCESS
%102 = call i32 @exit(i32 %101)
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_PACKET = global i32 0
@.str.2 = [13 x i8] c" (AF_PACKET)\00"
@AF_INET = global i32 0
@.str.3 = [11 x i8] c" (AF_INET)\00"
@AF_INET6 = global i32 0
@.str.4 = [12 x i8] c" (AF_INET6)\00"
@.str.5 = [1 x i8] zeroinitializer
@NI_NUMERICHOST = global i32 0
@.str.6 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.7 = [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 %13, 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 %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %10, %57
%18 = phi %struct.ifaddrs* [ %59, %57 ], [ %11, %10 ]
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 1
%20 = load %struct.TYPE_2__*, %struct.TYPE_2__** %19
%21 = icmp eq %struct.TYPE_2__* %20, null
br i1 %21, label %57, label %22
22: ; preds = %17
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = load i32, i32* @AF_PACKET
%28 = icmp eq i32 %24, %27
br i1 %28, label %36, label %29
29: ; preds = %22
%30 = load i32, i32* @AF_INET
%31 = icmp eq i32 %24, %30
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i32, i32* @AF_INET6
%34 = icmp eq i32 %24, %33
%35 = select i1 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
br label %36
36: ; preds = %32, %29, %22
%37 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %22 ], [ %35, %32 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %29 ]
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %24, i8* %37)
%39 = load i32, i32* @AF_INET
%40 = icmp eq i32 %24, %39
%41 = load i32, i32* @AF_INET6
%42 = icmp eq i32 %24, %41
%43 = select i1 %40, i1 true, i1 %42
br i1 %43, label %44, label %57
44: ; preds = %36
%45 = load %struct.TYPE_2__*, %struct.TYPE_2__** %19
%46 = load i32, i32* @NI_MAXHOST
%47 = load i32, i32* @NI_NUMERICHOST
%48 = call i32 @getnameinfo(%struct.TYPE_2__* %45, i32 4, i8* %7, i32 %46, i32* null, i32 0, i32 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %44
%51 = call i8* @gai_strerror(i32 %48)
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %7)
br label %57
57: ; preds = %36, %55, %17
%58 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 2
%59 = load %struct.ifaddrs*, %struct.ifaddrs** %58
%60 = icmp eq %struct.ifaddrs* %59, null
br i1 %60, label %61, label %17
61: ; preds = %57
%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
}