#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 *);
int /*<<< orphan*/ getifaddrs(struct ifaddrs **);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
void ipaddr(char ip[30]) {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  char *addr;
  getifaddrs(&ifap);
  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    if (ifa->ifa_addr->sa_family == AF_INET) {
      sa = (struct sockaddr_in *)ifa->ifa_addr;
      addr = inet_ntoa(sa->sin_addr);
    }
  }
  strcpy(ip, addr);
  freeifaddrs(ifap);
}


x86 assembly (clang, -O0):
<ipaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <getifaddrs@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b2 <ipaddr+0x72>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <ipaddr+0x5c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x28(%rbp)
jmp    11a1 <ipaddr+0x61>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    115d <ipaddr+0x1d>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <freeifaddrs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipaddr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
mov    0x8(%rsp),%rbx
mov    0x2e86(%rip),%r15
mov    (%r15),%rcx
jmp    1179 <ipaddr+0x39>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     118e <ipaddr+0x4e>
mov    (%rbx),%rdx
mov    (%rdx),%rdi
cmp    %rcx,%rdi
jne    1170 <ipaddr+0x30>
call   1040 <inet_ntoa@plt>
mov    (%r15),%rcx
jmp    1170 <ipaddr+0x30>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%rdi
call   1060 <freeifaddrs@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
define void @ipaddr(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%8 = load %struct.ifaddrs*, %struct.ifaddrs** %3
store %struct.ifaddrs* %8, %struct.ifaddrs** %4
br label %9
9: ; preds = %30, %1
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%11 = icmp ne %struct.ifaddrs* %10, null
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%14 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %13, i32 0, i32 0
%15 = load %struct.TYPE_2__*, %struct.TYPE_2__** %14
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @AF_INET
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %12
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i32 0, i32 0
%23 = load %struct.TYPE_2__*, %struct.TYPE_2__** %22
%24 = bitcast %struct.TYPE_2__* %23 to %struct.sockaddr_in*
store %struct.sockaddr_in* %24, %struct.sockaddr_in** %5
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i8* @inet_ntoa(i32 %27)
store i8* %28, i8** %6
br label %29
29: ; preds = %20, %12
br label %30
30: ; preds = %29
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%32 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %31, i32 0, i32 1
%33 = load %struct.ifaddrs*, %struct.ifaddrs** %32
store %struct.ifaddrs* %33, %struct.ifaddrs** %4
br label %9
34: ; preds = %9
%35 = load i8*, i8** %2
%36 = load i8*, i8** %6
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%39 = call i32 @freeifaddrs(%struct.ifaddrs* %38)
ret void
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_2__*, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
define void @ipaddr(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = bitcast %struct.ifaddrs** %2 to i8*
%4 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%5 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%6 = load i64, i64* @AF_INET
br label %7
7: ; preds = %1, %20
%8 = phi i64 [ %21, %20 ], [ %6, %1 ]
%9 = phi %struct.ifaddrs* [ %24, %20 ], [ %5, %1 ]
%10 = phi i8* [ %22, %20 ], [ undef, %1 ]
%11 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 0
%12 = load %struct.TYPE_2__*, %struct.TYPE_2__** %11
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %20
16: ; preds = %7
%17 = trunc i64 %14 to i32
%18 = call i8* @inet_ntoa(i32 %17)
%19 = load i64, i64* @AF_INET
br label %20
20: ; preds = %7, %16
%21 = phi i64 [ %19, %16 ], [ %8, %7 ]
%22 = phi i8* [ %18, %16 ], [ %10, %7 ]
%23 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %9, i64 0, i32 1
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %23
%25 = icmp eq %struct.ifaddrs* %24, null
br i1 %25, label %26, label %7
26: ; preds = %20
%27 = call i32 @strcpy(i8* %0, i8* %22)
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%29 = call i32 @freeifaddrs(%struct.ifaddrs* %28)
ret void
}