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

/* 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 **);
char *strdup(int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *get_interface(void) {
  struct ifaddrs *ifaddr, *ifa;
  char *ret = NULL;
  if (getifaddrs(&ifaddr) == -1) {
    die(strerror(errno));
  }
  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    unsigned int flags = ifa->ifa_flags;
    if ((flags & IFF_UP) && (flags & IFF_RUNNING) && !(flags & IFF_LOOPBACK)) {
      ret = strdup(ifa->ifa_name);
      break;
    }
  }
  freeifaddrs(ifaddr);
  return ret;
}


x86 assembly (clang, -O0):
<get_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1187 <get_interface+0x37>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edi
call   1050 <die@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120d <get_interface+0xbd>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e2b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11f7 <get_interface+0xa7>
mov    -0x1c(%rbp),%eax
mov    0x2e1e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11f7 <get_interface+0xa7>
mov    -0x1c(%rbp),%eax
mov    0x2e21(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11f7 <get_interface+0xa7>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    120d <get_interface+0xbd>
jmp    11fc <get_interface+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    118f <get_interface+0x3f>
mov    -0x8(%rbp),%rdi
call   1040 <freeifaddrs@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_interface>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1030 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1176 <get_interface+0x26>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edi
call   1050 <die@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11db <get_interface+0x8b>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%r8d
mov    0x2e5f(%rip),%rdx
mov    (%rdx),%edx
xor    %r14d,%r14d
mov    %rdi,%rsi
jmp    11b9 <get_interface+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsi),%rsi
test   %rsi,%rsi
je     11e0 <get_interface+0x90>
mov    (%rsi),%ebx
test   %ebx,%eax
je     11b0 <get_interface+0x60>
mov    %r8d,%ecx
and    %ebx,%ecx
je     11b0 <get_interface+0x60>
and    %edx,%ebx
jne    11b0 <get_interface+0x60>
mov    0x4(%rsi),%edi
call   1060 <strdup@plt>
mov    %rax,%r14
mov    (%rsp),%rdi
jmp    11e0 <get_interface+0x90>
xor    %edi,%edi
xor    %r14d,%r14d
call   1040 <freeifaddrs@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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