#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 */
typedef int /*<<< orphan*/ uint8_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifaddrs {
  struct ifaddrs *ifa_next;
  int /*<<< orphan*/ ifa_name;
  TYPE_1__ *ifa_addr;
};
struct TYPE_2__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs **);
int /*<<< orphan*/ getifaddrs(struct ifaddrs ***);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
scalar_t__ malloc(int);
scalar_t__ strcmp(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int get_ip(uint8_t *iface_name, uint8_t *addr_octet_contents) {
  struct ifaddrs **s = (struct ifaddrs **)malloc(10 * sizeof(struct ifaddrs *));
  getifaddrs(&s);
  struct ifaddrs *tmp = s[0];
  while (tmp) {
    if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) {
      struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
      if (strcmp(tmp->ifa_name, iface_name) == 0) {
        strcpy(addr_octet_contents, inet_ntoa(pAddr->sin_addr));
        freeifaddrs(s);
        return 0;
      }
    }
    tmp = tmp->ifa_next;
  }
  freeifaddrs(s);
  return -1;
}


x86 assembly (clang, -O0):
<get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1070 <getifaddrs@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1235 <get_ip+0xd5>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1225 <get_ip+0xc5>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
jne    1225 <get_ip+0xc5>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1220 <get_ip+0xc0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1080 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
jmp    1245 <get_ip+0xe5>
jmp    1225 <get_ip+0xc5>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1192 <get_ip+0x32>
mov    -0x20(%rbp),%rdi
call   1080 <freeifaddrs@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1070 <getifaddrs@plt>
mov    (%rsp),%rdi
mov    (%rdi),%rbp
mov    $0xffffffff,%r15d
test   %rbp,%rbp
je     11f3 <get_ip+0x93>
mov    0x2e48(%rip),%r13
jmp    11b9 <get_ip+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%rbp
test   %rbp,%rbp
je     11ef <get_ip+0x8f>
mov    0x10(%rbp),%rbx
test   %rbx,%rbx
je     11b0 <get_ip+0x50>
mov    (%rbx),%rax
cmp    0x0(%r13),%rax
jne    11b0 <get_ip+0x50>
mov    0x8(%rbp),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b0 <get_ip+0x50>
mov    (%rbx),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
xor    %r15d,%r15d
mov    (%rsp),%rdi
call   1080 <freeifaddrs@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.ifaddrs*, i32, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
define i32 @get_ip(i32* %0, i32* %1) {
%3 = alloca %struct.ifaddrs**
%4 = bitcast %struct.ifaddrs*** %3 to i8*
%5 = tail call i64 @malloc(i32 80)
%6 = inttoptr i64 %5 to %struct.ifaddrs**
store %struct.ifaddrs** %6, %struct.ifaddrs*** %3
%7 = call i32 @getifaddrs(%struct.ifaddrs*** %3)
%8 = load %struct.ifaddrs**, %struct.ifaddrs*** %3
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%10 = icmp eq %struct.ifaddrs* %9, null
br i1 %10, label %38, label %11
11: ; preds = %2, %32
%12 = phi %struct.ifaddrs* [ %34, %32 ], [ %9, %2 ]
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 2
%14 = load %struct.TYPE_2__*, %struct.TYPE_2__** %13
%15 = icmp eq %struct.TYPE_2__* %14, null
br i1 %15, label %32, label %16
16: ; preds = %11
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i64 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @AF_INET
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 1
%23 = load i32, i32* %22
%24 = call i64 @strcmp(i32 %23, i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = bitcast %struct.TYPE_2__* %14 to i32*
%28 = load i32, i32* %27
%29 = call i32 @inet_ntoa(i32 %28)
%30 = call i32 @strcpy(i32* %1, i32 %29)
%31 = load %struct.ifaddrs**, %struct.ifaddrs*** %3
br label %38
32: ; preds = %21, %16, %11
%33 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 0
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %33
%35 = icmp eq %struct.ifaddrs* %34, null
br i1 %35, label %36, label %11
36: ; preds = %32
%37 = load %struct.ifaddrs**, %struct.ifaddrs*** %3
br label %38
38: ; preds = %2, %36, %26
%39 = phi %struct.ifaddrs** [ %31, %26 ], [ %37, %36 ], [ %8, %2 ]
%40 = phi i32 [ 0, %26 ], [ -1, %36 ], [ -1, %2 ]
%41 = call i32 @freeifaddrs(%struct.ifaddrs** %39)
ret i32 %40
}