#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 {
  int ifr_name;
  TYPE_1__ ifr_addr;
};

/* 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*/ strncpy(int, char *, scalar_t__);
char get_ip(void) {
  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);
  strncpy(fd, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr),
          IFNAMSIZ - 1);
  return fd;
}


x86 assembly (clang, -O0):
<get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
lea    0xe68(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rsi
mov    0x2df3(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip>:
push   %r14
push   %rbx
push   %rax
mov    0x2e85(%rip),%r14
mov    (%r14),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
mov    0x2e4a(%rip),%r14
mov    (%r14),%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe74(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    (%r14),%rdx
add    $0xffffffffffffffff,%rdx
mov    %ebx,%edi
mov    %rax,%rsi
call   1030 <strncpy@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%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
define signext i8 @get_ip() {
%1 = alloca i32
%2 = alloca %struct.ifreq
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %1
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 1
%8 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i32 0, i32 0
store i32 %6, i32* %8
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i64, i64* @IFNAMSIZ
%12 = sub nsw i64 %11, 1
%13 = call i32 @strncpy(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = load i32, i32* %1
%15 = load i32, i32* @SIOCGIFADDR
%16 = call i32 @ioctl(i32 %14, i32 %15, %struct.ifreq* %2)
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %1
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 1
%21 = bitcast %struct.TYPE_2__* %20 to %struct.sockaddr_in*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i8* @inet_ntoa(i32 %23)
%25 = load i64, i64* @IFNAMSIZ
%26 = sub nsw i64 %25, 1
%27 = call i32 @strncpy(i32 %19, i8* %24, i64 %26)
%28 = load i32, i32* %1
%29 = trunc i32 %28 to i8
ret i8 %29
}

LLVM IR (-O2):
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%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 signext i8 @get_ip() {
%1 = alloca %struct.ifreq
%2 = bitcast %struct.ifreq* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 1, i32 0
store i32 %6, i32* %7
%8 = load i64, i64* @IFNAMSIZ
%9 = add nsw i64 %8, -1
%10 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = load i32, i32* @SIOCGIFADDR
%12 = call i32 @ioctl(i32 %5, i32 %11, %struct.ifreq* %1)
%13 = call i32 @close(i32 %5)
%14 = load i32, i32* %7
%15 = call i8* @inet_ntoa(i32 %14)
%16 = load i64, i64* @IFNAMSIZ
%17 = add nsw i64 %16, -1
%18 = call i32 @strncpy(i32 %5, i8* %15, i64 %17)
%19 = trunc i32 %5 to i8
ret i8 %19
}