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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ fstat(int, struct stat *);
scalar_t__ ftruncate(int, int);
int mkstemp(char *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char file[] = "/tmp/dietlibc-fadvise-test.XXXXXX";
  int fd;
  struct stat st;
  fd = mkstemp(file);
  unlink(file);
  assert(ftruncate(fd, 500000) == 0);
  assert(fstat(fd, &st) == 0);
  if (st.st_blocks > 1) {
    return EXIT_SUCCESS;
  }
  assert(ftruncate(fd, (1)) == 0);
  assert(fstat(fd, &st) == 0);
  assert(st.st_size == (1));
  ;
  assert(ftruncate(fd, (0x7fffffff)) == 0);
  assert(fstat(fd, &st) == 0);
  assert(st.st_size == (0x7fffffff));
  ;
  assert(ftruncate(fd, (0x17fffffffull)) == 0);
  assert(fstat(fd, &st) == 0);
  assert(st.st_size == (0x17fffffffull));
  ;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x22,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rdi
call   1070 <mkstemp@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x34(%rbp),%edi
mov    $0x7a120,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x1,-0x40(%rbp)
jle    11ef <main+0x8f>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ef <main+0x18f>
mov    -0x34(%rbp),%edi
mov    $0x1,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x1,-0x3c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
mov    $0x7fffffff,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x7fffffff,-0x3c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
mov    $0x7fffffff,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movslq -0x3c(%rbp),%rax
movabs $0x17fffffff,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x58,0x30(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    $0x7a120,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1070 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
cmpl   $0x1,0x8(%rsp)
jg     1292 <main+0x142>
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0xc(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
mov    $0x7fffffff,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x7fffffff,0xc(%rsp)
7f
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
mov    $0x7fffffff,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@__const.main.file = [34 x i8] c"/tmp/dietlibc-fadvise-test.XXXXXX\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [34 x i8]
%3 = alloca i32
%4 = alloca %struct.stat
store i32 0, i32* %1
%5 = bitcast [34 x i8]* %2 to i8*
%6 = getelementptr inbounds [34 x i8], [34 x i8]* %2, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %6)
store i32 %7, i32* %3
%8 = getelementptr inbounds [34 x i8], [34 x i8]* %2, i64 0, i64 0
%9 = call i32 @unlink(i8* %8)
%10 = load i32, i32* %3
%11 = call i64 @ftruncate(i32 %10, i32 500000)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %3
%16 = call i64 @fstat(i32 %15, %struct.stat* %4)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %1
br label %73
25: ; preds = %0
%26 = load i32, i32* %3
%27 = call i64 @ftruncate(i32 %26, i32 1)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %3
%32 = call i64 @fstat(i32 %31, %struct.stat* %4)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 1
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32, i32* %3
%42 = call i64 @ftruncate(i32 %41, i32 2147483647)
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %3
%47 = call i64 @fstat(i32 %46, %struct.stat* %4)
%48 = icmp eq i64 %47, 0
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%52 = load i32, i32* %51
%53 = icmp eq i32 %52, 2147483647
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i32, i32* %3
%57 = call i64 @ftruncate(i32 %56, i32 2147483647)
%58 = icmp eq i64 %57, 0
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i32, i32* %3
%62 = call i64 @fstat(i32 %61, %struct.stat* %4)
%63 = icmp eq i64 %62, 0
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%67 = load i32, i32* %66
%68 = sext i32 %67 to i64
%69 = icmp eq i64 %68, 6442450943
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i32, i32* @EXIT_SUCCESS
store i32 %72, i32* %1
br label %73
73: ; preds = %25, %23
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@__const.main.file = [34 x i8] c"/tmp/dietlibc-fadvise-test.XXXXXX\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [34 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = call i32 @mkstemp(i8* %3)
%6 = call i32 @unlink(i8* %3)
%7 = call i64 @ftruncate(i32 %5, i32 500000)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i64 @fstat(i32 %5, %struct.stat* %2)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, 1
br i1 %17, label %53, label %18
18: ; preds = %0
%19 = call i64 @ftruncate(i32 %5, i32 1)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i64 @fstat(i32 %5, %struct.stat* %2)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 1
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i64 @ftruncate(i32 %5, i32 2147483647)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i64 @fstat(i32 %5, %struct.stat* %2)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32, i32* %27
%41 = icmp eq i32 %40, 2147483647
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i64 @ftruncate(i32 %5, i32 2147483647)
%45 = icmp eq i64 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i64 @fstat(i32 %5, %struct.stat* %2)
%49 = icmp eq i64 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i32 @assert(i32 0)
br label %53
53: ; preds = %0, %18
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}