#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_in {
  int dummy;
};
struct ifaddrs {
  char *ifa_name;
  TYPE_1__ *ifa_addr;
  struct ifaddrs *ifa_next;
};
struct TYPE_2__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ getnameinfo(TYPE_1__ *, int, char *, int,
                               int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
char *smprintf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *getifaddr(void) {
  struct ifaddrs *ifaddr, *ifa;
  char host[NI_MAXHOST], output[200] = {0}, buf[100];
  if (getifaddrs(&ifaddr) == 1)
    return 0;
  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    if (strncmp(ifa->ifa_name, "virbr", 5) != 0 &&
        strncmp(ifa->ifa_name, "lo", 2) != 0 &&
        ifa->ifa_addr->sa_family == AF_INET) {
      getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST,
                  NULL, 0, NI_NUMERICHOST);
      sprintf(buf, " %s: %s |", ifa->ifa_name, host);
      strcat(output, buf);
    }
  }
  freeifaddrs(ifaddr);
  return smprintf("%s", output);
}


x86 assembly (clang, -O0):
<getifaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x170(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1070 <getifaddrs@plt>
cmp    $0x1,%eax
jne    11f6 <getifaddr+0x76>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x164(%rbp)
jmp    1318 <getifaddr+0x198>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12ee <getifaddr+0x16e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xde9(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12d8 <getifaddr+0x158>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcd(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12d8 <getifaddr+0x158>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%rax
jne    12d8 <getifaddr+0x158>
mov    -0x170(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d52(%rip),%rax
mov    (%rax),%ecx
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <getnameinfo@plt>
mov    -0x170(%rbp),%rcx
add    $0x10,%rsp
lea    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xd49(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xf0(%rbp),%rdi
lea    -0x160(%rbp),%rsi
call   1090 <strcat@plt>
jmp    12dd <getifaddr+0x15d>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11fe <getifaddr+0x7e>
mov    -0x10(%rbp),%rdi
call   1080 <freeifaddrs@plt>
lea    -0xf0(%rbp),%rsi
lea    0xd0e(%rip),%rdi
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x164(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getifaddr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rsp,%r14
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movaps %xmm0,-0x80(%rbp)
movaps %xmm0,-0x90(%rbp)
movaps %xmm0,-0xa0(%rbp)
movaps %xmm0,-0xb0(%rbp)
movaps %xmm0,-0xc0(%rbp)
movaps %xmm0,-0xd0(%rbp)
movaps %xmm0,-0xe0(%rbp)
movaps %xmm0,-0xf0(%rbp)
movaps %xmm0,-0x100(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0x1,%eax
jne    1209 <getifaddr+0x99>
xor    %eax,%eax
jmp    130a <getifaddr+0x19a>
mov    -0x30(%rbp),%r12
test   %r12,%r12
je     12f0 <getifaddr+0x180>
mov    %r14,-0x38(%rbp)
lea    0xddf(%rip),%r14
lea    0xdde(%rip),%r15
lea    -0x170(%rbp),%r13
jmp    124e <getifaddr+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%r12),%r12
test   %r12,%r12
je     12e6 <getifaddr+0x176>
mov    (%r12),%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1240 <getifaddr+0xd0>
mov    (%r12),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1240 <getifaddr+0xd0>
mov    0x8(%r12),%rdi
mov    (%rdi),%rax
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%rax
jne    1240 <getifaddr+0xd0>
mov    0x2d3b(%rip),%rax
mov    (%rax),%ecx
mov    0x2d3a(%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
mov    (%r12),%rdx
mov    %r13,%rdi
lea    0xd3f(%rip),%rsi
mov    %rbx,%rcx
call   1090 <sprintf@plt>
lea    -0x100(%rbp),%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
jmp    1240 <getifaddr+0xd0>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%r14
jmp    12f2 <getifaddr+0x182>
xor    %edi,%edi
call   1070 <freeifaddrs@plt>
lea    0xd15(%rip),%rdi
lea    -0x100(%rbp),%rsi
call   1040 <smprintf@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@NI_MAXHOST = global i32 0
@.str = [6 x i8] c"virbr\00"
@.str.1 = [3 x i8] c"lo\00"
@AF_INET = global i64 0
@NI_NUMERICHOST = global i32 0
@.str.2 = [10 x i8] c" %s: %s |\00"
@.str.3 = [3 x i8] c"%s\00"
define i8* @getifaddr() {
%1 = alloca %struct.ifaddrs*
%2 = alloca [200 x i8]
%3 = alloca [100 x i8]
%4 = bitcast %struct.ifaddrs** %1 to i8*
%5 = load i32, i32* @NI_MAXHOST
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %50, label %13
13: ; preds = %0
%14 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%15 = icmp eq %struct.ifaddrs* %14, null
br i1 %15, label %46, label %16
16: ; preds = %13, %40
%17 = phi %struct.ifaddrs* [ %42, %40 ], [ %14, %13 ]
%18 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %16
%23 = load i8*, i8** %18
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %40, label %26
26: ; preds = %22
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 1
%28 = load %struct.TYPE_2__*, %struct.TYPE_2__** %27
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i64 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @AF_INET
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i32, i32* @NI_MAXHOST
%35 = load i32, i32* @NI_NUMERICHOST
%36 = call i32 @getnameinfo(%struct.TYPE_2__* %28, i32 4, i8* %8, i32 %34, i32* null, i32 0, i32 %35)
%37 = load i8*, i8** %18
%38 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %8)
%39 = call i32 @strcat(i8* %9, i8* %10)
br label %40
40: ; preds = %16, %22, %26, %33
%41 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 2
%42 = load %struct.ifaddrs*, %struct.ifaddrs** %41
%43 = icmp eq %struct.ifaddrs* %42, null
br i1 %43, label %44, label %16
44: ; preds = %40
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %46
46: ; preds = %44, %13
%47 = phi %struct.ifaddrs* [ %45, %44 ], [ null, %13 ]
%48 = call i32 @freeifaddrs(%struct.ifaddrs* %47)
%49 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %50
50: ; preds = %0, %46
%51 = phi i8* [ %49, %46 ], [ null, %0 ]
ret i8* %51
}