#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 stat64 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int _STAT_VER;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int __fxstat64(int vers, int fd, struct stat64 *buf) {
  if (vers != _STAT_VER) {
    __set_errno(EINVAL);
    return -1;
  }
  if (fd < 0) {
    __set_errno(EBADF);
    return -1;
  } else if (buf == NULL) {
    __set_errno(EINVAL);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<__fxstat64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eac(%rip),%rcx
cmp    (%rcx),%eax
je     114e <__fxstat64+0x3e>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <__fxstat64+0xa1>
cmpl   $0x0,-0xc(%rbp)
jge    1172 <__fxstat64+0x62>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <__fxstat64+0xa1>
cmpq   $0x0,-0x18(%rbp)
jne    1197 <__fxstat64+0x87>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <__fxstat64+0xa1>
jmp    119c <__fxstat64+0x8c>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__fxstat64>:
push   %rax
mov    0x2ec0(%rip),%rax
cmp    %edi,(%rax)
jne    1125 <__fxstat64+0x15>
test   %esi,%esi
js     112e <__fxstat64+0x1e>
test   %rdx,%rdx
jne    1137 <__fxstat64+0x27>
mov    0x2ea4(%rip),%rax
jmp    113e <__fxstat64+0x2e>
mov    0x2e93(%rip),%rax
jmp    113e <__fxstat64+0x2e>
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat64 = type { i32 }
@_STAT_VER = global i32 0
@EINVAL = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @__fxstat64(i32 %0, i32 %1, %struct.stat64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat64*
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.stat64* %2, %struct.stat64** %7
%8 = load i32, i32* %5
%9 = load i32, i32* @_STAT_VER
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @EINVAL
%13 = call i32 @__set_errno(i32 %12)
store i32 -1, i32* %4
br label %30
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EBADF
%19 = call i32 @__set_errno(i32 %18)
store i32 -1, i32* %4
br label %30
20: ; preds = %14
%21 = load %struct.stat64*, %struct.stat64** %7
%22 = icmp eq %struct.stat64* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EINVAL
%25 = call i32 @__set_errno(i32 %24)
store i32 -1, i32* %4
br label %30
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = load i32, i32* @ENOSYS
%29 = call i32 @__set_errno(i32 %28)
store i32 -1, i32* %4
br label %30
30: ; preds = %27, %23, %17, %11
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.stat64 = type { i32 }
@_STAT_VER = global i32 0
@EINVAL = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @__fxstat64(i32 %0, i32 %1, %struct.stat64* readnone %2) {
%4 = load i32, i32* @_STAT_VER
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = icmp slt i32 %1, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = icmp eq %struct.stat64* %2, null
%10 = select i1 %9, i32* @EINVAL, i32* @ENOSYS
br label %11
11: ; preds = %8, %6, %3
%12 = phi i32* [ @EINVAL, %3 ], [ @EBADF, %6 ], [ %10, %8 ]
%13 = load i32, i32* %12
%14 = tail call i32 @__set_errno(i32 %13)
ret i32 -1
}