#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 */
struct flow {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ POSIX_FADV_DONTNEED;
int /*<<< orphan*/ assert(int);
scalar_t__ fdatasync(int);
int /*<<< orphan*/ posix_fadvise(int, int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/);
int flush_chunk(const struct flow *fw, int fd) {
  ((void)fw);
  if (fdatasync(fd) < 0)
    return -1;
  assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED));
  return 0;
}


x86 assembly (clang, -O0):
<flush_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <fdatasync@plt>
cmp    $0x0,%rax
jge    115d <flush_chunk+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <flush_chunk+0x5b>
mov    -0x14(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1040 <posix_fadvise@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_chunk>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %esi,%edi
call   1030 <fdatasync@plt>
test   %rax,%rax
js     1166 <flush_chunk+0x36>
mov    0x2ea8(%rip),%rax
mov    (%rax),%ecx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <posix_fadvise@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
jmp    116b <flush_chunk+0x3b>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.flow = type { i32 }
@POSIX_FADV_DONTNEED = global i32 0
define i32 @flush_chunk(%struct.flow* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.flow*
%5 = alloca i32
store %struct.flow* %0, %struct.flow** %4
store i32 %1, i32* %5
%6 = load %struct.flow*, %struct.flow** %4
%7 = load i32, i32* %5
%8 = call i64 @fdatasync(i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %19
11: ; preds = %2
%12 = load i32, i32* %5
%13 = load i32, i32* @POSIX_FADV_DONTNEED
%14 = call i32 @posix_fadvise(i32 %12, i32 0, i32 0, i32 %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
store i32 0, i32* %3
br label %19
19: ; preds = %11, %10
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.flow = type { i32 }
@POSIX_FADV_DONTNEED = global i32 0
define i32 @flush_chunk(%struct.flow* nocapture readnone %0, i32 %1) {
%3 = tail call i64 @fdatasync(i32 %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @POSIX_FADV_DONTNEED
%7 = tail call i32 @posix_fadvise(i32 %1, i32 0, i32 0, i32 %6)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
br label %11
11: ; preds = %2, %5
%12 = phi i32 [ 0, %5 ], [ -1, %2 ]
ret i32 %12
}