#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifreq {
  int /*<<< orphan*/ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
char *inet_ntoa(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main() {
  int inet_sock;
  struct ifreq ifr;
  inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
  strcpy(ifr.ifr_name, "eno16777736");
  if (ioctl(inet_sock, SIOCGIFADDR, &ifr) < 0)
    perror("ioctl");
  printf("%s\n", inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe6b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    11c5 <main+0x65>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
lea    0xe79(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
js     11c6 <main+0x66>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe3f(%rip),%rdi
call   1070 <perror@plt>
jmp    11a6 <main+0x46>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"eno16777736\00"
@SIOCGIFADDR = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.ifreq
store i32 0, i32* %1
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%8 = load i32, i32* %7
%9 = call i32 @strcpy(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = load i32, i32* @SIOCGIFADDR
%12 = call i64 @ioctl(i32 %10, i32 %11, %struct.ifreq* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%18 = bitcast i32* %17 to %struct.sockaddr_in*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i8* @inet_ntoa(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"eno16777736\00"
@SIOCGIFADDR = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%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 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @SIOCGIFADDR
%8 = call i64 @ioctl(i32 %5, i32 %7, %struct.ifreq* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @inet_ntoa(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15)
ret i32 0
}