#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 **);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
uint32_t getipv4addr(char *intname) {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  uint32_t rval = 0;
  getifaddrs(&ifap);
  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    if ((ifa->ifa_addr->sa_family == AF_INET) &&
        !(strcmp(ifa->ifa_name, intname))) {
      sa = (struct sockaddr_in *)ifa->ifa_addr;
      rval = sa->sin_addr.s_addr;
    }
  }
  freeifaddrs(ifap);
  return (htonl(rval));
}


x86 assembly (clang, -O0):
<getipv4addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <getifaddrs@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cc <getipv4addr+0x8c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11b6 <getipv4addr+0x76>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11b6 <getipv4addr+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11bb <getipv4addr+0x7b>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1164 <getipv4addr+0x24>
mov    -0x10(%rbp),%rdi
call   1060 <freeifaddrs@plt>
mov    -0x24(%rbp),%edi
call   1030 <htonl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getipv4addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1050 <getifaddrs@plt>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     11a3 <getipv4addr+0x63>
mov    0x2e86(%rip),%r15
mov    (%r15),%rcx
xor    %r14d,%r14d
jmp    1179 <getipv4addr+0x39>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rbp),%rbp
test   %rbp,%rbp
je     119d <getipv4addr+0x5d>
mov    0x0(%rbp),%rax
cmp    %rcx,(%rax)
jne    1170 <getipv4addr+0x30>
mov    0x8(%rbp),%edi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
mov    (%r15),%rcx
test   %eax,%eax
jne    1170 <getipv4addr+0x30>
mov    0x0(%rbp),%rax
mov    (%rax),%r14d
jmp    1170 <getipv4addr+0x30>
mov    (%rsp),%rdi
jmp    11a8 <getipv4addr+0x68>
xor    %edi,%edi
xor    %r14d,%r14d
call   1060 <freeifaddrs@plt>
mov    %r14d,%edi
call   1030 <htonl@plt>
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 @getipv4addr(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%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 = %37, %1
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%11 = icmp ne %struct.ifaddrs* %10, null
br i1 %11, label %12, label %41
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_4__*, %struct.TYPE_4__** %14
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %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 %36
20: ; preds = %12
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %2
%25 = call i32 @strcmp(i32 %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %36, label %27
27: ; preds = %20
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 0
%30 = load %struct.TYPE_4__*, %struct.TYPE_4__** %29
%31 = bitcast %struct.TYPE_4__* %30 to %struct.sockaddr_in*
store %struct.sockaddr_in* %31, %struct.sockaddr_in** %5
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 0
%35 = load i32, i32* %34
store i32 %35, i32* %6
br label %36
36: ; preds = %27, %20, %12
br label %37
37: ; preds = %36
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%39 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %38, i32 0, i32 2
%40 = load %struct.ifaddrs*, %struct.ifaddrs** %39
store %struct.ifaddrs* %40, %struct.ifaddrs** %4
br label %9
41: ; preds = %9
%42 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%43 = call i32 @freeifaddrs(%struct.ifaddrs* %42)
%44 = load i32, i32* %6
%45 = call i32 @htonl(i32 %44)
ret i32 %45
}

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