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

/* Variables and functions */
int IFF_UP;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ show_address_info(struct ifaddrs *);
int main(int argc, char **argv) {
  struct ifaddrs *myaddrs, *ifa;
  int status;
  status = getifaddrs(&myaddrs);
  if (status != 0) {
    perror("getifaddrs failed!");
    exit(1);
  }
  for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
    if (NULL == ifa->ifa_addr) {
      continue;
    }
    if ((ifa->ifa_flags & IFF_UP) == 0) {
      continue;
    }
    show_address_info(ifa);
  }
  freeifaddrs(myaddrs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1192 <main+0x42>
lea    0xe7d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f1 <main+0xa1>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    0x8(%rcx),%rax
jne    11ba <main+0x6a>
jmp    11e0 <main+0x90>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2e21(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11d7 <main+0x87>
jmp    11e0 <main+0x90>
mov    -0x20(%rbp),%rdi
call   1030 <show_address_info@plt>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    119a <main+0x4a>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1040 <getifaddrs@plt>
test   %eax,%eax
jne    11b8 <main+0x68>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11a7 <main+0x57>
mov    0x2e78(%rip),%r14
jmp    1189 <main+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     11a1 <main+0x51>
cmpq   $0x0,0x8(%rbx)
je     1180 <main+0x30>
mov    (%r14),%eax
test   %eax,(%rbx)
je     1180 <main+0x30>
mov    %rbx,%rdi
call   1030 <show_address_info@plt>
jmp    1180 <main+0x30>
mov    (%rsp),%rdi
jmp    11a9 <main+0x59>
xor    %edi,%edi
call   1050 <freeifaddrs@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.ifaddrs = type { i32, i32*, %struct.ifaddrs* }
@.str = [19 x i8] c"getifaddrs failed!\00"
@IFF_UP = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.ifaddrs*
%4 = bitcast %struct.ifaddrs** %3 to i8*
%5 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%6 = icmp eq i32 %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 %32, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %26
%14 = phi %struct.ifaddrs* [ %28, %26 ], [ %8, %7 ]
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 1
%16 = load i32*, i32** %15
%17 = icmp eq i32* %16, null
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @IFF_UP
%22 = and i32 %21, %20
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 @show_address_info(%struct.ifaddrs* %14)
br label %26
26: ; preds = %18, %13, %24
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 2
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %27
%29 = icmp eq %struct.ifaddrs* %28, null
br i1 %29, label %30, label %13
30: ; preds = %26
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br label %32
32: ; preds = %30, %7
%33 = phi %struct.ifaddrs* [ %31, %30 ], [ null, %7 ]
%34 = call i32 @freeifaddrs(%struct.ifaddrs* %33)
ret i32 0
}