#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 /*<<< 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)
      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("%s:%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    0x2e33(%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    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11e3 <main+0x73>
cmpq   $0x0,-0x18(%rbp)
je     12ee <main+0x17e>
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    12dd <main+0x16d>
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     1243 <main+0xd3>
jmp    12dd <main+0x16d>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%ecx
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%ecx
mov    0x2d60(%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     12c4 <main+0x154>
mov    -0x20(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd52(%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    0x2cd3(%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    0x2e3b(%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    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rax
test   %rax,%rax
jne    11d7 <main+0x67>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe2d(%rip),%r14
mov    0x2e03(%rip),%r13
mov    0x2dec(%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
jne    1200 <main+0x90>
mov    0x2d81(%rip),%rax
mov    (%rax),%ecx
mov    (%r12),%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    127b <main+0x10b>
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    0xd85(%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
@NI_NUMERICHOST = global i32 0
@.str.2 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.3 = [7 x i8] c"%s:%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 = %73, %21
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%24 = icmp ne %struct.ifaddrs* %23, null
br i1 %24, label %25, label %77
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 %73
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 %47
46: ; preds = %37
br label %73
47: ; preds = %37
%48 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%49 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %48, i32 0, i32 1
%50 = load %struct.TYPE_2__*, %struct.TYPE_2__** %49
%51 = load i32, i32* %7
%52 = load i32, i32* @AF_INET
%53 = icmp eq i32 %51, %52
%54 = zext i1 %53 to i64
%55 = select i1 %53, i64 4, i64 4
%56 = trunc i64 %55 to i32
%57 = load i32, i32* @NI_MAXHOST
%58 = load i32, i32* @NI_NUMERICHOST
%59 = call i32 @getnameinfo(%struct.TYPE_2__* %50, i32 %56, i8* %14, i32 %57, i32* null, i32 0, i32 %58)
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %47
%63 = load i32, i32* %8
%64 = call i8* @gai_strerror(i32 %63)
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %47
%69 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%70 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %71, i8* %14)
br label %73
73: ; preds = %68, %46, %36
%74 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%75 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %74, i32 0, i32 2
%76 = load %struct.ifaddrs*, %struct.ifaddrs** %75
store %struct.ifaddrs* %76, %struct.ifaddrs** %6
br label %22
77: ; preds = %22
%78 = load i32, i32* @EXIT_SUCCESS
%79 = call i32 @exit(i32 %78)
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
@NI_NUMERICHOST = global i32 0
@.str.2 = [26 x i8] c"getnameinfo() failed: %s\0A\00"
@.str.3 = [7 x i8] c"%s:%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 %55, label %17
17: ; preds = %14, %50
%18 = phi %struct.ifaddrs* [ %53, %50 ], [ %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 %50, 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 %50, 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
br i1 %34, label %35, label %50
35: ; preds = %27
%36 = load i32, i32* @NI_MAXHOST
%37 = load i32, i32* @NI_NUMERICHOST
%38 = call i32 @getnameinfo(%struct.TYPE_2__* %30, i32 4, i8* %7, i32 %36, i32* null, i32 0, i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = call i8* @gai_strerror(i32 %38)
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35
%46 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%47 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %46, i64 0, i32 0
%48 = load i8*, i8** %47
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %7)
br label %50
50: ; preds = %27, %17, %22, %45
%51 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%52 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %51, i64 0, i32 2
%53 = load %struct.ifaddrs*, %struct.ifaddrs** %52
store %struct.ifaddrs* %53, %struct.ifaddrs** %3
%54 = icmp eq %struct.ifaddrs* %53, null
br i1 %54, label %55, label %17
55: ; preds = %50, %14
%56 = load i32, i32* @EXIT_SUCCESS
%57 = call i32 @exit(i32 %56)
unreachable
}