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

/* Variables and functions */
int AF_INET;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int getnameinfo(TYPE_1__ *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
char *smprintf(char *, char *, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *getaddr() {
  int family, s, n;
  struct ifaddrs *ifaddr, *ifa;
  if (getifaddrs(&ifaddr) == -1) {
    fprintf(stderr, "getaddr: getifaddrs returned -1");
  }
  char host[NI_MAXHOST];
  char *ret_host = NULL;
  for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
    if ((ifa->ifa_addr == NULL) || (strcmp(ifa->ifa_name, "lo") == 0))
      continue;
    family = ifa->ifa_addr->sa_family;
    if (family == AF_INET) {
      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) {
        freeifaddrs(ifaddr);
        fprintf(stderr, "getnameinfo() failed.\n");
        return NULL;
      }
      if (ret_host == NULL) {
        ret_host = smprintf("%s: %s", ifa->ifa_name, host);
      } else {
        char *temp_host = ret_host;
        ret_host = smprintf("%s , %s: %s", ret_host, ifa->ifa_name, host);
        free(temp_host);
      }
    }
  }
  freeifaddrs(ifaddr);
  return ret_host;
}


x86 assembly (clang, -O0):
<getaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x20(%rbp),%rdi
call   1080 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    119f <getaddr+0x2f>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e22(%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,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     134b <getaddr+0x1db>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1218 <getaddr+0xa8>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121d <getaddr+0xad>
jmp    1331 <getaddr+0x1c1>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%eax
jne    132c <getaddr+0x1bc>
mov    -0x58(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0xc(%rbp),%ecx
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%eax
cmp    %esi,%ecx
cmove  %rax,%rax
mov    %eax,%esi
mov    0x2d60(%rip),%rax
mov    (%rax),%ecx
mov    0x2d5f(%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,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     12c8 <getaddr+0x158>
mov    -0x20(%rbp),%rdi
call   1090 <freeifaddrs@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1363 <getaddr+0x1f3>
cmpq   $0x0,-0x40(%rbp)
jne    12f5 <getaddr+0x185>
mov    -0x58(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq (%rax),%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x40(%rbp)
jmp    1327 <getaddr+0x1b7>
mov    -0x58(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rax
movslq (%rax),%rdx
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
jmp    132c <getaddr+0x1bc>
jmp    1331 <getaddr+0x1c1>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e2 <getaddr+0x72>
mov    -0x20(%rbp),%rdi
call   1090 <freeifaddrs@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    -0x30(%rbp),%rdi
call   1080 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    11a4 <getaddr+0x34>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rsp,%rbx
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x30(%rbp),%r13
test   %r13,%r13
je     12ae <getaddr+0x13e>
mov    %rbx,-0x38(%rbp)
lea    0xe47(%rip),%rbx
mov    0x2e08(%rip),%r15
xor    %r12d,%r12d
jmp    1229 <getaddr+0xb9>
lea    0xe4e(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <smprintf@plt>
mov    %r12,%rdi
mov    %r14,%r12
mov    %rbx,%r14
mov    %rax,%rbx
call   1030 <free@plt>
mov    %rbx,%rax
mov    %r14,%rbx
mov    %r12,%r14
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%r13),%r13
test   %r13,%r13
je     12a4 <getaddr+0x134>
cmpq   $0x0,0x8(%r13)
je     1220 <getaddr+0xb0>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1220 <getaddr+0xb0>
mov    0x8(%r13),%rdi
mov    (%rdi),%eax
cmp    (%r15),%eax
jne    1220 <getaddr+0xb0>
mov    0x2d75(%rip),%rax
mov    (%rax),%ecx
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    $0x4,%esi
mov    %r14,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    12cd <getaddr+0x15d>
movslq 0x0(%r13),%rdx
test   %r12,%r12
jne    11e5 <getaddr+0x75>
lea    0xdad(%rip),%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <smprintf@plt>
jmp    1213 <getaddr+0xa3>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rbx
jmp    12b3 <getaddr+0x143>
xor    %edi,%edi
xor    %r12d,%r12d
call   1090 <freeifaddrs@plt>
mov    %rbx,%rsp
mov    %r12,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x30(%rbp),%rdi
call   1090 <freeifaddrs@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   1070 <fprintf@plt>
xor    %r12d,%r12d
mov    -0x38(%rbp),%rbx
jmp    12b8 <getaddr+0x148>

LLVM IR (-O0):
%struct.ifaddrs = type { i32, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"getaddr: getifaddrs returned -1\00"
@NI_MAXHOST = global i32 0
@.str.1 = [3 x i8] c"lo\00"
@AF_INET = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.2 = [23 x i8] c"getnameinfo() failed.\0A\00"
@.str.3 = [7 x i8] c"%s: %s\00"
@.str.4 = [12 x i8] c"%s , %s: %s\00"
define i8* @getaddr() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.ifaddrs*
%6 = alloca %struct.ifaddrs*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = call i32 @getifaddrs(%struct.ifaddrs** %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %0
%18 = load i32, i32* @NI_MAXHOST
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8, i64 %19
store i64 %19, i64* %8
store i8* null, i8** %9
%22 = load %struct.ifaddrs*, %struct.ifaddrs** %5
store %struct.ifaddrs* %22, %struct.ifaddrs** %6
store i32 0, i32* %4
br label %23
23: ; preds = %90, %17
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%25 = icmp ne %struct.ifaddrs* %24, null
br i1 %25, label %26, label %96
26: ; preds = %23
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%28 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %27, i32 0, i32 1
%29 = load %struct.TYPE_2__*, %struct.TYPE_2__** %28
%30 = icmp eq %struct.TYPE_2__* %29, null
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%33 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @strcmp(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31, %26
br label %90
38: ; preds = %31
%39 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%40 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %39, i32 0, i32 1
%41 = load %struct.TYPE_2__*, %struct.TYPE_2__** %40
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
%43 = load i32, i32* %42
store i32 %43, i32* %2
%44 = load i32, i32* %2
%45 = load i32, i32* @AF_INET
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %89
47: ; preds = %38
%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* %2
%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* %21, i32 %57, i32* null, i32 0, i32 %58)
store i32 %59, i32* %3
%60 = load i32, i32* %3
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %47
%63 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%64 = call i32 @freeifaddrs(%struct.ifaddrs* %63)
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
store i32 1, i32* %10
br label %100
67: ; preds = %47
%68 = load i8*, i8** %9
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %77
70: ; preds = %67
%71 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%72 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = sext i32 %73 to i64
%75 = inttoptr i64 %74 to i8*
%76 = call i8* (i8*, i8*, i8*, ...) @smprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %21)
store i8* %76, i8** %9
br label %88
77: ; preds = %67
%78 = load i8*, i8** %9
store i8* %78, i8** %11
%79 = load i8*, i8** %9
%80 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%81 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = sext i32 %82 to i64
%84 = inttoptr i64 %83 to i8*
%85 = call i8* (i8*, i8*, i8*, ...) @smprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %79, i8* %84, i8* %21)
store i8* %85, i8** %9
%86 = load i8*, i8** %11
%87 = call i32 @free(i8* %86)
br label %88
88: ; preds = %77, %70
br label %89
89: ; preds = %88, %38
br label %90
90: ; preds = %89, %37
%91 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%92 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %91, i32 0, i32 2
%93 = load %struct.ifaddrs*, %struct.ifaddrs** %92
store %struct.ifaddrs* %93, %struct.ifaddrs** %6
%94 = load i32, i32* %4
%95 = add nsw i32 %94, 1
store i32 %95, i32* %4
br label %23
96: ; preds = %23
%97 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%98 = call i32 @freeifaddrs(%struct.ifaddrs* %97)
%99 = load i8*, i8** %9
store i8* %99, i8** %1
store i32 1, i32* %10
br label %100
100: ; preds = %96, %62
%101 = load i8*, i8** %7
%102 = load i8*, i8** %1
ret i8* %102
}

LLVM IR (-O2):
%struct.ifaddrs = type { i32, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"getaddr: getifaddrs returned -1\00"
@NI_MAXHOST = global i32 0
@.str.1 = [3 x i8] c"lo\00"
@AF_INET = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.2 = [23 x i8] c"getnameinfo() failed.\0A\00"
@.str.3 = [7 x i8] c"%s: %s\00"
@.str.4 = [12 x i8] c"%s , %s: %s\00"
define i8* @getaddr() {
%1 = alloca %struct.ifaddrs*
%2 = bitcast %struct.ifaddrs** %1 to i8*
%3 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = load i32, i32* @NI_MAXHOST
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%14 = icmp eq %struct.ifaddrs* %13, null
br i1 %14, label %59, label %15
15: ; preds = %8, %52
%16 = phi %struct.ifaddrs* [ %55, %52 ], [ %13, %8 ]
%17 = phi i8* [ %53, %52 ], [ null, %8 ]
%18 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i64 0, i32 1
%19 = load %struct.TYPE_2__*, %struct.TYPE_2__** %18
%20 = icmp eq %struct.TYPE_2__* %19, null
br i1 %20, label %52, label %21
21: ; preds = %15
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @strcmp(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %52, label %26
26: ; preds = %21
%27 = load %struct.TYPE_2__*, %struct.TYPE_2__** %18
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i64 0, i32 0
%29 = load i32, i32* %28
%30 = load i32, i32* @AF_INET
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %52
32: ; preds = %26
%33 = load i32, i32* @NI_MAXHOST
%34 = load i32, i32* @NI_NUMERICHOST
%35 = call i32 @getnameinfo(%struct.TYPE_2__* %27, i32 4, i8* %12, i32 %33, i32* null, i32 0, i32 %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%39 = call i32 @freeifaddrs(%struct.ifaddrs* %38)
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %63
42: ; preds = %32
%43 = icmp eq i8* %17, null
%44 = load i32, i32* %22
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i8*
br i1 %43, label %47, label %49
47: ; preds = %42
%48 = call i8* (i8*, i8*, i8*, ...) @smprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %12)
br label %52
49: ; preds = %42
%50 = call i8* (i8*, i8*, i8*, ...) @smprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %17, i8* %46, i8* %12)
%51 = call i32 @free(i8* %17)
br label %52
52: ; preds = %26, %49, %47, %15, %21
%53 = phi i8* [ %17, %15 ], [ %17, %21 ], [ %48, %47 ], [ %50, %49 ], [ %17, %26 ]
%54 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i64 0, i32 2
%55 = load %struct.ifaddrs*, %struct.ifaddrs** %54
%56 = icmp eq %struct.ifaddrs* %55, null
br i1 %56, label %57, label %15
57: ; preds = %52
%58 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %59
59: ; preds = %57, %8
%60 = phi %struct.ifaddrs* [ null, %8 ], [ %58, %57 ]
%61 = phi i8* [ null, %8 ], [ %53, %57 ]
%62 = call i32 @freeifaddrs(%struct.ifaddrs* %60)
br label %63
63: ; preds = %59, %37
%64 = phi i8* [ null, %37 ], [ %61, %59 ]
ret i8* %64
}