#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__ EOPNOTSUPP;
scalar_t__ errno;
scalar_t__ fallocate(int, int /*<<< orphan*/, int /*<<< orphan*/, size_t);
int ftruncate(int, size_t);
int fallocate_or_ftruncate(int fd, size_t size) {
  if (fallocate(fd, 0, 0, size) == 0)
    return 0;
  if (errno != EOPNOTSUPP)
    return -1;
  if (ftruncate(fd, size) == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<fallocate_or_ftruncate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rcx
xor    %edx,%edx
mov    %edx,%esi
call   1040 <fallocate@plt>
cmp    $0x0,%rax
jne    1155 <fallocate_or_ftruncate+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <fallocate_or_ftruncate+0x83>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     117b <fallocate_or_ftruncate+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <fallocate_or_ftruncate+0x83>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    119c <fallocate_or_ftruncate+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <fallocate_or_ftruncate+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fallocate_or_ftruncate>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <fallocate@plt>
test   %rax,%rax
je     116c <fallocate_or_ftruncate+0x4c>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
mov    0x2e93(%rip),%rcx
mov    $0xffffffff,%ebp
cmp    (%rcx),%rax
jne    116c <fallocate_or_ftruncate+0x4c>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <ftruncate@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
neg    %ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EOPNOTSUPP = global i64 0
define i32 @fallocate_or_ftruncate(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
%6 = load i32, i32* %4
%7 = load i64, i64* %5
%8 = call i64 @fallocate(i32 %6, i32 0, i32 0, i64 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %23
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EOPNOTSUPP
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %3
br label %23
16: ; preds = %11
%17 = load i32, i32* %4
%18 = load i64, i64* %5
%19 = call i32 @ftruncate(i32 %17, i64 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %3
br label %23
22: ; preds = %16
store i32 0, i32* %3
br label %23
23: ; preds = %22, %21, %15, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
@EOPNOTSUPP = global i64 0
define i32 @fallocate_or_ftruncate(i32 %0, i64 %1) {
%3 = tail call i64 @fallocate(i32 %0, i32 0, i32 0, i64 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EOPNOTSUPP
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32 @ftruncate(i32 %0, i64 %1)
%11 = icmp eq i32 %10, -1
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %9, %5, %2
%14 = phi i32 [ 0, %2 ], [ -1, %5 ], [ %12, %9 ]
ret i32 %14
}