#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifaddrs {
  TYPE_1__ *ifa_addr;
  struct ifaddrs *ifa_next;
};
struct TYPE_2__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
char *inet_ntoa(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int HaveAnIPAddress(void) {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  char *addr;
  int FoundAddress;
  FoundAddress = 0;
  if (getifaddrs(&ifap) == 0) {
    for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
      if (ifa->ifa_addr != NULL) {
        if (ifa->ifa_addr->sa_family == AF_INET) {
          sa = (struct sockaddr_in *)ifa->ifa_addr;
          addr = inet_ntoa(sa->sin_addr);
          if (strcmp(addr, "127.0.0.1") != 0) {
            FoundAddress = 1;
          }
        }
      }
    }
  }
  freeifaddrs(ifap);
  return FoundAddress;
}


x86 assembly (clang, -O0):
<HaveAnIPAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x24(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0x0,%rax
jne    11fd <HaveAnIPAddress+0xbd>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f8 <HaveAnIPAddress+0xb8>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11e2 <HaveAnIPAddress+0xa2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <HaveAnIPAddress+0x9d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11d8 <HaveAnIPAddress+0x98>
movl   $0x1,-0x24(%rbp)
jmp    11dd <HaveAnIPAddress+0x9d>
jmp    11e2 <HaveAnIPAddress+0xa2>
jmp    11e7 <HaveAnIPAddress+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    116a <HaveAnIPAddress+0x2a>
jmp    11fd <HaveAnIPAddress+0xbd>
mov    -0x8(%rbp),%rdi
call   1060 <freeifaddrs@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HaveAnIPAddress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
xor    %ebp,%ebp
mov    0x8(%rsp),%rbx
test   %rax,%rax
jne    11b7 <HaveAnIPAddress+0x77>
test   %rbx,%rbx
je     11b7 <HaveAnIPAddress+0x77>
xor    %ebp,%ebp
mov    0x2e78(%rip),%r15
lea    0xe89(%rip),%r14
mov    $0x1,%r12d
jmp    1189 <HaveAnIPAddress+0x49>
nop
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     11b2 <HaveAnIPAddress+0x72>
mov    (%rbx),%rax
test   %rax,%rax
je     1180 <HaveAnIPAddress+0x40>
mov    (%rax),%rdi
cmp    (%r15),%rdi
jne    1180 <HaveAnIPAddress+0x40>
call   1030 <inet_ntoa@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
cmovne %r12d,%ebp
jmp    1180 <HaveAnIPAddress+0x40>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <freeifaddrs@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i64 0
@.str = [10 x i8] c"127.0.0.1\00"
define i32 @HaveAnIPAddress() {
%1 = alloca %struct.ifaddrs*
%2 = alloca %struct.ifaddrs*
%3 = alloca %struct.sockaddr_in*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %5
%6 = call i64 @getifaddrs(%struct.ifaddrs** %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %47
8: ; preds = %0
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %1
store %struct.ifaddrs* %9, %struct.ifaddrs** %2
br label %10
10: ; preds = %42, %8
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%12 = icmp ne %struct.ifaddrs* %11, null
br i1 %12, label %13, label %46
13: ; preds = %10
%14 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i32 0, i32 0
%16 = load %struct.TYPE_2__*, %struct.TYPE_2__** %15
%17 = icmp ne %struct.TYPE_2__* %16, null
br i1 %17, label %18, label %41
18: ; preds = %13
%19 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %19, i32 0, i32 0
%21 = load %struct.TYPE_2__*, %struct.TYPE_2__** %20
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @AF_INET
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %18
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%28 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %27, i32 0, i32 0
%29 = load %struct.TYPE_2__*, %struct.TYPE_2__** %28
%30 = bitcast %struct.TYPE_2__* %29 to %struct.sockaddr_in*
store %struct.sockaddr_in* %30, %struct.sockaddr_in** %3
%31 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i8* @inet_ntoa(i32 %33)
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %26
store i32 1, i32* %5
br label %39
39: ; preds = %38, %26
br label %40
40: ; preds = %39, %18
br label %41
41: ; preds = %40, %13
br label %42
42: ; preds = %41
%43 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%44 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %43, i32 0, i32 1
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %44
store %struct.ifaddrs* %45, %struct.ifaddrs** %2
br label %10
46: ; preds = %10
br label %47
47: ; preds = %46, %0
%48 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%49 = call i32 @freeifaddrs(%struct.ifaddrs* %48)
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@.str = [10 x i8] c"127.0.0.1\00"
define i32 @HaveAnIPAddress() {
%1 = alloca %struct.ifaddrs*
%2 = bitcast %struct.ifaddrs** %1 to i8*
%3 = call i64 @getifaddrs(%struct.ifaddrs** %1)
%4 = icmp ne i64 %3, 0
%5 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%6 = icmp eq %struct.ifaddrs* %5, null
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %32, label %8
8: ; preds = %0, %25
%9 = phi %struct.ifaddrs* [ %28, %25 ], [ %5, %0 ]
%10 = phi i32 [ %26, %25 ], [ 0, %0 ]
%11 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 0
%12 = load %struct.TYPE_2__*, %struct.TYPE_2__** %11
%13 = icmp eq %struct.TYPE_2__* %12, null
br i1 %13, label %25, label %14
14: ; preds = %8
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i64 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = trunc i64 %16 to i32
%21 = call i8* @inet_ntoa(i32 %20)
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i32 %10, i32 1
br label %25
25: ; preds = %19, %8, %14
%26 = phi i32 [ %10, %14 ], [ %10, %8 ], [ %24, %19 ]
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 1
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %27
%29 = icmp eq %struct.ifaddrs* %28, null
br i1 %29, label %30, label %8
30: ; preds = %25
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %32
32: ; preds = %30, %0
%33 = phi %struct.ifaddrs* [ %5, %0 ], [ %31, %30 ]
%34 = phi i32 [ 0, %0 ], [ %26, %30 ]
%35 = call i32 @freeifaddrs(%struct.ifaddrs* %33)
ret i32 %34
}