#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*/ mfd_assert_size(int, int);
int /*<<< orphan*/ printf(char *);
void mfd_assert_grow(int fd) {
  int r;
  r = ftruncate(fd, 8192 * 2);
  if (r < 0) {
    printf("ftruncate(GROW) failed: %m\n");
    abort();
  }
  mfd_assert_size(fd, 8192 * 2);
  r = fallocate(fd, 0, 0, 8192 * 4);
  if (r < 0) {
    printf("fallocate(ALLOC) failed: %m\n");
    abort();
  }
  mfd_assert_size(fd, 8192 * 4);
}


x86 assembly (clang, -O0):
<mfd_assert_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)
jge    1188 <mfd_assert_grow+0x38>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
mov    $0x4000,%esi
call   1070 <mfd_assert_size@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)
jge    11c6 <mfd_assert_grow+0x76>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
mov    $0x8000,%esi
call   1070 <mfd_assert_size@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_assert_grow>:
push   %rbx
mov    %edi,%ebx
mov    $0x4000,%esi
call   1050 <ftruncate@plt>
test   %eax,%eax
js     118e <mfd_assert_grow+0x3e>
mov    %ebx,%edi
mov    $0x4000,%esi
call   1070 <mfd_assert_size@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x8000,%ecx
call   1060 <fallocate@plt>
test   %eax,%eax
js     1197 <mfd_assert_grow+0x47>
mov    %ebx,%edi
mov    $0x8000,%esi
pop    %rbx
jmp    1070 <mfd_assert_size@plt>
lea    0xe6b(%rip),%rdi
jmp    119e <mfd_assert_grow+0x4e>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"ftruncate(GROW) failed: %m\0A\00"
@.str.1 = [29 x i8] c"fallocate(ALLOC) failed: %m\0A\00"
define void @mfd_assert_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 slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 @mfd_assert_size(i32 %12, i32 16384)
%14 = load i32, i32* %2
%15 = call i32 @fallocate(i32 %14, i32 0, i32 0, i32 32768)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %11
%22 = load i32, i32* %2
%23 = call i32 @mfd_assert_size(i32 %22, i32 32768)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"ftruncate(GROW) failed: %m\0A\00"
@.str.1 = [29 x i8] c"fallocate(ALLOC) failed: %m\0A\00"
define void @mfd_assert_grow(i32 %0) {
%2 = tail call i32 @ftruncate(i32 %0, i32 16384)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %1
%8 = tail call i32 @mfd_assert_size(i32 %0, i32 16384)
%9 = tail call i32 @fallocate(i32 %0, i32 0, i32 0, i32 32768)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %7
%15 = tail call i32 @mfd_assert_size(i32 %0, i32 32768)
ret void
}