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

/* Variables and functions */
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
int is_valid_interface(const char *ifname) {
  struct ifaddrs *ifa, *cur;
  if (getifaddrs(&ifa)) {
    perror("Failed to getifaddrs()");
    return 0;
  }
  int found = 0;
  for (cur = ifa; cur; cur = cur->ifa_next) {
    if (strcmp(ifname, cur->ifa_name) == 0) {
      found = 1;
      break;
    }
  }
  freeifaddrs(ifa);
  return found;
}


x86 assembly (clang, -O0):
<is_valid_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0x0,%rax
je     1177 <is_valid_interface+0x37>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <is_valid_interface+0x9b>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cc <is_valid_interface+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11b6 <is_valid_interface+0x76>
movl   $0x1,-0x24(%rbp)
jmp    11cc <is_valid_interface+0x8c>
jmp    11bb <is_valid_interface+0x7b>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1186 <is_valid_interface+0x46>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_interface>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rdi
call   1040 <getifaddrs@plt>
test   %rax,%rax
jne    119a <is_valid_interface+0x5a>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     117c <is_valid_interface+0x3c>
nopl   (%rax)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1182 <is_valid_interface+0x42>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
jne    1160 <is_valid_interface+0x20>
xor    %ebx,%ebx
jmp    1187 <is_valid_interface+0x47>
xor    %edi,%edi
xor    %ebx,%ebx
jmp    118b <is_valid_interface+0x4b>
mov    $0x1,%ebx
mov    (%rsp),%rdi
call   1050 <freeifaddrs@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
xor    %ebx,%ebx
jmp    1190 <is_valid_interface+0x50>

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

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