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

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int /*<<< orphan*/ getifaddrs(struct ifaddrs **);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int32_t printAllInterfaces() {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  char *addr;
  getifaddrs(&ifap);
  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    if (ifa->ifa_addr->sa_family == AF_INET) {
      sa = (struct sockaddr_in *)ifa->ifa_addr;
      addr = inet_ntoa(sa->sin_addr);
      printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr);
    }
  }
  freeifaddrs(ifap);
  return 0;
}


x86 assembly (clang, -O0):
<printAllInterfaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <getifaddrs@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c7 <printAllInterfaces+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <printAllInterfaces+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
jmp    11b6 <printAllInterfaces+0x76>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1159 <printAllInterfaces+0x19>
mov    -0x8(%rbp),%rdi
call   1060 <freeifaddrs@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAllInterfaces>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11a4 <printAllInterfaces+0x64>
mov    0x2e84(%rip),%r15
mov    (%r15),%rax
lea    0xe92(%rip),%r14
jmp    1179 <printAllInterfaces+0x39>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     119d <printAllInterfaces+0x5d>
mov    0x8(%rbx),%rcx
mov    (%rcx),%rdi
cmp    %rax,%rdi
jne    1170 <printAllInterfaces+0x30>
call   1030 <inet_ntoa@plt>
mov    (%rbx),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    (%r15),%rax
jmp    1170 <printAllInterfaces+0x30>
mov    0x8(%rsp),%rdi
jmp    11a6 <printAllInterfaces+0x66>
xor    %edi,%edi
call   1060 <freeifaddrs@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i64 0
@.str = [27 x i8] c"Interface: %s\09Address: %s\0A\00"
define i32 @printAllInterfaces() {
%1 = alloca %struct.ifaddrs*
%2 = alloca %struct.ifaddrs*
%3 = alloca %struct.sockaddr_in*
%4 = alloca i8*
%5 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%6 = load %struct.ifaddrs*, %struct.ifaddrs** %1
store %struct.ifaddrs* %6, %struct.ifaddrs** %2
br label %7
7: ; preds = %33, %0
%8 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%9 = icmp ne %struct.ifaddrs* %8, null
br i1 %9, label %10, label %37
10: ; preds = %7
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%12 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %11, i32 0, i32 1
%13 = load %struct.TYPE_2__*, %struct.TYPE_2__** %12
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %10
%19 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %19, i32 0, i32 1
%21 = load %struct.TYPE_2__*, %struct.TYPE_2__** %20
%22 = bitcast %struct.TYPE_2__* %21 to %struct.sockaddr_in*
store %struct.sockaddr_in* %22, %struct.sockaddr_in** %3
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
store i8* %26, i8** %4
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%28 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = load i8*, i8** %4
%31 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30)
br label %32
32: ; preds = %18, %10
br label %33
33: ; preds = %32
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%35 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %34, i32 0, i32 2
%36 = load %struct.ifaddrs*, %struct.ifaddrs** %35
store %struct.ifaddrs* %36, %struct.ifaddrs** %2
br label %7
37: ; preds = %7
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%39 = call i32 @freeifaddrs(%struct.ifaddrs* %38)
ret i32 0
}

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@.str = [27 x i8] c"Interface: %s\09Address: %s\0A\00"
define i32 @printAllInterfaces() {
%1 = alloca %struct.ifaddrs*
%2 = bitcast %struct.ifaddrs** %1 to i8*
%3 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%4 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%5 = icmp eq %struct.ifaddrs* %4, null
br i1 %5, label %30, label %6
6: ; preds = %0
%7 = load i64, i64* @AF_INET
br label %8
8: ; preds = %6, %23
%9 = phi i64 [ %24, %23 ], [ %7, %6 ]
%10 = phi %struct.ifaddrs* [ %26, %23 ], [ %4, %6 ]
%11 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 1
%12 = load %struct.TYPE_2__*, %struct.TYPE_2__** %11
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %9
br i1 %15, label %16, label %23
16: ; preds = %8
%17 = trunc i64 %14 to i32
%18 = call i8* @inet_ntoa(i32 %17)
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %18)
%22 = load i64, i64* @AF_INET
br label %23
23: ; preds = %8, %16
%24 = phi i64 [ %9, %8 ], [ %22, %16 ]
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 2
%26 = load %struct.ifaddrs*, %struct.ifaddrs** %25
%27 = icmp eq %struct.ifaddrs* %26, null
br i1 %27, label %28, label %8
28: ; preds = %23
%29 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %30
30: ; preds = %28, %0
%31 = phi %struct.ifaddrs* [ %29, %28 ], [ null, %0 ]
%32 = call i32 @freeifaddrs(%struct.ifaddrs* %31)
ret i32 0
}