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

/* Variables and functions */
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__ *);
int main(int argc, const char **argv) {
  struct ifaddrs *ifa, *cur;
  if (getifaddrs(&ifa)) {
    perror("Failed to getifaddrs()");
    return 1;
  }
  for (cur = ifa; cur; cur = cur->ifa_next) {
    if (cur->ifa_name && cur->ifa_name[0] != 0) {
      printf("%s\n", cur->ifa_name);
      freeifaddrs(ifa);
      return 0;
    }
  }
  freeifaddrs(ifa);
  perror("no interfaces found via getifaddrs()");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0x0,%rax
je     1181 <main+0x41>
lea    0xe90(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <main+0xcd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f1 <main+0xb1>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11db <main+0x9b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     11db <main+0x9b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
jmp    120d <main+0xcd>
jmp    11e0 <main+0xa0>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1189 <main+0x49>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
lea    0xe1a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1040 <getifaddrs@plt>
test   %rax,%rax
jne    11a8 <main+0x68>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1190 <main+0x50>
mov    %rdi,%rax
jmp    1169 <main+0x29>
nopl   0x0(%rax)
mov    0x8(%rax),%rax
test   %rax,%rax
je     1190 <main+0x50>
mov    (%rax),%rsi
test   %rsi,%rsi
je     1160 <main+0x20>
cmpq   $0x0,(%rsi)
je     1160 <main+0x20>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    (%rsp),%rdi
call   1050 <freeifaddrs@plt>
xor    %eax,%eax
pop    %rcx
ret
call   1050 <freeifaddrs@plt>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.ifaddrs = type { i64*, %struct.ifaddrs* }
@.str = [23 x i8] c"Failed to getifaddrs()\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [37 x i8] c"no interfaces found via getifaddrs()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifaddrs*
%7 = alloca %struct.ifaddrs*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @getifaddrs(%struct.ifaddrs** %6)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %45
12: ; preds = %2
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %6
store %struct.ifaddrs* %13, %struct.ifaddrs** %7
br label %14
14: ; preds = %37, %12
%15 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%16 = icmp ne %struct.ifaddrs* %15, null
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i32 0, i32 0
%20 = load i64*, i64** %19
%21 = icmp ne i64* %20, null
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%24 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %23, i32 0, i32 0
%25 = load i64*, i64** %24
%26 = getelementptr inbounds i64, i64* %25, i64 0
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%31 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %30, i32 0, i32 0
%32 = load i64*, i64** %31
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %32)
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%35 = call i32 @freeifaddrs(%struct.ifaddrs* %34)
store i32 0, i32* %3
br label %45
36: ; preds = %22, %17
br label %37
37: ; preds = %36
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%39 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %38, i32 0, i32 1
%40 = load %struct.ifaddrs*, %struct.ifaddrs** %39
store %struct.ifaddrs* %40, %struct.ifaddrs** %7
br label %14
41: ; preds = %14
%42 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%43 = call i32 @freeifaddrs(%struct.ifaddrs* %42)
%44 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %45
45: ; preds = %41, %29, %10
%46 = load i32, i32* %3
ret i32 %46
}

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