#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 {
  int if_index;
  char *if_name;
};

/* Variables and functions */
scalar_t__ ENOSYS;
int IFNAMSIZ;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ if_freenameindex(struct if_nameindex *);
char *if_indextoname(int, char *);
struct if_nameindex *if_nameindex();
unsigned int if_nametoindex(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int do_test(void) {
  int failures = 0;
  struct if_nameindex *idx = if_nameindex(), *p;
  if (idx == NULL) {
    if (errno != ENOSYS) {
      printf("Couldn't get any interfaces.\n");
      exit(1);
    }
    exit(0);
  }
  printf("Idx            Name | Idx           Name\n");
  for (p = idx; p->if_index || p->if_name; ++p) {
    char buf[IFNAMSIZ];
    unsigned int ni;
    int result;
    printf("%3d %15s | ", p->if_index, p->if_name);
    printf("%3d", ni = if_nametoindex(p->if_name));
    printf("%15s", if_indextoname(p->if_index, buf));
    result = (ni != p->if_index || (strcmp(buf, p->if_name)));
    if (ni == p->if_index)
      if (p->if_index == if_nametoindex(buf))
        result = 0;
    printf("%10s", result ? "fail" : "okay");
    printf("\n");
    failures += result;
  }
  if_freenameindex(idx);
  return failures ? 1 : 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <if_nameindex@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <do_test+0x5e>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
je     11c7 <do_test+0x57>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    $0x1,%al
cmpl   $0x0,(%rcx)
mov    %al,-0x31(%rbp)
jne    1205 <do_test+0x95>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1215 <do_test+0xa5>
jmp    1366 <do_test+0x1f6>
mov    0x2dbc(%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,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <if_nametoindex@plt>
mov    %eax,%esi
mov    %esi,-0x2c(%rbp)
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <if_indextoname@plt>
mov    %rax,%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rdx
mov    $0x1,%al
cmp    (%rdx),%ecx
mov    %al,-0x32(%rbp)
jne    12cc <do_test+0x15c>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    1311 <do_test+0x1a1>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
call   1050 <if_nametoindex@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jne    130c <do_test+0x19c>
movl   $0x0,-0x30(%rbp)
jmp    1311 <do_test+0x1a1>
mov    -0x30(%rbp),%ecx
lea    0xd4c(%rip),%rsi
lea    0xd40(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    11e4 <do_test+0x74>
mov    -0x10(%rbp),%rdi
call   1080 <if_freenameindex@plt>
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1080 <if_nameindex@plt>
test   %rax,%rax
je     12f2 <do_test+0x162>
mov    %rax,%r13
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,-0x38(%rbp)
xor    %ebx,%ebx
jmp    120f <do_test+0x7f>
nopl   0x0(%rax,%rax,1)
movzbl %r12b,%ebx
test   %bl,%bl
lea    0xe42(%rip),%rsi
lea    0xe36(%rip),%rax
cmovne %rax,%rsi
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
add    %ebx,%eax
mov    %eax,%ebx
mov    -0x40(%rbp),%rsp
add    $0x10,%r13
cmpl   $0x0,0x0(%r13)
jne    1221 <do_test+0x91>
cmpq   $0x0,0x8(%r13)
je     12d3 <do_test+0x143>
mov    %rsp,-0x40(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x0(%r13),%esi
mov    0x8(%r13),%rdx
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r13),%rdi
call   1070 <if_nametoindex@plt>
mov    %eax,%r15d
lea    0xda4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1090 <if_indextoname@plt>
lea    0xd8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%r13),%eax
mov    $0x1,%r12b
cmp    %eax,%r15d
jne    12b1 <do_test+0x121>
mov    0x8(%r13),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
setne  %r12b
mov    0x0(%r13),%eax
cmp    %eax,%r15d
mov    %ebx,-0x2c(%rbp)
jne    11d0 <do_test+0x40>
mov    %r14,%rdi
call   1070 <if_nametoindex@plt>
cmp    %eax,%r15d
setne  %al
and    %al,%r12b
jmp    11d0 <do_test+0x40>
mov    -0x38(%rbp),%rdi
call   10a0 <if_freenameindex@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd7(%rip),%rax
mov    (%rax),%rax
mov    0x2ce5(%rip),%rcx
cmp    (%rcx),%rax
jne    130f <do_test+0x17f>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.if_nameindex = type { i32, i8* }
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [30 x i8] c"Couldn't get any interfaces.\0A\00"
@.str.1 = [42 x i8] c"Idx Name | Idx Name\0A\00"
@IFNAMSIZ = global i32 0
@.str.2 = [12 x i8] c"%3d %15s | \00"
@.str.3 = [4 x i8] c"%3d\00"
@.str.4 = [5 x i8] c"%15s\00"
@.str.5 = [5 x i8] c"%10s\00"
@.str.6 = [5 x i8] c"fail\00"
@.str.7 = [5 x i8] c"okay\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca %struct.if_nameindex*
%3 = alloca %struct.if_nameindex*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call %struct.if_nameindex* (...) @if_nameindex()
store %struct.if_nameindex* %8, %struct.if_nameindex** %2
%9 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%10 = icmp eq %struct.if_nameindex* %9, null
br i1 %10, label %11, label %20
11: ; preds = %0
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOSYS
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%22 = load %struct.if_nameindex*, %struct.if_nameindex** %2
store %struct.if_nameindex* %22, %struct.if_nameindex** %3
br label %23
23: ; preds = %95, %20
%24 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%25 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %23
%29 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%30 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br label %33
33: ; preds = %28, %23
%34 = phi i1 [ true, %23 ], [ %32, %28 ]
br i1 %34, label %35, label %98
35: ; preds = %33
%36 = load i32, i32* @IFNAMSIZ
%37 = zext i32 %36 to i64
%38 = call i8* @llvm.stacksave()
store i8* %38, i8** %4
%39 = alloca i8, i64 %37
store i64 %37, i64* %5
%40 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%41 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%44 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %43, i32 0, i32 1
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %42, i8* %45)
%47 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%48 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %47, i32 0, i32 1
%49 = load i8*, i8** %48
%50 = call i32 @if_nametoindex(i8* %49)
store i32 %50, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%53 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @if_indextoname(i32 %54, i8* %39)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32, i32* %6
%58 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%59 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = icmp ne i32 %57, %60
br i1 %61, label %68, label %62
62: ; preds = %35
%63 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%64 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %63, i32 0, i32 1
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %39, i8* %65)
%67 = icmp ne i64 %66, 0
br label %68
68: ; preds = %62, %35
%69 = phi i1 [ true, %35 ], [ %67, %62 ]
%70 = zext i1 %69 to i32
store i32 %70, i32* %7
%71 = load i32, i32* %6
%72 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%73 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = icmp eq i32 %71, %74
br i1 %75, label %76, label %84
76: ; preds = %68
%77 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%78 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @if_nametoindex(i8* %39)
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %83
82: ; preds = %76
store i32 0, i32* %7
br label %83
83: ; preds = %82, %76
br label %84
84: ; preds = %83, %68
%85 = load i32, i32* %7
%86 = icmp ne i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%91 = load i32, i32* %7
%92 = load i32, i32* %1
%93 = add nsw i32 %92, %91
store i32 %93, i32* %1
%94 = load i8*, i8** %4
br label %95
95: ; preds = %84
%96 = load %struct.if_nameindex*, %struct.if_nameindex** %3
%97 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %96, i32 1
store %struct.if_nameindex* %97, %struct.if_nameindex** %3
br label %23
98: ; preds = %33
%99 = load %struct.if_nameindex*, %struct.if_nameindex** %2
%100 = call i32 @if_freenameindex(%struct.if_nameindex* %99)
%101 = load i32, i32* %1
%102 = icmp ne i32 %101, 0
%103 = zext i1 %102 to i64
%104 = select i1 %102, i32 1, i32 0
ret i32 %104
}

LLVM IR (-O2):
%struct.if_nameindex = type { i32, i8* }
@errno = global i64 0
@ENOSYS = global i64 0
@IFNAMSIZ = global i32 0
@.str.2 = [12 x i8] c"%3d %15s | \00"
@.str.3 = [4 x i8] c"%3d\00"
@.str.4 = [5 x i8] c"%15s\00"
@.str.5 = [5 x i8] c"%10s\00"
@.str.6 = [5 x i8] c"fail\00"
@.str.7 = [5 x i8] c"okay\00"
@str = [41 x i8] c"Idx Name | Idx Name\00"
@str.9 = [29 x i8] c"Couldn't get any interfaces.\00"
define i32 @do_test() {
%1 = tail call %struct.if_nameindex* (...) @if_nameindex()
%2 = icmp eq %struct.if_nameindex* %1, null
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENOSYS
%6 = icmp eq i64 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.9, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %54, %12
%15 = phi %struct.if_nameindex* [ %1, %12 ], [ %61, %54 ]
%16 = phi i32 [ 0, %12 ], [ %60, %54 ]
%17 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %15, i64 0, i32 0
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %15, i64 0, i32 1
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %62, label %24
24: ; preds = %14, %20
%25 = load i32, i32* @IFNAMSIZ
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
%28 = alloca i8, i64 %26
%29 = load i32, i32* %17
%30 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %15, i64 0, i32 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %29, i8* %31)
%33 = load i8*, i8** %30
%34 = call i32 @if_nametoindex(i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %17
%37 = call i8* @if_indextoname(i32 %36, i8* %28)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %17
%40 = icmp eq i32 %34, %39
br i1 %40, label %41, label %46
41: ; preds = %24
%42 = load i8*, i8** %30
%43 = call i64 @strcmp(i8* %28, i8* %42)
%44 = icmp ne i64 %43, 0
%45 = load i32, i32* %17
br label %46
46: ; preds = %41, %24
%47 = phi i32 [ %39, %24 ], [ %45, %41 ]
%48 = phi i1 [ true, %24 ], [ %44, %41 ]
%49 = icmp eq i32 %34, %47
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 @if_nametoindex(i8* %28)
%52 = icmp ne i32 %34, %51
%53 = select i1 %52, i1 %48, i1 false
br label %54
54: ; preds = %50, %46
%55 = phi i1 [ %48, %46 ], [ %53, %50 ]
%56 = zext i1 %55 to i32
%57 = select i1 %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %57)
%59 = call i32 @putchar(i32 10)
%60 = add nuw nsw i32 %16, %56
%61 = getelementptr inbounds %struct.if_nameindex, %struct.if_nameindex* %15, i64 1
br label %14
62: ; preds = %20
%63 = call i32 @if_freenameindex(%struct.if_nameindex* %1)
%64 = icmp ne i32 %16, 0
%65 = zext i1 %64 to i32
ret i32 %65
}