#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ warn(char *, char *);
int page_cache_hog(void) {
  int fd = -1;
  char buff[100];
  char path[100];
  int ret = 0;
  sprintf(path, "%s", "DATAFILE");
  fd = open(path, O_RDONLY);
  if (fd == -1) {
    warn("open %s failed", path);
    return -1;
  }
  while ((ret = read(fd, buff, sizeof(buff))) > 0)
    ;
  if (ret == -1)
    warn("read %s failed", path);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<page_cache_hog>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0xffffffff,-0x8(%rbp)
movl   $0x0,-0xe4(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    0xe82(%rip),%rdx
call   1070 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c7 <page_cache_hog+0x77>
lea    -0xe0(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <page_cache_hog+0xd2>
jmp    11cc <page_cache_hog+0x7c>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0xe4(%rbp)
cmp    $0x0,%eax
jle    11f1 <page_cache_hog+0xa1>
jmp    11cc <page_cache_hog+0x7c>
cmpl   $0xffffffff,-0xe4(%rbp)
jne    1211 <page_cache_hog+0xc1>
lea    -0xe0(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1030 <warn@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xe4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_cache_hog>:
push   %rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
movabs $0x454c494641544144,%rax
49 4c 45
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b2 <page_cache_hog+0x72>
mov    %eax,%ebx
lea    0x70(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     1180 <page_cache_hog+0x40>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a9 <page_cache_hog+0x69>
lea    0xe77(%rip),%rdi
mov    %rsp,%rsi
call   1030 <warn@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11c6 <page_cache_hog+0x86>
lea    0xe50(%rip),%rdi
mov    %rsp,%rsi
call   1030 <warn@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [9 x i8] c"DATAFILE\00"
@O_RDONLY = global i32 0
@.str.2 = [15 x i8] c"open %s failed\00"
@.str.3 = [15 x i8] c"read %s failed\00"
define i32 @page_cache_hog() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i32
store i32 -1, i32* %2
store i32 0, i32* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32 -1, i32* %1
br label %33
16: ; preds = %0
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %2
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 100)
store i32 %20, i32* %5
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %17
23: ; preds = %17
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%28 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %2
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %5
store i32 %32, i32* %1
br label %33
33: ; preds = %29, %13
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"DATAFILE\00"
@O_RDONLY = global i32 0
@.str.2 = [15 x i8] c"open %s failed\00"
@.str.3 = [15 x i8] c"read %s failed\00"
define i32 @page_cache_hog() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %19
10: ; preds = %0, %10
%11 = call i32 @read(i32 %6, i8* %3, i32 100)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = icmp eq i32 %11, -1
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %17
17: ; preds = %15, %13
%18 = call i32 @close(i32 %6)
br label %19
19: ; preds = %17, %8
%20 = phi i32 [ -1, %8 ], [ %11, %17 ]
ret i32 %20
}