#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 */
int /*<<< orphan*/ abort();
int fallocate(int, int /*<<< orphan*/, int /*<<< orphan*/, int);
int ftruncate(int, int);
int /*<<< orphan*/ printf(char *);
void mfd_fail_grow(int fd) {
  int r;
  r = ftruncate(fd, 8192 * 2);
  if (r >= 0) {
    printf("ftruncate(GROW) didn't fail as expected\n");
    abort();
  }
  r = fallocate(fd, 0, 0, 8192 * 4);
  if (r >= 0) {
    printf("fallocate(ALLOC) didn't fail as expected\n");
    abort();
  }
}


x86 assembly (clang, -O0):
<mfd_fail_grow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4000,%esi
call   1050 <ftruncate@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1178 <mfd_fail_grow+0x38>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    $0x8000,%ecx
mov    %edx,%esi
call   1060 <fallocate@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11a9 <mfd_fail_grow+0x69>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_fail_grow>:
push   %rbx
mov    %edi,%ebx
mov    $0x4000,%esi
call   1050 <ftruncate@plt>
test   %eax,%eax
jns    1167 <mfd_fail_grow+0x27>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x8000,%ecx
call   1060 <fallocate@plt>
test   %eax,%eax
jns    1170 <mfd_fail_grow+0x30>
pop    %rbx
ret
lea    0xebb(%rip),%rdi
jmp    1177 <mfd_fail_grow+0x37>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"ftruncate(GROW) didn't fail as expected\0A\00"
@.str.1 = [42 x i8] c"fallocate(ALLOC) didn't fail as expected\0A\00"
define void @mfd_fail_grow(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @ftruncate(i32 %4, i32 16384)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 @fallocate(i32 %12, i32 0, i32 0, i32 32768)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %11
ret void
}

LLVM IR (-O2):
@str = [41 x i8] c"fallocate(ALLOC) didn't fail as expected\00"
@str.2 = [40 x i8] c"ftruncate(GROW) didn't fail as expected\00"
define void @mfd_fail_grow(i32 %0) {
%2 = tail call i32 @ftruncate(i32 %0, i32 16384)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.2, i64 0, i64 0))
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %1
%8 = tail call i32 @fallocate(i32 %0, i32 0, i32 0, i32 32768)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %7
ret void
}