#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*/ BLKFLSBUF;
int /*<<< orphan*/ do_drive_cmd(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ fdatasync(int);
int /*<<< orphan*/ fsync(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sync();
void flush_buffer_cache(int fd) {
  sync();
  fsync(fd);
  fdatasync(fd);
  sync();
  if (ioctl(fd, BLKFLSBUF, NULL))
    perror("BLKFLSBUF failed");
  else
    do_drive_cmd(fd, NULL, 0);
  sync();
}


x86 assembly (clang, -O0):
<flush_buffer_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1060 <sync@plt>
mov    -0x4(%rbp),%edi
call   1070 <fsync@plt>
mov    -0x4(%rbp),%edi
call   1030 <fdatasync@plt>
mov    $0x0,%al
call   1060 <sync@plt>
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11b9 <flush_buffer_cache+0x59>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
jmp    11c7 <flush_buffer_cache+0x67>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <do_drive_cmd@plt>
mov    $0x0,%al
call   1060 <sync@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_buffer_cache>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <sync@plt>
mov    %ebx,%edi
call   1070 <fsync@plt>
mov    %ebx,%edi
call   1030 <fdatasync@plt>
xor    %eax,%eax
call   1060 <sync@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
jne    11a9 <flush_buffer_cache+0x49>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <do_drive_cmd@plt>
xor    %eax,%eax
pop    %rbx
jmp    1060 <sync@plt>
lea    0xe50(%rip),%rdi
call   1080 <perror@plt>
jmp    11a1 <flush_buffer_cache+0x41>

LLVM IR (-O0):
@BLKFLSBUF = global i32 0
@.str = [17 x i8] c"BLKFLSBUF failed\00"
define void @flush_buffer_cache(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (...) @sync()
%4 = load i32, i32* %2
%5 = call i32 @fsync(i32 %4)
%6 = load i32, i32* %2
%7 = call i32 @fdatasync(i32 %6)
%8 = call i32 (...) @sync()
%9 = load i32, i32* %2
%10 = load i32, i32* @BLKFLSBUF
%11 = call i64 @ioctl(i32 %9, i32 %10, i32* null)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %18
15: ; preds = %1
%16 = load i32, i32* %2
%17 = call i32 @do_drive_cmd(i32 %16, i32* null, i32 0)
br label %18
18: ; preds = %15, %13
%19 = call i32 (...) @sync()
ret void
}

LLVM IR (-O2):
@BLKFLSBUF = global i32 0
@.str = [17 x i8] c"BLKFLSBUF failed\00"
define void @flush_buffer_cache(i32 %0) {
%2 = tail call i32 (...) @sync()
%3 = tail call i32 @fsync(i32 %0)
%4 = tail call i32 @fdatasync(i32 %0)
%5 = tail call i32 (...) @sync()
%6 = load i32, i32* @BLKFLSBUF
%7 = tail call i64 @ioctl(i32 %0, i32 %6, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %1
%12 = tail call i32 @do_drive_cmd(i32 %0, i32* null, i32 0)
br label %13
13: ; preds = %11, %9
%14 = tail call i32 (...) @sync()
ret void
}