#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 */

/* Type definitions */
struct if_nameindex {
  char *if_name;
  int if_index;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ if_freenameindex(struct if_nameindex *);
struct if_nameindex *if_nameindex();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void test_if_nameindex(void) {
  size_t i;
  struct if_nameindex *ret;
  ret = if_nameindex();
  if (ret == NULL) {
    perror("if_nameindex()");
    exit(1);
  }
  printf("--- if_nameindex()\n");
  for (i = 0; ret[i].if_name; ++i)
    printf("%i: %s\n", ret[i].if_index, ret[i].if_name);
  if_freenameindex(ret);
}


x86 assembly (clang, -O0):
<test_if_nameindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <if_nameindex@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <test_if_nameindex+0x34>
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     11f6 <test_if_nameindex+0xa6>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%esi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <test_if_nameindex+0x4a>
mov    -0x10(%rbp),%rdi
call   1050 <if_freenameindex@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_if_nameindex>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <if_nameindex@plt>
test   %rax,%rax
je     11c6 <test_if_nameindex+0x66>
mov    %rax,%r14
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%rdx
test   %rdx,%rdx
je     11b9 <test_if_nameindex+0x59>
mov    %r14,%rbx
add    $0x10,%rbx
lea    0xe6a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    -0x8(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdx
add    $0x10,%rbx
test   %rdx,%rdx
jne    11a0 <test_if_nameindex+0x40>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <if_freenameindex@plt>
lea    0xe3f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.if_nameindex = type { i8*, i32 }
@.str = [15 x i8] c"if_nameindex()\00"
@.str.1 = [20 x i8] c"--- if_nameindex()\0A\00"
@.str.2 = [8 x i8] c"%i: %s\0A\00"
define void @test_if_nameindex() {
%1 = alloca i64
%2 = alloca %struct.if_nameindex*
%3 = call %struct.if_nameindex* (...) @if_nameindex()
store %struct.if_nameindex* %3, %struct.if_nameindex** %2
%4 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%5 = icmp eq %struct.if_nameindex* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %1
br label %11
11: ; preds = %30, %9
%12 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%13 = load i64, i64* %1
%14 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %12, i64 %13
%15 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %33
18: ; preds = %11
%19 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%20 = load i64, i64* %1
%21 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %19, i64 %20
%22 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%25 = load i64, i64* %1
%26 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %24, i64 %25
%27 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %28)
br label %30
30: ; preds = %18
%31 = load i64, i64* %1
%32 = add i64 %31, 1
store i64 %32, i64* %1
br label %11
33: ; preds = %11
%34 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%35 = call i32 @if_freenameindex(%struct.if_nameindex* %34)
ret void
}

LLVM IR (-O2):
%struct.if_nameindex = type { i8*, i32 }
@.str = [15 x i8] c"if_nameindex()\00"
@.str.2 = [8 x i8] c"%i: %s\0A\00"
@str = [19 x i8] c"--- if_nameindex()\00"
define void @test_if_nameindex() {
%1 = tail call %struct.if_nameindex* (...) @if_nameindex()
%2 = icmp eq %struct.if_nameindex* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%8 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %1, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %6, %11
%12 = phi i8* [ %19, %11 ], [ %9, %6 ]
%13 = phi i64 [ %17, %11 ], [ 0, %6 ]
%14 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %1, i64 %13, i32 1
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %12)
%17 = add i64 %13, 1
%18 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %1, i64 %17, i32 0
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %11
21: ; preds = %11, %6
%22 = tail call i32 @if_freenameindex(%struct.if_nameindex* %1)
ret void
}