#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 */
typedef int /*<<< orphan*/ perror_string;

/* Variables and functions */
int /*<<< orphan*/ abort();
int ioctl(int, int, void *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, void *);
void xioctl(int fd, int request, void *arg) {
  int rv = ioctl(fd, request, arg);
  if (rv < 0) {
    char perror_string[1024];
    snprintf(perror_string, sizeof(perror_string), "ioctl(%d, %d, %p)", fd,
             request, arg);
    perror(perror_string);
    abort();
  }
}


x86 assembly (clang, -O0):
<xioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a7 <xioctl+0x67>
lea    -0x420(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0x10(%rbp),%r9
mov    $0x400,%esi
lea    0xe71(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xioctl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
call   1050 <ioctl@plt>
test   %eax,%eax
js     116b <xioctl+0x2b>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe8e(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r14,%r9
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"ioctl(%d, %d, %p)\00"
define void @xioctl(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = call i32 @ioctl(i32 %9, i32 %10, i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = load i8*, i8** %6
%20 = call i32 @snprintf(i8* %16, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%22 = call i32 @perror(i8* %21)
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"ioctl(%d, %d, %p)\00"
define void @xioctl(i32 %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = tail call i32 @ioctl(i32 %0, i32 %1, i8* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @snprintf(i8* %8, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i8* %2)
%10 = call i32 @perror(i8* %8)
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %3
ret void
}