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

/* Variables and functions */
int /*<<< orphan*/ CDROM_GET_CAPABILITY;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int stat_optical_get_caps(int fd) {
  int caps = 0;
  int rc = 0;
  caps = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
  if (caps < 0) {
    rc = -errno;
    fprintf(stderr, "CDROM_GET_CAPABILITY ioctl failed, rc = %d\n", rc);
    return rc;
  }
  return caps;
}


x86 assembly (clang, -O0):
<stat_optical_get_caps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118c <stat_optical_get_caps+0x6c>
xor    %eax,%eax
mov    0x2e74(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <stat_optical_get_caps+0x72>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_optical_get_caps>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1139 <stat_optical_get_caps+0x19>
pop    %rbx
ret
mov    0x2e98(%rip),%rax
sub    (%rax),%ebx
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@CDROM_GET_CAPABILITY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"CDROM_GET_CAPABILITY ioctl failed, rc = %d\0A\00"
define i32 @stat_optical_get_caps(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @CDROM_GET_CAPABILITY
%8 = call i32 @ioctl(i32 %6, i32 %7, i32* null)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = sub nsw i32 0, %12
store i32 %13, i32* %5
%14 = load i32, i32* @stderr
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %20
18: ; preds = %1
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %11
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@CDROM_GET_CAPABILITY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"CDROM_GET_CAPABILITY ioctl failed, rc = %d\0A\00"
define i32 @stat_optical_get_caps(i32 %0) {
%2 = load i32, i32* @CDROM_GET_CAPABILITY
%3 = tail call i32 @ioctl(i32 %0, i32 %2, i32* null)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = sub nsw i32 0, %6
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %7, %5 ], [ %3, %1 ]
ret i32 %11
}