#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 TYPE_2__ {
  scalar_t__ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ free(struct ifreq *);
int if_IOCTL(struct ifreq *, int /*<<< orphan*/, char *);
struct ifreq *malloc(int);
int /*<<< orphan*/ memcpy(char *, scalar_t__, int);
int get_IFACE_IPv4(char *IP, char *name) {
  int ret;
  struct ifreq *if_req;
  if_req = malloc(sizeof(struct ifreq));
  if (ret = if_IOCTL(if_req, SIOCGIFADDR, name)) {
    return ret;
  }
  memcpy(IP, if_req->ifr_addr.sa_data + 2, 4);
  free(if_req);
  return 0;
}


x86 assembly (clang, -O0):
<get_IFACE_IPv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1060 <if_IOCTL@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     118b <get_IFACE_IPv4+0x4b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <get_IFACE_IPv4+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
add    $0x2,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_IFACE_IPv4>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1060 <if_IOCTL@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    118d <get_IFACE_IPv4+0x4d>
mov    (%rbx),%rsi
add    $0x2,%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@SIOCGIFADDR = global i32 0
define i32 @get_IFACE_IPv4(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.ifreq*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call %struct.ifreq* @malloc(i32 8)
store %struct.ifreq* %8, %struct.ifreq** %7
%9 = load %struct.ifreq*, %struct.ifreq** %7
%10 = load i32, i32* @SIOCGIFADDR
%11 = load i8*, i8** %5
%12 = call i32 @if_IOCTL(%struct.ifreq* %9, i32 %10, i8* %11)
store i32 %12, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %26
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load %struct.ifreq*, %struct.ifreq** %7
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = add nsw i64 %21, 2
%23 = call i32 @memcpy(i8* %17, i64 %22, i32 4)
%24 = load %struct.ifreq*, %struct.ifreq** %7
%25 = call i32 @free(%struct.ifreq* %24)
store i32 0, i32* %3
br label %26
26: ; preds = %16, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@SIOCGIFADDR = global i32 0
define i32 @get_IFACE_IPv4(i8* %0, i8* %1) {
%3 = tail call %struct.ifreq* @malloc(i32 8)
%4 = load i32, i32* @SIOCGIFADDR
%5 = tail call i32 @if_IOCTL(%struct.ifreq* %3, i32 %4, i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%9 = load i64, i64* %8
%10 = add nsw i64 %9, 2
%11 = tail call i32 @memcpy(i8* %0, i64 %10, i32 4)
%12 = tail call i32 @free(%struct.ifreq* %3)
br label %13
13: ; preds = %2, %7
ret i32 %5
}