#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 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*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
void getIP(char *retIP) {
  int fd;
  struct ifreq ifr;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, "eth0", IFNAMSIZ - 1);
  ioctl(fd, SIOCGIFADDR, &ifr);
  close(fd);
  sprintf(retIP, "%s",
          inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
}


x86 assembly (clang, -O0):
<getIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
lea    0xe54(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rdx
lea    0xe19(%rip),%rsi
call   1070 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIP>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e6e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe5f(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
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
@.str = [5 x i8] c"eth0\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @getIP(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.ifreq
store i8* %0, i8** %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load i64, i64* @IFNAMSIZ
%14 = sub nsw i64 %13, 1
%15 = call i32 @strncpy(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* @SIOCGIFADDR
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.ifreq* %4)
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
%21 = load i8*, i8** %2
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%23 = bitcast %struct.TYPE_2__* %22 to %struct.sockaddr_in*
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
%27 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
ret void
}

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
@.str = [5 x i8] c"eth0\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
define void @getIP(i8* %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
store i32 %7, i32* %8
%9 = load i64, i64* @IFNAMSIZ
%10 = add nsw i64 %9, -1
%11 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @SIOCGIFADDR
%13 = call i32 @ioctl(i32 %6, i32 %12, %struct.ifreq* %2)
%14 = call i32 @close(i32 %6)
%15 = load i32, i32* %8
%16 = call i8* @inet_ntoa(i32 %15)
%17 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %16)
ret void
}