#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*/ _IO(int, int);
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, _IO(0x12, 97), NULL))
    perror("BLKFLSBUF failed");
  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),%eax
mov    %eax,-0x8(%rbp)
mov    $0x12,%edi
mov    $0x61,%esi
call   1040 <_IO@plt>
mov    -0x8(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11c2 <flush_buffer_cache+0x62>
lea    0xe43(%rip),%rdi
call   1080 <perror@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    $0x12,%edi
mov    $0x61,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
jne    11a6 <flush_buffer_cache+0x46>
xor    %eax,%eax
pop    %rbx
jmp    1060 <sync@plt>
lea    0xe53(%rip),%rdi
call   1080 <perror@plt>
jmp    119e <flush_buffer_cache+0x3e>

LLVM IR (-O0):
@.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 = call i32 @_IO(i32 18, i32 97)
%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 %15
15: ; preds = %13, %1
%16 = call i32 (...) @sync()
ret void
}

LLVM IR (-O2):
@.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 = tail call i32 @_IO(i32 18, i32 97)
%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 %11
11: ; preds = %9, %1
%12 = tail call i32 (...) @sync()
ret void
}