#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*/);
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 *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  struct ifaddrs *ifaddr;
  int family, s;
  char host[NI_MAXHOST];
  if (getifaddrs(&ifaddr) == -1) {
    perror("getifaddrs");
    exit(EXIT_FAILURE);
  }
  for (; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
    if (ifaddr->ifa_addr == NULL || strcmp(ifaddr->ifa_name, "lo") == 0)
      continue;
    family = ifaddr->ifa_addr->sa_family;
    if (family != AF_INET && family != AF_INET6)
      continue;
    s = getnameinfo(ifaddr->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("%-16s %s\n", ifaddr->ifa_name, host);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <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>
jmp    11e3 <main+0x73>
cmpq   $0x0,-0x18(%rbp)
je     1300 <main+0x190>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     121a <main+0xaa>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe00(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0xaf>
jmp    12ef <main+0x17f>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%eax
je     1255 <main+0xe5>
mov    -0x1c(%rbp),%eax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%eax
je     1255 <main+0xe5>
jmp    12ef <main+0x17f>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%ecx
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2d37(%rip),%rax
mov    (%rax),%ecx
mov    0x2d46(%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,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12d6 <main+0x166>
mov    -0x20(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11e3 <main+0x73>
mov    0x2cb9(%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,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rdi
call   1070 <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),%rax
test   %rax,%rax
jne    11d7 <main+0x67>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe2d(%rip),%r14
mov    0x2e03(%rip),%r13
mov    0x2df4(%rip),%r12
lea    0xe35(%rip),%r15
jmp    1211 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
test   %rax,%rax
je     11c9 <main+0x59>
cmpq   $0x0,0x8(%rax)
je     1200 <main+0x90>
mov    (%rax),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x90>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
mov    (%rdi),%eax
cmp    0x0(%r13),%eax
je     123e <main+0xce>
cmp    (%r12),%eax
jne    1200 <main+0x90>
mov    0x2d73(%rip),%rax
mov    (%rax),%ecx
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1289 <main+0x119>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1200 <main+0x90>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xd77(%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 = [3 x i8] c"lo\00"
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.2 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.3 = [10 x i8] c"%-16s %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 i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @NI_MAXHOST
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = call i32 @getifaddrs(%struct.ifaddrs** %6)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %77, %21
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%24 = icmp ne %struct.ifaddrs* %23, null
br i1 %24, label %25, label %81
25: ; preds = %22
%26 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %26, i32 0, i32 1
%28 = load %struct.TYPE_2__*, %struct.TYPE_2__** %27
%29 = icmp eq %struct.TYPE_2__* %28, null
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%32 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30, %25
br label %77
37: ; preds = %30
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%39 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %38, i32 0, i32 1
%40 = load %struct.TYPE_2__*, %struct.TYPE_2__** %39
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
%42 = load i32, i32* %41
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = load i32, i32* @AF_INET
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %51
46: ; preds = %37
%47 = load i32, i32* %7
%48 = load i32, i32* @AF_INET6
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
br label %77
51: ; preds = %46, %37
%52 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%53 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %52, i32 0, i32 1
%54 = load %struct.TYPE_2__*, %struct.TYPE_2__** %53
%55 = load i32, i32* %7
%56 = load i32, i32* @AF_INET
%57 = icmp eq i32 %55, %56
%58 = zext i1 %57 to i64
%59 = select i1 %57, i64 4, i64 4
%60 = trunc i64 %59 to i32
%61 = load i32, i32* @NI_MAXHOST
%62 = load i32, i32* @NI_NUMERICHOST
%63 = call i32 @getnameinfo(%struct.TYPE_2__* %54, i32 %60, i8* %14, i32 %61, i32* null, i32 0, i32 %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %51
%67 = load i32, i32* %8
%68 = call i8* @gai_strerror(i32 %67)
%69 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %51
%73 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%74 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %73, i32 0, i32 0
%75 = load i8*, i8** %74
%76 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %14)
br label %77
77: ; preds = %72, %50, %36
%78 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%79 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %78, i32 0, i32 2
%80 = load %struct.ifaddrs*, %struct.ifaddrs** %79
store %struct.ifaddrs* %80, %struct.ifaddrs** %6
br label %22
81: ; preds = %22
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
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 = [3 x i8] c"lo\00"
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.2 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.3 = [10 x i8] c"%-16s %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 %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%16 = icmp eq %struct.ifaddrs* %15, null
br i1 %16, label %58, label %17
17: ; preds = %14, %53
%18 = phi %struct.ifaddrs* [ %56, %53 ], [ %15, %14 ]
%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 %53, label %22
22: ; preds = %17
%23 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %53, label %27
27: ; preds = %22
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i64 0, i32 1
%30 = load %struct.TYPE_2__*, %struct.TYPE_2__** %29
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i64 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* @AF_INET
%34 = icmp eq i32 %32, %33
%35 = load i32, i32* @AF_INET6
%36 = icmp eq i32 %32, %35
%37 = select i1 %34, i1 true, i1 %36
br i1 %37, label %38, label %53
38: ; preds = %27
%39 = load i32, i32* @NI_MAXHOST
%40 = load i32, i32* @NI_NUMERICHOST
%41 = call i32 @getnameinfo(%struct.TYPE_2__* %30, i32 4, i8* %7, i32 %39, i32* null, i32 0, i32 %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = call i8* @gai_strerror(i32 %41)
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %38
%49 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%50 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %49, i64 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %7)
br label %53
53: ; preds = %27, %17, %22, %48
%54 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%55 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %54, i64 0, i32 2
%56 = load %struct.ifaddrs*, %struct.ifaddrs** %55
store %struct.ifaddrs* %56, %struct.ifaddrs** %3
%57 = icmp eq %struct.ifaddrs* %56, null
br i1 %57, label %58, label %17
58: ; preds = %53, %14
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
}