#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*/ u_int32_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  TYPE_1__ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ INET_ADDRSTRLEN;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct ifreq *);
int /*<<< orphan*/ socket(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, scalar_t__);
int __fetchIp(const char *__device, char *__ip) {
  register u_int32_t sock;
  signed int __ctrl;
  auto struct ifreq eth;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  eth.ifr_addr.sa_family = AF_INET;
  strncpy(eth.ifr_name, __device, (IFNAMSIZ - 1));
  __ctrl = !ioctl(sock, SIOCGIFADDR, &eth);
  if (__ctrl) {
    auto struct sockaddr_in *address = (struct sockaddr_in *)&eth.ifr_addr;
    inet_ntop(AF_INET, &(address->sin_addr), __ip, INET_ADDRSTRLEN);
  }
  return !!__ctrl;
}


x86 assembly (clang, -O0):
<__fetchIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2e42(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e8 <__fetchIp+0xa8>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    0x2ddf(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__fetchIp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
mov    0x2e8c(%rip),%r15
mov    (%r15),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,(%rsp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
mov    %rbp,%rsi
call   1040 <strncpy@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11b5 <__fetchIp+0x75>
mov    (%r15),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@INET_ADDRSTRLEN = global i32 0
define i32 @__fetchIp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca %struct.sockaddr_in*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load i8*, i8** %3
%18 = load i64, i64* @IFNAMSIZ
%19 = sub nsw i64 %18, 1
%20 = call i32 @strncpy(i32 %16, i8* %17, i64 %19)
%21 = load i32, i32* %5
%22 = load i32, i32* @SIOCGIFADDR
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.ifreq* %7)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %2
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%31 = bitcast %struct.TYPE_2__* %30 to %struct.sockaddr_in*
store %struct.sockaddr_in* %31, %struct.sockaddr_in** %8
%32 = load i32, i32* @AF_INET
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %33, i32 0, i32 0
%35 = load i8*, i8** %4
%36 = load i32, i32* @INET_ADDRSTRLEN
%37 = call i32 @inet_ntop(i32 %32, i32* %34, i8* %35, i32 %36)
br label %38
38: ; preds = %29, %2
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
%42 = xor i1 %41, true
%43 = zext i1 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@INET_ADDRSTRLEN = global i32 0
define i32 @__fetchIp(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i64, i64* @IFNAMSIZ
%11 = add nsw i64 %10, -1
%12 = tail call i32 @strncpy(i32 undef, i8* %0, i64 %11)
%13 = load i32, i32* @SIOCGIFADDR
%14 = call i32 @ioctl(i32 %7, i32 %13, %struct.ifreq* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @INET_ADDRSTRLEN
%19 = call i32 @inet_ntop(i32 %17, i32* %9, i8* %1, i32 %18)
br label %20
20: ; preds = %16, %2
%21 = zext i1 %15 to i32
ret i32 %21
}