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

/* Variables and functions */
int errno;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int check_existent_interface(char *interface) {
  struct ifaddrs *ifa, *if_aux;
  if (getifaddrs(&ifa) == -1)
    return -1;
  if_aux = ifa;
  for (; if_aux != NULL; if_aux = if_aux->ifa_next) {
    if (if_aux->ifa_addr == NULL)
      continue;
    if (strcmp(if_aux->ifa_name, interface) == 0) {
      freeifaddrs(ifa);
      return 0;
    }
  }
  freeifaddrs(ifa);
  errno = -1;
  return -1;
}


x86 assembly (clang, -O0):
<check_existent_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    115a <check_existent_interface+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <check_existent_interface+0xb2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c5 <check_existent_interface+0x95>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1181 <check_existent_interface+0x51>
jmp    11b4 <check_existent_interface+0x84>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11af <check_existent_interface+0x7f>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <check_existent_interface+0xb2>
jmp    11b4 <check_existent_interface+0x84>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <check_existent_interface+0x32>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
mov    0x2e0b(%rip),%rax
movl   $0xffffffff,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_existent_interface>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1040 <getifaddrs@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11a6 <check_existent_interface+0x76>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
jne    1169 <check_existent_interface+0x39>
xor    %edi,%edi
jmp    1194 <check_existent_interface+0x64>
xchg   %ax,%ax
mov    0x10(%rbp),%rbp
test   %rbp,%rbp
je     118f <check_existent_interface+0x5f>
cmpq   $0x0,0x8(%rbp)
je     1160 <check_existent_interface+0x30>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1160 <check_existent_interface+0x30>
mov    0x8(%rsp),%rdi
call   1050 <freeifaddrs@plt>
xor    %r14d,%r14d
jmp    11a6 <check_existent_interface+0x76>
mov    0x8(%rsp),%rdi
call   1050 <freeifaddrs@plt>
mov    0x2e40(%rip),%rax
movl   $0xffffffff,(%rax)
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.ifaddrs = type { i32, i32*, %struct.ifaddrs* }
@errno = global i32 0
define i32 @check_existent_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 %31, label %6
6: ; preds = %1
%7 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%8 = icmp eq %struct.ifaddrs* %7, null
br i1 %8, label %28, label %9
9: ; preds = %6, %22
%10 = phi %struct.ifaddrs* [ %24, %22 ], [ %7, %6 ]
%11 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 1
%12 = load i32*, i32** %11
%13 = icmp eq i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @strcmp(i32 %16, i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%21 = call i32 @freeifaddrs(%struct.ifaddrs* %20)
br label %31
22: ; preds = %14, %9
%23 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %10, i64 0, i32 2
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %23
%25 = icmp eq %struct.ifaddrs* %24, null
br i1 %25, label %26, label %9
26: ; preds = %22
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %2
br label %28
28: ; preds = %26, %6
%29 = phi %struct.ifaddrs* [ %27, %26 ], [ null, %6 ]
%30 = call i32 @freeifaddrs(%struct.ifaddrs* %29)
store i32 -1, i32* @errno
br label %31
31: ; preds = %1, %28, %19
%32 = phi i32 [ 0, %19 ], [ -1, %28 ], [ -1, %1 ]
ret i32 %32
}