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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ POSIX_FADV_DONTNEED;
int errno;
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/, int);
int posix_fadvise(int, int, int, int /*<<< orphan*/);
int posix_fallocate(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int main() {
  struct stat s;
  int f = open("/test", O_RDONLY, 0777);
  printf("posix_fadvise: %d\n", posix_fadvise(f, 3, 2, POSIX_FADV_DONTNEED));
  printf("errno: %d\n", errno);
  printf("\n");
  errno = 0;
  printf("posix_fallocate: %d\n", posix_fallocate(f, 3, 2));
  printf("errno: %d\n", errno);
  stat("/test", &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  printf("\n");
  errno = 0;
  printf("posix_fallocate2: %d\n", posix_fallocate(f, 3, 7));
  printf("errno: %d\n", errno);
  stat("/test", &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
mov    $0x3,%esi
mov    $0x2,%edx
call   1050 <posix_fadvise@plt>
mov    %eax,%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ded(%rip),%rax
movl   $0x0,(%rax)
mov    -0xc(%rbp),%edi
mov    $0x3,%esi
mov    $0x2,%edx
call   1070 <posix_fallocate@plt>
mov    %eax,%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x8(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d68(%rip),%rax
movl   $0x0,(%rax)
mov    -0xc(%rbp),%edi
mov    $0x3,%esi
mov    $0x7,%edx
call   1070 <posix_fallocate@plt>
mov    %eax,%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd52(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x8(%rbp),%esi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%r14
mov    %r14,%rdi
mov    $0x1ff,%edx
call   1090 <open@plt>
mov    %eax,%ebp
mov    0x2e4f(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
mov    $0x3,%esi
mov    $0x2,%edx
call   1060 <posix_fadvise@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e05(%rip),%r13
mov    0x0(%r13),%esi
lea    0xe43(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,0x0(%r13)
mov    %ebp,%edi
mov    $0x3,%esi
mov    $0x2,%edx
call   1080 <posix_fallocate@plt>
lea    0xe1a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stat@plt>
mov    (%rsp),%esi
lea    0xe00(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,0x0(%r13)
mov    %ebp,%edi
mov    $0x3,%esi
mov    $0x7,%edx
call   1080 <posix_fallocate@plt>
lea    0xdca(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"/test\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"posix_fadvise: %d\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [21 x i8] c"posix_fallocate: %d\0A\00"
@.str.5 = [13 x i8] c"st_size: %d\0A\00"
@.str.6 = [22 x i8] c"posix_fallocate2: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4, i32 511)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* @POSIX_FADV_DONTNEED
%8 = call i32 @posix_fadvise(i32 %6, i32 3, i32 2, i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @errno
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* @errno
%13 = load i32, i32* %3
%14 = call i32 @posix_fallocate(i32 %13, i32 3, i32 2)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @errno
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* @errno
%24 = load i32, i32* %3
%25 = call i32 @posix_fallocate(i32 %24, i32 3, i32 7)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @errno
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"/test\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"posix_fadvise: %d\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.4 = [21 x i8] c"posix_fallocate: %d\0A\00"
@.str.5 = [13 x i8] c"st_size: %d\0A\00"
@.str.6 = [22 x i8] c"posix_fallocate2: %d\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3, i32 511)
%5 = load i32, i32* @POSIX_FADV_DONTNEED
%6 = tail call i32 @posix_fadvise(i32 %4, i32 3, i32 2, i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @errno
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32 @putchar(i32 10)
store i32 0, i32* @errno
%11 = tail call i32 @posix_fallocate(i32 %4, i32 3, i32 2)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @errno
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
%20 = call i32 @putchar(i32 10)
store i32 0, i32* @errno
%21 = call i32 @posix_fallocate(i32 %4, i32 3, i32 7)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @errno
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%26 = load i32, i32* %16
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
ret i32 0
}