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

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int getnameinfo(TYPE_1__ *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strdup(char *);
char *get_interface_address(char *ifname) {
  struct ifaddrs *ifaddr, *ifa;
  char *address = 0, host[1025];
  int family, s;
  s = getifaddrs(&ifaddr);
  if (s != -1) {
    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
      if (ifa->ifa_addr == NULL)
        continue;
      if (strcmp(ifa->ifa_name, ifname))
        continue;
      family = ifa->ifa_addr->sa_family;
      if (family == AF_INET || family == AF_INET6) {
        s = getnameinfo(ifa->ifa_addr,
                        (family == AF_INET) ? sizeof(struct sockaddr_in)
                                            : sizeof(struct sockaddr_in6),
                        host, 1025, NULL, 0, NI_NUMERICHOST);
        if (s == 0) {
          fprintf(stderr,
                  "[Note   ] Using %s for server address on iface %s.\n", host,
                  ifname);
          address = strdup(host);
          break;
        }
      }
    }
    freeifaddrs(ifaddr);
  }
  if (!address)
    fprintf(stderr, "[Warning] Unable to get interface addresses; using "
                    "hostname instead.\n");
  return address;
}


x86 assembly (clang, -O0):
<get_interface_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1060 <getifaddrs@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0xffffffff,-0x438(%rbp)
je     12c5 <get_interface_address+0x165>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12bc <get_interface_address+0x15c>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b9 <get_interface_address+0x59>
jmp    12ab <get_interface_address+0x14b>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11d8 <get_interface_address+0x78>
jmp    12ab <get_interface_address+0x14b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1211 <get_interface_address+0xb1>
mov    -0x434(%rbp),%eax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%eax
jne    12a6 <get_interface_address+0x146>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x434(%rbp),%ecx
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%eax
cmp    %edx,%ecx
cmove  %rax,%rax
mov    %eax,%esi
lea    -0x430(%rbp),%rdx
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    $0x401,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1030 <getnameinfo@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x438(%rbp)
jne    12a1 <get_interface_address+0x141>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x430(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    12bc <get_interface_address+0x15c>
jmp    12a6 <get_interface_address+0x146>
jmp    12ab <get_interface_address+0x14b>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    119b <get_interface_address+0x3b>
mov    -0x10(%rbp),%rdi
call   1070 <freeifaddrs@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12e7 <get_interface_address+0x187>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_interface_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     1210 <get_interface_address+0xb0>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1209 <get_interface_address+0xa9>
mov    0x2e50(%rip),%r12
mov    0x2e41(%rip),%r13
mov    0x2e22(%rip),%rbp
lea    0x10(%rsp),%r14
jmp    11d9 <get_interface_address+0x79>
mov    0x0(%rbp),%eax
mov    %eax,(%rsp)
mov    $0x4,%esi
mov    %r14,%rdx
mov    $0x401,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <getnameinfo@plt>
test   %eax,%eax
je     123e <get_interface_address+0xde>
nop
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1202 <get_interface_address+0xa2>
cmpq   $0x0,(%rbx)
je     11d0 <get_interface_address+0x70>
mov    0x8(%rbx),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11d0 <get_interface_address+0x70>
mov    (%rbx),%rdi
mov    (%rdi),%eax
cmp    (%r12),%eax
je     11ad <get_interface_address+0x4d>
cmp    0x0(%r13),%eax
jne    11d0 <get_interface_address+0x70>
jmp    11ad <get_interface_address+0x4d>
mov    0x8(%rsp),%rdi
jmp    120b <get_interface_address+0xab>
xor    %edi,%edi
call   1070 <freeifaddrs@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1070 <freeifaddrs@plt>
test   %rbx,%rbx
jne    1229 <get_interface_address+0xc9>
jmp    1210 <get_interface_address+0xb0>

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_2__*, i32, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
@stderr = global i32 0
@.str = [52 x i8] c"[Note ] Using %s for server address on iface %s.\0A\00"
@.str.1 = [70 x i8] c"[Warning] Unable to get interface addresses; using hostname instead.\0A\00"
define i8* @get_interface_address(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
%5 = alloca i8*
%6 = alloca [1025 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %5
%9 = call i32 @getifaddrs(%struct.ifaddrs** %3)
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %75
12: ; preds = %1
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %3
store %struct.ifaddrs* %13, %struct.ifaddrs** %4
br label %14
14: ; preds = %68, %12
%15 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%16 = icmp ne %struct.ifaddrs* %15, null
br i1 %16, label %17, label %72
17: ; preds = %14
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i32 0, i32 0
%20 = load %struct.TYPE_2__*, %struct.TYPE_2__** %19
%21 = icmp eq %struct.TYPE_2__* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
br label %68
23: ; preds = %17
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = load i8*, i8** %2
%28 = call i64 @strcmp(i32 %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
br label %68
31: ; preds = %23
%32 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%33 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %32, i32 0, i32 0
%34 = load %struct.TYPE_2__*, %struct.TYPE_2__** %33
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = load i32, i32* @AF_INET
%39 = icmp eq i32 %37, %38
br i1 %39, label %44, label %40
40: ; preds = %31
%41 = load i32, i32* %7
%42 = load i32, i32* @AF_INET6
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %67
44: ; preds = %40, %31
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%46 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %45, i32 0, i32 0
%47 = load %struct.TYPE_2__*, %struct.TYPE_2__** %46
%48 = load i32, i32* %7
%49 = load i32, i32* @AF_INET
%50 = icmp eq i32 %48, %49
%51 = zext i1 %50 to i64
%52 = select i1 %50, i64 4, i64 4
%53 = trunc i64 %52 to i32
%54 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%55 = load i32, i32* @NI_NUMERICHOST
%56 = call i32 @getnameinfo(%struct.TYPE_2__* %47, i32 %53, i8* %54, i32 1025, i32* null, i32 0, i32 %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %44
%60 = load i32, i32* @stderr
%61 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%62 = load i8*, i8** %2
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %61, i8* %62)
%64 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%65 = call i8* @strdup(i8* %64)
store i8* %65, i8** %5
br label %72
66: ; preds = %44
br label %67
67: ; preds = %66, %40
br label %68
68: ; preds = %67, %30, %22
%69 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%70 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %69, i32 0, i32 2
%71 = load %struct.ifaddrs*, %struct.ifaddrs** %70
store %struct.ifaddrs* %71, %struct.ifaddrs** %4
br label %14
72: ; preds = %59, %14
%73 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%74 = call i32 @freeifaddrs(%struct.ifaddrs* %73)
br label %75
75: ; preds = %72, %1
%76 = load i8*, i8** %5
%77 = icmp ne i8* %76, null
br i1 %77, label %81, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
br label %81
81: ; preds = %78, %75
%82 = load i8*, i8** %5
ret i8* %82
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_2__*, i32, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@NI_NUMERICHOST = global i32 0
@stderr = global i32 0
@.str = [52 x i8] c"[Note ] Using %s for server address on iface %s.\0A\00"
@.str.1 = [70 x i8] c"[Warning] Unable to get interface addresses; using hostname instead.\0A\00"
define i8* @get_interface_address(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = alloca [1025 x i8]
%4 = bitcast %struct.ifaddrs** %2 to i8*
%5 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%6 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %50, label %8
8: ; preds = %1
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%10 = icmp eq %struct.ifaddrs* %9, null
br i1 %10, label %13, label %16
11: ; preds = %39
%12 = load %struct.ifaddrs*, %struct.ifaddrs** %2
br label %13
13: ; preds = %11, %8
%14 = phi %struct.ifaddrs* [ %12, %11 ], [ null, %8 ]
%15 = call i32 @freeifaddrs(%struct.ifaddrs* %14)
br label %50
16: ; preds = %8, %39
%17 = phi %struct.ifaddrs* [ %41, %39 ], [ %9, %8 ]
%18 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 0
%19 = load %struct.TYPE_2__*, %struct.TYPE_2__** %18
%20 = icmp eq %struct.TYPE_2__* %19, null
br i1 %20, label %39, label %21
21: ; preds = %16
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 1
%23 = load i32, i32* %22
%24 = call i64 @strcmp(i32 %23, i8* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %39
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
%32 = load i32, i32* @AF_INET6
%33 = icmp eq i32 %29, %32
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %35, label %39
35: ; preds = %26
%36 = load i32, i32* @NI_NUMERICHOST
%37 = call i32 @getnameinfo(%struct.TYPE_2__* %27, i32 4, i8* %5, i32 1025, i32* null, i32 0, i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %26, %35, %21, %16
%40 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i64 0, i32 2
%41 = load %struct.ifaddrs*, %struct.ifaddrs** %40
%42 = icmp eq %struct.ifaddrs* %41, null
br i1 %42, label %11, label %16
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %0)
%46 = call i8* @strdup(i8* %5)
%47 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%48 = call i32 @freeifaddrs(%struct.ifaddrs* %47)
%49 = icmp eq i8* %46, null
br i1 %49, label %50, label %53
50: ; preds = %1, %13, %43
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %50, %43
%54 = phi i8* [ null, %50 ], [ %46, %43 ]
ret i8* %54
}