#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 virt_conf_message {
  int dummy;
};
struct ifreq {
  struct virt_conf_message *ifr_data;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
scalar_t__ SIOCDEVPRIVATE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int ioctl(int, scalar_t__, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int virt_conf_ioctl(const char *device, struct virt_conf_message *msg) {
  int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
  if (sockfd < 0)
    return -1;
  struct ifreq ifr;
  strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
  ifr.ifr_data = msg;
  int result = ioctl(sockfd, (SIOCDEVPRIVATE + 15), &ifr);
  close(sockfd);
  return result;
}


x86 assembly (clang, -O0):
<virt_conf_ioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1189 <virt_conf_ioctl+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <virt_conf_ioctl+0x8d>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%rsi
add    $0xf,%rsi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<virt_conf_ioctl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11ad <virt_conf_ioctl+0x6d>
mov    %eax,%ebx
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r14,0x8(%rsp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rsi
add    $0xf,%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
jmp    11b2 <virt_conf_ioctl+0x72>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.virt_conf_message = type { i32 }
%struct.ifreq = type { %struct.virt_conf_message*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@SIOCDEVPRIVATE = global i64 0
define i32 @virt_conf_ioctl(i8* %0, %struct.virt_conf_message* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.virt_conf_message*
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca i32
store i8* %0, i8** %4
store %struct.virt_conf_message* %1, %struct.virt_conf_message** %5
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_IP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %30
16: ; preds = %2
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load i8*, i8** %4
%20 = call i32 @strncpy(i32 %18, i8* %19, i32 4)
%21 = load %struct.virt_conf_message*, %struct.virt_conf_message** %5
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
store %struct.virt_conf_message* %21, %struct.virt_conf_message** %22
%23 = load i32, i32* %6
%24 = load i64, i64* @SIOCDEVPRIVATE
%25 = add nsw i64 %24, 15
%26 = call i32 @ioctl(i32 %23, i64 %25, %struct.ifreq* %7)
store i32 %26, i32* %8
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %8
store i32 %29, i32* %3
br label %30
30: ; preds = %16, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.virt_conf_message = type { i32 }
%struct.ifreq = type { %struct.virt_conf_message*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@SIOCDEVPRIVATE = global i64 0
define i32 @virt_conf_ioctl(i8* %0, %struct.virt_conf_message* %1) {
%3 = alloca %struct.ifreq
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @IPPROTO_IP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = bitcast %struct.ifreq* %3 to i8*
%11 = tail call i32 @strncpy(i32 undef, i8* %0, i32 4)
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store %struct.virt_conf_message* %1, %struct.virt_conf_message** %12
%13 = load i64, i64* @SIOCDEVPRIVATE
%14 = add nsw i64 %13, 15
%15 = call i32 @ioctl(i32 %7, i64 %14, %struct.ifreq* %3)
%16 = call i32 @close(i32 %7)
br label %17
17: ; preds = %2, %9
%18 = phi i32 [ %15, %9 ], [ -1, %2 ]
ret i32 %18
}