#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 /*<<< orphan*/ getifaddrs(struct ifaddrs **);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
uint32_t getMyIp(const char *networkInterface) {
  struct ifaddrs *ifAddrStruct = NULL;
  struct ifaddrs *ifa = NULL;
  getifaddrs(&ifAddrStruct);
  for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
    if (!ifa->ifa_addr) {
      continue;
    }
    if (ifa->ifa_addr->sa_family == AF_INET) {
      if (strcmp(ifa->ifa_name, networkInterface) == 0) {
        return (uint32_t)((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
      }
    }
  }
  if (ifAddrStruct != NULL)
    freeifaddrs(ifAddrStruct);
  return 0;
}


x86 assembly (clang, -O0):
<getMyIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11db <getMyIp+0xab>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117b <getMyIp+0x4b>
jmp    11ca <getMyIp+0x9a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    11c5 <getMyIp+0x95>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c0 <getMyIp+0x90>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <getMyIp+0xc6>
jmp    11c5 <getMyIp+0x95>
jmp    11ca <getMyIp+0x9a>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    115d <getMyIp+0x2d>
cmpq   $0x0,-0x18(%rbp)
je     11ef <getMyIp+0xbf>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMyIp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1040 <getifaddrs@plt>
mov    (%rsp),%rbp
xor    %r14d,%r14d
test   %rbp,%rbp
je     11a1 <getMyIp+0x71>
mov    0x2e8b(%rip),%rbx
jmp    1169 <getMyIp+0x39>
nop
mov    0x10(%rbp),%rbp
test   %rbp,%rbp
je     1193 <getMyIp+0x63>
mov    0x0(%rbp),%rax
test   %rax,%rax
je     1160 <getMyIp+0x30>
mov    (%rax),%rax
cmp    (%rbx),%rax
jne    1160 <getMyIp+0x30>
mov    0x8(%rbp),%edi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1160 <getMyIp+0x30>
mov    0x0(%rbp),%rax
mov    (%rax),%r14d
jmp    11a1 <getMyIp+0x71>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11a1 <getMyIp+0x71>
call   1050 <freeifaddrs@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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
define i32 @getMyIp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.ifaddrs*
%5 = alloca %struct.ifaddrs*
store i8* %0, i8** %3
store %struct.ifaddrs* null, %struct.ifaddrs** %4
store %struct.ifaddrs* null, %struct.ifaddrs** %5
%6 = call i32 @getifaddrs(%struct.ifaddrs** %4)
%7 = load %struct.ifaddrs*, %struct.ifaddrs** %4
store %struct.ifaddrs* %7, %struct.ifaddrs** %5
br label %8
8: ; preds = %42, %1
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%10 = icmp ne %struct.ifaddrs* %9, null
br i1 %10, label %11, label %46
11: ; preds = %8
%12 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i32 0, i32 0
%14 = load %struct.TYPE_4__*, %struct.TYPE_4__** %13
%15 = icmp ne %struct.TYPE_4__* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
br label %42
17: ; preds = %11
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i32 0, i32 0
%20 = load %struct.TYPE_4__*, %struct.TYPE_4__** %19
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @AF_INET
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %17
%26 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%27 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = load i8*, i8** %3
%30 = call i64 @strcmp(i32 %28, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %25
%33 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%34 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %33, i32 0, i32 0
%35 = load %struct.TYPE_4__*, %struct.TYPE_4__** %34
%36 = bitcast %struct.TYPE_4__* %35 to %struct.sockaddr_in*
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 0
%39 = load i32, i32* %38
store i32 %39, i32* %2
br label %53
40: ; preds = %25
br label %41
41: ; preds = %40, %17
br label %42
42: ; preds = %41, %16
%43 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%44 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %43, i32 0, i32 2
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %44
store %struct.ifaddrs* %45, %struct.ifaddrs** %5
br label %8
46: ; preds = %8
%47 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%48 = icmp ne %struct.ifaddrs* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%51 = call i32 @freeifaddrs(%struct.ifaddrs* %50)
br label %52
52: ; preds = %49, %46
store i32 0, i32* %2
br label %53
53: ; preds = %52, %32
%54 = load i32, i32* %2
ret i32 %54
}

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
define i32 @getMyIp(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = bitcast %struct.ifaddrs** %2 to i8*
store %struct.ifaddrs* null, %struct.ifaddrs** %2
%4 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%5 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%6 = icmp eq %struct.ifaddrs* %5, null
br i1 %6, label %36, label %7
7: ; preds = %1, %27
%8 = phi %struct.ifaddrs* [ %29, %27 ], [ %5, %1 ]
%9 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %8, i64 0, i32 0
%10 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%11 = icmp eq %struct.TYPE_4__* %10, null
br i1 %11, label %27, label %12
12: ; preds = %7
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @AF_INET
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %8, i64 0, i32 1
%19 = load i32, i32* %18
%20 = call i64 @strcmp(i32 %19, i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = bitcast %struct.ifaddrs* %8 to %struct.sockaddr_in**
%24 = load %struct.sockaddr_in*, %struct.sockaddr_in** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i64 0, i32 0, i32 0
%26 = load i32, i32* %25
br label %36
27: ; preds = %12, %17, %7
%28 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %8, i64 0, i32 2
%29 = load %struct.ifaddrs*, %struct.ifaddrs** %28
%30 = icmp eq %struct.ifaddrs* %29, null
br i1 %30, label %31, label %7
31: ; preds = %27
%32 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%33 = icmp eq %struct.ifaddrs* %32, null
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @freeifaddrs(%struct.ifaddrs* %32)
br label %36
36: ; preds = %1, %31, %34, %22
%37 = phi i32 [ %26, %22 ], [ 0, %34 ], [ 0, %31 ], [ 0, %1 ]
ret i32 %37
}