#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 */
scalar_t__ HDIO_GET_WCACHE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, unsigned long);
scalar_t__ ioctl(int, int, unsigned long *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int getWriteCacheStatus(int fd) {
  unsigned long val = 0;
  if (ioctl(fd, (int)(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),%rax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jl     1186 <getWriteCacheStatus+0x56>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1192 <getWriteCacheStatus+0x62>
lea    0xe9d(%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 i64 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 i64, i64* @HDIO_GET_WCACHE
%6 = trunc i64 %5 to i32
%7 = call i64 @ioctl(i32 %4, i32 %6, i64* %3)
%8 = icmp sge i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* %2
%12 = load i64, i64* %3
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %11, i64 %12)
br label %16
14: ; preds = %1
%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, %9
%17 = load i64, i64* %3
%18 = trunc i64 %17 to i32
ret i32 %18
}

LLVM IR (-O2):
@HDIO_GET_WCACHE = global i64 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 i64, i64* @HDIO_GET_WCACHE
%5 = trunc i64 %4 to i32
%6 = call i64 @ioctl(i32 %0, i32 %5, i64* %2)
%7 = icmp sgt i64 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i64, i64* %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %10)
br label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
ret i32 %16
}