#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 */
scalar_t__ alloc_pagecache(int, size_t);
long cg_read_key_long(char const *, char *, char *);
long cg_read_long(char const *, char *);
int /*<<< orphan*/ close(int);
int get_temp_fd();
int /*<<< orphan*/ values_close(long, long, int);
int alloc_pagecache_50M_check(const char *cgroup, void *arg) {
  size_t size = (50 << 20);
  int ret = -1;
  long current, file;
  int fd;
  fd = get_temp_fd();
  if (fd < 0)
    return -1;
  if (alloc_pagecache(fd, size))
    goto cleanup;
  current = cg_read_long(cgroup, "memory.current");
  if (current < size)
    goto cleanup;
  file = cg_read_key_long(cgroup, "memory.stat", "file ");
  if (file < 0)
    goto cleanup;
  if (!values_close(file, current, 10))
    goto cleanup;
  ret = 0;
cleanup:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<alloc_pagecache_50M_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x3200000,-0x20(%rbp)
03
movl   $0xffffffff,-0x24(%rbp)
mov    $0x0,%al
call   1050 <get_temp_fd@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    119f <alloc_pagecache_50M_check+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <alloc_pagecache_50M_check+0xe1>
mov    -0x3c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <alloc_pagecache@plt>
cmp    $0x0,%rax
je     11ba <alloc_pagecache_50M_check+0x5a>
jmp    1233 <alloc_pagecache_50M_check+0xd3>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1030 <cg_read_long@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e1 <alloc_pagecache_50M_check+0x81>
jmp    1233 <alloc_pagecache_50M_check+0xd3>
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
lea    0xe28(%rip),%rdx
call   1060 <cg_read_key_long@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    120c <alloc_pagecache_50M_check+0xac>
jmp    1233 <alloc_pagecache_50M_check+0xd3>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1070 <values_close@plt>
cmp    $0x0,%eax
jne    122c <alloc_pagecache_50M_check+0xcc>
jmp    1233 <alloc_pagecache_50M_check+0xd3>
movl   $0x0,-0x24(%rbp)
mov    -0x3c(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_pagecache_50M_check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <get_temp_fd@plt>
test   %eax,%eax
js     11e0 <alloc_pagecache_50M_check+0x80>
mov    %eax,%ebx
mov    $0x3200000,%esi
mov    %eax,%edi
call   1080 <alloc_pagecache@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11d7 <alloc_pagecache_50M_check+0x77>
lea    0xe6c(%rip),%rsi
mov    %r14,%rdi
call   1030 <cg_read_long@plt>
cmp    $0x3200000,%rax
jb     11d7 <alloc_pagecache_50M_check+0x77>
mov    %rax,%r15
lea    0xe61(%rip),%rsi
lea    0xe66(%rip),%rdx
mov    %r14,%rdi
call   1060 <cg_read_key_long@plt>
test   %rax,%rax
js     11d7 <alloc_pagecache_50M_check+0x77>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1070 <values_close@plt>
cmp    $0x1,%eax
sbb    %ebp,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11e5 <alloc_pagecache_50M_check+0x85>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"memory.current\00"
@.str.1 = [12 x i8] c"memory.stat\00"
@.str.2 = [6 x i8] c"file \00"
define i32 @alloc_pagecache_50M_check(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 52428800, i64* %6
store i32 -1, i32* %7
%11 = call i32 (...) @get_temp_fd()
store i32 %11, i32* %10
%12 = load i32, i32* %10
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %45
15: ; preds = %2
%16 = load i32, i32* %10
%17 = load i64, i64* %6
%18 = call i64 @alloc_pagecache(i32 %16, i64 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %41
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = call i64 @cg_read_long(i8* %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = load i64, i64* %6
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %21
br label %41
28: ; preds = %21
%29 = load i8*, i8** %4
%30 = call i64 @cg_read_key_long(i8* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i64 %30, i64* %9
%31 = load i64, i64* %9
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
br label %41
34: ; preds = %28
%35 = load i64, i64* %9
%36 = load i64, i64* %8
%37 = call i32 @values_close(i64 %35, i64 %36, i32 10)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34
br label %41
40: ; preds = %34
store i32 0, i32* %7
br label %41
41: ; preds = %40, %39, %33, %27, %20
%42 = load i32, i32* %10
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %7
store i32 %44, i32* %3
br label %45
45: ; preds = %41, %14
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [15 x i8] c"memory.current\00"
@.str.1 = [12 x i8] c"memory.stat\00"
@.str.2 = [6 x i8] c"file \00"
define i32 @alloc_pagecache_50M_check(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i32 (...) @get_temp_fd()
%4 = icmp slt i32 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = tail call i64 @alloc_pagecache(i32 %3, i64 52428800)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = tail call i64 @cg_read_long(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = icmp ult i64 %9, 52428800
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = tail call i64 @cg_read_key_long(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp slt i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call i32 @values_close(i64 %12, i64 %9, i32 10)
%16 = icmp eq i32 %15, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %11, %8, %5
%19 = phi i32 [ -1, %5 ], [ -1, %8 ], [ -1, %11 ], [ %17, %14 ]
%20 = tail call i32 @close(i32 %3)
br label %21
21: ; preds = %2, %18
%22 = phi i32 [ %19, %18 ], [ -1, %2 ]
ret i32 %22
}