#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct ifaddrs {
  TYPE_2__ *ifa_addr;
  int /*<<< orphan*/ ifa_name;
  struct ifaddrs *ifa_next;
};
struct TYPE_4__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
uint32_t get_ip_address() {
  struct ifaddrs *ifaddr, *ifa;
  int family, s, n;
  uint32_t result;
  if (getifaddrs(&ifaddr) == -1) {
    return 0;
  }
  for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
    if (ifa->ifa_addr == NULL)
      continue;
    if (ifa->ifa_addr->sa_family != AF_INET)
      continue;
    if (strcmp(ifa->ifa_name, "lo") == 0)
      continue;
    result = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
    freeifaddrs(ifaddr);
    return result;
  }
  freeifaddrs(ifaddr);
  return 0;
}


x86 assembly (clang, -O0):
<get_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x10(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1156 <get_ip_address+0x26>
movl   $0x0,-0x4(%rbp)
jmp    120e <get_ip_address+0xde>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fe <get_ip_address+0xce>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1183 <get_ip_address+0x53>
jmp    11e4 <get_ip_address+0xb4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
je     11a2 <get_ip_address+0x72>
jmp    11e4 <get_ip_address+0xb4>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xe50(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c4 <get_ip_address+0x94>
jmp    11e4 <get_ip_address+0xb4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <freeifaddrs@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120e <get_ip_address+0xde>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <get_ip_address+0x35>
mov    -0x10(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_address>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1040 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     11a6 <get_ip_address+0x76>
mov    (%rsp),%rbx
xor    %r14d,%r14d
test   %rbx,%rbx
je     11ab <get_ip_address+0x7b>
mov    0x2e90(%rip),%r12
lea    0xea1(%rip),%r15
jmp    1179 <get_ip_address+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     11a0 <get_ip_address+0x70>
mov    (%rbx),%rax
test   %rax,%rax
je     1170 <get_ip_address+0x40>
mov    (%rax),%rax
cmp    (%r12),%rax
jne    1170 <get_ip_address+0x40>
mov    0x8(%rbx),%edi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1170 <get_ip_address+0x40>
mov    (%rbx),%rax
mov    (%rax),%r14d
mov    (%rsp),%rdi
jmp    11ad <get_ip_address+0x7d>
xor    %r14d,%r14d
jmp    11b2 <get_ip_address+0x82>
xor    %edi,%edi
call   1050 <freeifaddrs@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_4__*, i32, %struct.ifaddrs* }
%struct.TYPE_4__ = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@AF_INET = global i64 0
@.str = [3 x i8] c"lo\00"
define i32 @get_ip_address() {
%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 %39, label %5
5: ; preds = %0
%6 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%7 = icmp eq %struct.ifaddrs* %6, null
br i1 %7, label %35, label %8
8: ; preds = %5, %29
%9 = phi %struct.ifaddrs* [ %31, %29 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 0
%11 = load %struct.TYPE_4__*, %struct.TYPE_4__** %10
%12 = icmp eq %struct.TYPE_4__* %11, null
br i1 %12, label %29, label %13
13: ; preds = %8
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i64 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 1
%20 = load i32, i32* %19
%21 = call i64 @strcmp(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = bitcast %struct.ifaddrs* %9 to %struct.sockaddr_in**
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i64 0, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %35
29: ; preds = %18, %13, %8
%30 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 2
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %30
%32 = icmp eq %struct.ifaddrs* %31, null
br i1 %32, label %33, label %8
33: ; preds = %29
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %35
35: ; preds = %5, %33, %23
%36 = phi %struct.ifaddrs* [ %28, %23 ], [ %34, %33 ], [ null, %5 ]
%37 = phi i32 [ %27, %23 ], [ 0, %33 ], [ 0, %5 ]
%38 = call i32 @freeifaddrs(%struct.ifaddrs* %36)
br label %39
39: ; preds = %35, %0
%40 = phi i32 [ 0, %0 ], [ %37, %35 ]
ret i32 %40
}