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

/* Variables and functions */
scalar_t__ ENOSYS;
scalar_t__ __dietlibc_fstat64(int, struct stat64 *);
int /*<<< orphan*/ __stat64_cvt(struct stat *, struct stat64 *);
scalar_t__ errno;
scalar_t__ fstat(int, struct stat *);
int fstat64(int __fd, struct stat64 *__buf) {
  if (__dietlibc_fstat64(__fd, __buf)) {
    struct stat temp;
    if (errno != ENOSYS)
      return -1;
    if (fstat(__fd, &temp))
      return -1;
    __stat64_cvt(&temp, __buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<fstat64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <__dietlibc_fstat64@plt>
cmp    $0x0,%rax
je     11aa <fstat64+0x7a>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
je     117b <fstat64+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <fstat64+0x81>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
je     119d <fstat64+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <fstat64+0x81>
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1030 <__stat64_cvt@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fstat64>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
call   1040 <__dietlibc_fstat64@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1184 <fstat64+0x54>
mov    0x2e88(%rip),%rax
mov    (%rax),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
jne    1170 <fstat64+0x40>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1050 <fstat@plt>
test   %rax,%rax
je     1177 <fstat64+0x47>
mov    $0xffffffff,%ebx
jmp    1184 <fstat64+0x54>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <__stat64_cvt@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat64 = type { i32 }
%struct.stat = type { i32 }
@errno = global i64 0
@ENOSYS = global i64 0
define i32 @fstat64(i32 %0, %struct.stat64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat64*
%6 = alloca %struct.stat
store i32 %0, i32* %4
store %struct.stat64* %1, %struct.stat64** %5
%7 = load i32, i32* %4
%8 = load %struct.stat64*, %struct.stat64** %5
%9 = call i64 @__dietlibc_fstat64(i32 %7, %struct.stat64* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOSYS
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %3
br label %25
16: ; preds = %11
%17 = load i32, i32* %4
%18 = call i64 @fstat(i32 %17, %struct.stat* %6)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %3
br label %25
21: ; preds = %16
%22 = load %struct.stat64*, %struct.stat64** %5
%23 = call i32 @__stat64_cvt(%struct.stat* %6, %struct.stat64* %22)
br label %24
24: ; preds = %21, %2
store i32 0, i32* %3
br label %25
25: ; preds = %24, %20, %15
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.stat64 = type { i32 }
%struct.stat = type { i32 }
@errno = global i64 0
@ENOSYS = global i64 0
define i32 @fstat64(i32 %0, %struct.stat64* %1) {
%3 = alloca %struct.stat
%4 = tail call i64 @__dietlibc_fstat64(i32 %0, %struct.stat64* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = bitcast %struct.stat* %3 to i8*
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOSYS
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call i64 @fstat(i32 %0, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %6, %11
br label %17
15: ; preds = %11
%16 = call i32 @__stat64_cvt(%struct.stat* %3, %struct.stat64* %1)
br label %17
17: ; preds = %2, %15, %14
%18 = phi i32 [ -1, %14 ], [ 0, %15 ], [ 0, %2 ]
ret i32 %18
}