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

/* Variables and functions */
unsigned int IFF_LOOPBACK;
unsigned int IFF_RUNNING;
unsigned int IFF_UP;
int /*<<< orphan*/ die(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
bool check_interface(const char *if_name) {
  struct ifaddrs *ifaddr, *ifa;
  if (getifaddrs(&ifaddr) == -1) {
    die(strerror(errno));
  }
  ifa = ifaddr;
  while (ifa && strcmp(if_name, ifa->ifa_name)) {
    ifa = ifa->ifa_next;
  }
  unsigned int flags = ifa ? ifa->ifa_flags : 0;
  bool ret = ifa && (flags & IFF_UP) && (flags & IFF_RUNNING) &&
             !(flags & IFF_LOOPBACK);
  freeifaddrs(ifaddr);
  return ret;
}


x86 assembly (clang, -O0):
<check_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1183 <check_interface+0x33>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edi
call   1060 <die@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     11b5 <check_interface+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c5 <check_interface+0x75>
jmp    11d6 <check_interface+0x86>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    118b <check_interface+0x3b>
cmpq   $0x0,-0x18(%rbp)
je     11ef <check_interface+0x9f>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    11f9 <check_interface+0xa9>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11f9 <check_interface+0xa9>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
je     125a <check_interface+0x10a>
mov    -0x1c(%rbp),%ecx
mov    0x2dbf(%rip),%rax
and    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     125a <check_interface+0x10a>
mov    -0x1c(%rbp),%ecx
mov    0x2dad(%rip),%rax
and    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     125a <check_interface+0x10a>
mov    -0x1c(%rbp),%eax
mov    0x2dab(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <freeifaddrs@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_interface>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    117f <check_interface+0x2f>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edi
call   1060 <die@plt>
mov    0x8(%rsp),%rbp
xor    %r14d,%r14d
test   %rbp,%rbp
je     11a9 <check_interface+0x59>
nopl   0x0(%rax)
mov    0x10(%rbp),%esi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11bf <check_interface+0x6f>
mov    0x8(%rbp),%rbp
test   %rbp,%rbp
jne    1190 <check_interface+0x40>
mov    0x8(%rsp),%rdi
call   1050 <freeifaddrs@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x0(%rbp),%eax
mov    0x2e0f(%rip),%rcx
test   %eax,(%rcx)
je     11a9 <check_interface+0x59>
mov    0x2e0c(%rip),%rcx
test   %eax,(%rcx)
je     11a9 <check_interface+0x59>
mov    0x2e19(%rip),%rcx
xor    %r14d,%r14d
test   %eax,(%rcx)
sete   %r14b
jmp    11a9 <check_interface+0x59>

LLVM IR (-O0):
%struct.ifaddrs = type { i32, %struct.ifaddrs*, i32 }
@errno = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@IFF_LOOPBACK = global i32 0
define i32 @check_interface(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @die(i32 %11)
br label %13
13: ; preds = %9, %1
%14 = load %struct.ifaddrs*, %struct.ifaddrs** %3
store %struct.ifaddrs* %14, %struct.ifaddrs** %4
br label %15
15: ; preds = %27, %13
%16 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%17 = icmp ne %struct.ifaddrs* %16, null
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i8*, i8** %2
%20 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%21 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = call i64 @strcmp(i8* %19, i32 %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %18, %15
%26 = phi i1 [ false, %15 ], [ %24, %18 ]
br i1 %26, label %27, label %31
27: ; preds = %25
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 1
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %29
store %struct.ifaddrs* %30, %struct.ifaddrs** %4
br label %15
31: ; preds = %25
%32 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%33 = icmp ne %struct.ifaddrs* %32, null
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%36 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %35, i32 0, i32 0
%37 = load i32, i32* %36
br label %39
38: ; preds = %31
br label %39
39: ; preds = %38, %34
%40 = phi i32 [ %37, %34 ], [ 0, %38 ]
store i32 %40, i32* %5
%41 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%42 = icmp ne %struct.ifaddrs* %41, null
br i1 %42, label %43, label %59
43: ; preds = %39
%44 = load i32, i32* %5
%45 = load i32, i32* @IFF_UP
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %43
%49 = load i32, i32* %5
%50 = load i32, i32* @IFF_RUNNING
%51 = and i32 %49, %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i32, i32* %5
%55 = load i32, i32* @IFF_LOOPBACK
%56 = and i32 %54, %55
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br label %59
59: ; preds = %53, %48, %43, %39
%60 = phi i1 [ false, %48 ], [ false, %43 ], [ false, %39 ], [ %58, %53 ]
%61 = zext i1 %60 to i32
store i32 %61, i32* %6
%62 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%63 = call i32 @freeifaddrs(%struct.ifaddrs* %62)
%64 = load i32, i32* %6
ret i32 %64
}

LLVM IR (-O2):
%struct.ifaddrs = type { i32, %struct.ifaddrs*, i32 }
@errno = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@IFF_LOOPBACK = global i32 0
define i32 @check_interface(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = bitcast %struct.ifaddrs** %2 to i8*
%4 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @die(i32 %8)
br label %10
10: ; preds = %6, %1
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%12 = icmp eq %struct.ifaddrs* %11, null
br i1 %12, label %38, label %13
13: ; preds = %10, %19
%14 = phi %struct.ifaddrs* [ %21, %19 ], [ %11, %10 ]
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 2
%16 = load i32, i32* %15
%17 = call i64 @strcmp(i8* %0, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 1
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %20
%22 = icmp eq %struct.ifaddrs* %21, null
br i1 %22, label %38, label %13
23: ; preds = %13
%24 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @IFF_UP
%27 = and i32 %26, %25
%28 = icmp eq i32 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %23
%30 = load i32, i32* @IFF_RUNNING
%31 = and i32 %30, %25
%32 = icmp eq i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %29
%34 = load i32, i32* @IFF_LOOPBACK
%35 = and i32 %34, %25
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
br label %38
38: ; preds = %19, %10, %33, %29, %23
%39 = phi i32 [ 0, %29 ], [ 0, %23 ], [ %37, %33 ], [ 0, %10 ], [ 0, %19 ]
%40 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%41 = call i32 @freeifaddrs(%struct.ifaddrs* %40)
ret i32 %39
}