#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_long(char const *, char *);
int /*<<< orphan*/ close(int);
int get_temp_fd();
int alloc_pagecache_max_30M(const char *cgroup, void *arg) {
  size_t size = (50 << 20);
  int ret = -1;
  long current;
  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 <= (29 << 20) || current > (30 << 20))
    goto cleanup;
  ret = 0;
cleanup:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<alloc_pagecache_max_30M>:
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,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    117f <alloc_pagecache_max_30M+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <alloc_pagecache_max_30M+0xa4>
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <alloc_pagecache@plt>
cmp    $0x0,%rax
je     119a <alloc_pagecache_max_30M+0x5a>
jmp    11d6 <alloc_pagecache_max_30M+0x96>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <cg_read_long@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1d00000,-0x30(%rbp)
01
jle    11ca <alloc_pagecache_max_30M+0x8a>
cmpq   $0x1e00000,-0x30(%rbp)
01
jle    11cf <alloc_pagecache_max_30M+0x8f>
jmp    11d6 <alloc_pagecache_max_30M+0x96>
movl   $0x0,-0x24(%rbp)
mov    -0x34(%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_max_30M>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <get_temp_fd@plt>
test   %eax,%eax
js     1190 <alloc_pagecache_max_30M+0x50>
mov    %eax,%ebx
mov    $0x3200000,%esi
mov    %eax,%edi
call   1060 <alloc_pagecache@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1187 <alloc_pagecache_max_30M+0x47>
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
call   1030 <cg_read_long@plt>
add    $0xfffffffffe1fffff,%rax
cmp    $0xfffffffffff00000,%rax
sbb    %ebp,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1195 <alloc_pagecache_max_30M+0x55>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"memory.current\00"
define i32 @alloc_pagecache_max_30M(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 52428800, i64* %6
store i32 -1, i32* %7
%10 = call i32 (...) @get_temp_fd()
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %34
14: ; preds = %2
%15 = load i32, i32* %9
%16 = load i64, i64* %6
%17 = call i64 @alloc_pagecache(i32 %15, i64 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %30
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i64 @cg_read_long(i8* %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = icmp sle i64 %23, 30408704
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i64, i64* %8
%27 = icmp sgt i64 %26, 31457280
br i1 %27, label %28, label %29
28: ; preds = %25, %20
br label %30
29: ; preds = %25
store i32 0, i32* %7
br label %30
30: ; preds = %29, %28, %19
%31 = load i32, i32* %9
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %34
34: ; preds = %30, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [15 x i8] c"memory.current\00"
define i32 @alloc_pagecache_max_30M(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i32 (...) @get_temp_fd()
%4 = icmp slt i32 %3, 0
br i1 %4, label %16, 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 %13
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 = add i64 %9, -31457281
%11 = icmp ult i64 %10, -1048576
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %8, %5
%14 = phi i32 [ -1, %5 ], [ %12, %8 ]
%15 = tail call i32 @close(i32 %3)
br label %16
16: ; preds = %2, %13
%17 = phi i32 [ %14, %13 ], [ -1, %2 ]
ret i32 %17
}