#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__ EINVAL;
scalar_t__ errno;
int fdatasync(int);
int fsync(int);
int /*<<< orphan*/ perror(char *);
int fsync_all(int fd) {
  if (fsync(fd) == -1) {
    if (errno == EINVAL) {
      if (fdatasync(fd) == -1) {
        perror("fdatasync");
        return -1;
      }
    }
    perror("fsync");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fsync_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <fsync@plt>
cmp    $0xffffffff,%eax
jne    11ac <fsync_all+0x7c>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <fsync_all+0x64>
mov    -0x8(%rbp),%edi
call   1030 <fdatasync@plt>
cmp    $0xffffffff,%eax
jne    118f <fsync_all+0x5f>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <fsync_all+0x83>
jmp    1194 <fsync_all+0x64>
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <fsync_all+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsync_all>:
push   %rbx
mov    %edi,%ebx
call   1040 <fsync@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1143 <fsync_all+0x13>
pop    %rbx
ret
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
jne    116e <fsync_all+0x3e>
mov    %ebx,%edi
call   1030 <fdatasync@plt>
cmp    $0xffffffff,%eax
jne    116e <fsync_all+0x3e>
lea    0xe94(%rip),%rdi
jmp    1175 <fsync_all+0x45>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@.str = [10 x i8] c"fdatasync\00"
@.str.1 = [6 x i8] c"fsync\00"
define i32 @fsync_all(i32 %0) {
%2 = tail call i32 @fsync(i32 %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINVAL
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 @fdatasync(i32 %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %12, label %11
11: ; preds = %8, %4
br label %12
12: ; preds = %8, %11
%13 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %8 ]
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ 0, %1 ], [ -1, %12 ]
ret i32 %16
}