#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;
  struct ifaddrs *ifa_next;
  TYPE_1__ *ifa_addr;
};
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);
  }
  while (ifaddr != NULL) {
    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);
    ifaddr = ifaddr->ifa_next;
  }
  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,0x10(%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    11e3 <main+0x73>
mov    -0x18(%rbp),%rax
mov    0x10(%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    11e3 <main+0x73>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%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    0x8(%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),%rcx
test   %rcx,%rcx
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    1205 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nop
test   %rcx,%rcx
je     11c9 <main+0x59>
cmpq   $0x0,0x10(%rcx)
je     1200 <main+0x90>
mov    (%rcx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
mov    -0x30(%rbp),%rcx
test   %rax,%rax
je     1200 <main+0x90>
mov    0x10(%rcx),%rdi
mov    (%rdi),%eax
cmp    0x0(%r13),%eax
je     1232 <main+0xc2>
cmp    (%r12),%eax
jne    1200 <main+0x90>
mov    0x2d7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8e(%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>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rcx
mov    %rcx,-0x30(%rbp)
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.ifaddrs*, %struct.TYPE_2__* }
%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 = %72, %50, %36, %21
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%24 = icmp ne %struct.ifaddrs* %23, null
br i1 %24, label %25, label %80
25: ; preds = %22
%26 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %26, i32 0, i32 2
%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 %22
37: ; preds = %30
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%39 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %38, i32 0, i32 2
%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 %22
51: ; preds = %46, %37
%52 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%53 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %52, i32 0, i32 2
%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)
%77 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%78 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %77, i32 0, i32 1
%79 = load %struct.ifaddrs*, %struct.ifaddrs** %78
store %struct.ifaddrs* %79, %struct.ifaddrs** %6
br label %22
80: ; preds = %22
%81 = load i32, i32* @EXIT_SUCCESS
%82 = call i32 @exit(i32 %81)
unreachable
}

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.ifaddrs*, %struct.TYPE_2__* }
%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 %13, label %10
10: ; preds = %2
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%12 = icmp eq %struct.ifaddrs* %11, null
br i1 %12, label %62, label %20
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 = %25, %31, %20
%18 = phi %struct.ifaddrs* [ %30, %31 ], [ %21, %20 ], [ %30, %25 ]
%19 = icmp eq %struct.ifaddrs* %18, null
br i1 %19, label %62, label %60
20: ; preds = %10, %60
%21 = phi %struct.ifaddrs* [ %61, %60 ], [ %11, %10 ]
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i64 0, i32 2
%23 = load %struct.TYPE_2__*, %struct.TYPE_2__** %22
%24 = icmp eq %struct.TYPE_2__* %23, null
br i1 %24, label %17, label %25
25: ; preds = %20
%26 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br i1 %29, label %17, label %31
31: ; preds = %25
%32 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %30, i64 0, i32 2
%33 = load %struct.TYPE_2__*, %struct.TYPE_2__** %32
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i64 0, i32 0
%35 = load i32, i32* %34
%36 = load i32, i32* @AF_INET
%37 = icmp eq i32 %35, %36
%38 = load i32, i32* @AF_INET6
%39 = icmp eq i32 %35, %38
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %41, label %17
41: ; preds = %31
%42 = load i32, i32* @NI_MAXHOST
%43 = load i32, i32* @NI_NUMERICHOST
%44 = call i32 @getnameinfo(%struct.TYPE_2__* %33, 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 = %41
%47 = call i8* @gai_strerror(i32 %44)
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %41
%52 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%53 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %52, i64 0, i32 0
%54 = load i8*, i8** %53
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %54, i8* %7)
%56 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%57 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %56, i64 0, i32 1
%58 = load %struct.ifaddrs*, %struct.ifaddrs** %57
store %struct.ifaddrs* %58, %struct.ifaddrs** %3
%59 = icmp eq %struct.ifaddrs* %58, null
br i1 %59, label %62, label %60
60: ; preds = %51, %17
%61 = phi %struct.ifaddrs* [ %58, %51 ], [ %18, %17 ]
br label %20
62: ; preds = %17, %51, %10
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
}