#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*/ HDIO_GET_WCACHE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, unsigned long);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned long *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int getWriteCacheStatus(int fd) {
  unsigned long val = 0;
  if (ioctl(fd, HDIO_GET_WCACHE, &val) >= 0) {
    fprintf(stderr, "*info* write cache setting for %d is %lu\n", fd, val);
  } else {
    perror("ioctl");
  }
  return val;
}


x86 assembly (clang, -O0):
<getWriteCacheStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jl     1183 <getWriteCacheStatus+0x53>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe87(%rip),%rsi
call   1040 <fprintf@plt>
jmp    118f <getWriteCacheStatus+0x5f>
lea    0xea0(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWriteCacheStatus>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movq   $0x0,0x8(%rsp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     117e <getWriteCacheStatus+0x4e>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rcx
lea    0xe93(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xea5(%rip),%rdi
call   1050 <perror@plt>
jmp    1174 <getWriteCacheStatus+0x44>

LLVM IR (-O0):
@HDIO_GET_WCACHE = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"*info* write cache setting for %d is %lu\0A\00"
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @getWriteCacheStatus(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
store i64 0, i64* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @HDIO_GET_WCACHE
%6 = call i64 @ioctl(i32 %4, i32 %5, i64* %3)
%7 = icmp sge i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = load i64, i64* %3
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %10, i64 %11)
br label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = load i64, i64* %3
%17 = trunc i64 %16 to i32
ret i32 %17
}

LLVM IR (-O2):
@HDIO_GET_WCACHE = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"*info* write cache setting for %d is %lu\0A\00"
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @getWriteCacheStatus(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = load i32, i32* @HDIO_GET_WCACHE
%5 = call i64 @ioctl(i32 %0, i32 %4, i64* %2)
%6 = icmp sgt i64 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i64, i64* %2
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %9)
br label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = load i64, i64* %2
%15 = trunc i64 %14 to i32
ret i32 %15
}