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

/* Variables and functions */
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int if_nametoindex(char *);
int /*<<< orphan*/ printf(char *, ...);
int test_ifa() {
  struct ifaddrs *ifaddr, *ifa;
  if (getifaddrs(&ifaddr) == -1) {
    printf("getifaddrs error\n");
    return -1;
  }
  printf("%-10s\t%-10s\t%-5s\n", "ifa_name", "ifa_index", "family");
  for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
    int family = ifa->ifa_addr->sa_family;
    printf("%-10s\t%-10d\t%-5d\n", ifa->ifa_name, if_nametoindex(ifa->ifa_name),
           ifa->ifa_addr->sa_family);
  }
  freeifaddrs(ifaddr);
  return 0;
}


x86 assembly (clang, -O0):
<test_ifa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x10(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1174 <test_ifa+0x34>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <test_ifa+0xcd>
lea    0xe97(%rip),%rdi
lea    0xea2(%rip),%rsi
lea    0xea4(%rip),%rdx
lea    0xea7(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fd <test_ifa+0xbd>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <if_nametoindex@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%ecx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    119f <test_ifa+0x5f>
mov    -0x10(%rbp),%rdi
call   1060 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ifa>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     11cf <test_ifa+0x7f>
lea    0xe94(%rip),%rdi
lea    0xe9f(%rip),%rsi
lea    0xea1(%rip),%rdx
lea    0xea4(%rip),%rcx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11e3 <test_ifa+0x93>
lea    0xe91(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%r12
mov    %r12,%rdi
call   1050 <if_nametoindex@plt>
mov    0x8(%rbx),%rcx
mov    (%rcx),%ecx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
jne    11a0 <test_ifa+0x50>
mov    (%rsp),%rdi
jmp    11e5 <test_ifa+0x95>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    11ea <test_ifa+0x9a>
xor    %edi,%edi
call   1070 <freeifaddrs@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i32 }
@.str.1 = [18 x i8] c"%-10s\09%-10s\09%-5s\0A\00"
@.str.2 = [9 x i8] c"ifa_name\00"
@.str.3 = [10 x i8] c"ifa_index\00"
@.str.4 = [7 x i8] c"family\00"
@.str.5 = [18 x i8] c"%-10s\09%-10d\09%-5d\0A\00"
@str = [17 x i8] c"getifaddrs error\00"
define i32 @test_ifa() {
%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 %7
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %29
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%10 = icmp eq %struct.ifaddrs* %9, null
br i1 %10, label %26, label %11
11: ; preds = %7, %11
%12 = phi %struct.ifaddrs* [ %22, %11 ], [ %9, %7 ]
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 1
%14 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 @if_nametoindex(i8* %15)
%17 = load %struct.TYPE_2__*, %struct.TYPE_2__** %13
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %15, i32 %16, i32 %19)
%21 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 2
%22 = load %struct.ifaddrs*, %struct.ifaddrs** %21
%23 = icmp eq %struct.ifaddrs* %22, null
br i1 %23, label %24, label %11
24: ; preds = %11
%25 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %26
26: ; preds = %24, %7
%27 = phi %struct.ifaddrs* [ %25, %24 ], [ null, %7 ]
%28 = call i32 @freeifaddrs(%struct.ifaddrs* %27)
br label %29
29: ; preds = %26, %5
%30 = phi i32 [ -1, %5 ], [ 0, %26 ]
ret i32 %30
}