#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;
  int /*<<< orphan*/ ifa_name;
  struct ifaddrs *ifa_next;
};
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*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *getPrimaryIP() {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  char interface[5];
  char addr[20];
  getifaddrs(&ifap);
  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    if (((strcmp("lo", ifa->ifa_name) != 0) &&
         (strcmp("lo0", ifa->ifa_name))) &&
        (ifa->ifa_addr->sa_family == AF_INET)) {
      strcpy(interface, ifa->ifa_name);
      sa = (struct sockaddr_in *)ifa->ifa_addr;
      strcpy(addr, inet_ntoa(sa->sin_addr));
      break;
    }
  }
  freeifaddrs(ifap);
  if (1)
    printf("addr %s\n", addr);
  return addr;
}


x86 assembly (clang, -O0):
<getPrimaryIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x8(%rbp),%rdi
call   1070 <getifaddrs@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     122c <getPrimaryIP+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe6e(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1216 <getPrimaryIP+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe54(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1216 <getPrimaryIP+0xb6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
jne    1216 <getPrimaryIP+0xb6>
lea    -0x1d(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
jmp    122c <getPrimaryIP+0xcc>
jmp    121b <getPrimaryIP+0xbb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1179 <getPrimaryIP+0x19>
mov    -0x8(%rbp),%rdi
call   1080 <freeifaddrs@plt>
lea    -0x40(%rbp),%rsi
lea    0xdc7(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPrimaryIP>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%rdi
call   1070 <getifaddrs@plt>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11f8 <getPrimaryIP+0x98>
lea    0xe7d(%rip),%r15
lea    0xe79(%rip),%r14
mov    0x2e57(%rip),%r12
jmp    11a9 <getPrimaryIP+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     11f8 <getPrimaryIP+0x98>
mov    0x8(%rbx),%esi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <getPrimaryIP+0x40>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <getPrimaryIP+0x40>
mov    (%rbx),%rax
mov    (%rax),%rax
cmp    (%r12),%rax
jne    11a0 <getPrimaryIP+0x40>
mov    0x8(%rbx),%esi
lea    0xb(%rsp),%rdi
call   1030 <strcpy@plt>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
lea    0x10(%rsp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    (%rsp),%rdi
call   1080 <freeifaddrs@plt>
lea    0xdff(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_2__*, i32, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr_in = type { i32 }
@.str = [3 x i8] c"lo\00"
@.str.1 = [4 x i8] c"lo0\00"
@AF_INET = global i64 0
@.str.2 = [9 x i8] c"addr %s\0A\00"
define i8* @getPrimaryIP() {
%1 = alloca %struct.ifaddrs*
%2 = alloca %struct.ifaddrs*
%3 = alloca %struct.sockaddr_in*
%4 = alloca [5 x i8]
%5 = alloca [20 x i8]
%6 = call i32 @getifaddrs(%struct.ifaddrs** %1)
%7 = load %struct.ifaddrs*, %struct.ifaddrs** %1
store %struct.ifaddrs* %7, %struct.ifaddrs** %2
br label %8
8: ; preds = %48, %0
%9 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%10 = icmp ne %struct.ifaddrs* %9, null
br i1 %10, label %11, label %52
11: ; preds = %8
%12 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %47
17: ; preds = %11
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %47
23: ; preds = %17
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %24, i32 0, i32 0
%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 %47
31: ; preds = %23
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%33 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%34 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 @strcpy(i8* %32, i32 %35)
%37 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%38 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %37, i32 0, i32 0
%39 = load %struct.TYPE_2__*, %struct.TYPE_2__** %38
%40 = bitcast %struct.TYPE_2__* %39 to %struct.sockaddr_in*
store %struct.sockaddr_in* %40, %struct.sockaddr_in** %3
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%42 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @inet_ntoa(i32 %44)
%46 = call i32 @strcpy(i8* %41, i32 %45)
br label %52
47: ; preds = %23, %17, %11
br label %48
48: ; preds = %47
%49 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%50 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %49, i32 0, i32 2
%51 = load %struct.ifaddrs*, %struct.ifaddrs** %50
store %struct.ifaddrs* %51, %struct.ifaddrs** %2
br label %8
52: ; preds = %31, %8
%53 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%54 = call i32 @freeifaddrs(%struct.ifaddrs* %53)
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
ret i8* %57
}

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