#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 */
long cg_read_key_long(char const *, char *, char *);
long cg_read_long(char const *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ values_close(long, long, int);
int alloc_anon_50M_check(const char *cgroup, void *arg) {
  size_t size = (50 << 20);
  char *buf, *ptr;
  long anon, current;
  int ret = -1;
  buf = malloc(size);
  for (ptr = buf; ptr < buf + size; ptr += 4096)
    *ptr = 0;
  current = cg_read_long(cgroup, "memory.current");
  if (current < size)
    goto cleanup;
  if (!values_close(size, current, 3))
    goto cleanup;
  anon = cg_read_key_long(cgroup, "memory.stat", "anon ");
  if (anon < 0)
    goto cleanup;
  if (!values_close(anon, current, 3))
    goto cleanup;
  ret = 0;
cleanup:
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<alloc_anon_50M_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x3200000,-0x18(%rbp)
03
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    11b3 <alloc_anon_50M_check+0x63>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x28(%rbp)
jmp    1184 <alloc_anon_50M_check+0x34>
mov    -0x8(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1040 <cg_read_long@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11da <alloc_anon_50M_check+0x8a>
jmp    124c <alloc_anon_50M_check+0xfc>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3,%edx
call   1070 <values_close@plt>
cmp    $0x0,%eax
jne    11fa <alloc_anon_50M_check+0xaa>
jmp    124c <alloc_anon_50M_check+0xfc>
mov    -0x8(%rbp),%rdi
lea    0xe0a(%rip),%rsi
lea    0xe0f(%rip),%rdx
call   1060 <cg_read_key_long@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1225 <alloc_anon_50M_check+0xd5>
jmp    124c <alloc_anon_50M_check+0xfc>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3,%edx
call   1070 <values_close@plt>
cmp    $0x0,%eax
jne    1245 <alloc_anon_50M_check+0xf5>
jmp    124c <alloc_anon_50M_check+0xfc>
movl   $0x0,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_anon_50M_check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3200000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0xfffffffffffff000,%rax
xchg   %ax,%ax
movb   $0x0,0x1000(%rbx,%rax,1)
movb   $0x0,0x2000(%rbx,%rax,1)
movb   $0x0,0x3000(%rbx,%rax,1)
movb   $0x0,0x4000(%rbx,%rax,1)
movb   $0x0,0x5000(%rbx,%rax,1)
movb   $0x0,0x6000(%rbx,%rax,1)
movb   $0x0,0x7000(%rbx,%rax,1)
movb   $0x0,0x8000(%rbx,%rax,1)
add    $0x8000,%rax
cmp    $0x31ff000,%rax
jb     1170 <alloc_anon_50M_check+0x20>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1040 <cg_read_long@plt>
mov    $0xffffffff,%r15d
cmp    $0x3200000,%rax
jb     1225 <alloc_anon_50M_check+0xd5>
mov    %rax,%rbp
mov    $0x3200000,%edi
mov    %rax,%rsi
mov    $0x3,%edx
call   1070 <values_close@plt>
test   %eax,%eax
je     1225 <alloc_anon_50M_check+0xd5>
lea    0xe14(%rip),%rsi
lea    0xe19(%rip),%rdx
mov    %r14,%rdi
call   1060 <cg_read_key_long@plt>
test   %rax,%rax
js     1225 <alloc_anon_50M_check+0xd5>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1070 <values_close@plt>
cmp    $0x1,%eax
sbb    %r15d,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%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"anon \00"
define i32 @alloc_anon_50M_check(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 52428800, i64* %5
store i32 -1, i32* %10
%11 = load i64, i64* %5
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
br label %14
14: ; preds = %22, %2
%15 = load i8*, i8** %7
%16 = load i8*, i8** %6
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = icmp ult i8* %15, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8*, i8** %7
store i8 0, i8* %21
br label %22
22: ; preds = %20
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 4096
store i8* %24, i8** %7
br label %14
25: ; preds = %14
%26 = load i8*, i8** %3
%27 = call i64 @cg_read_long(i8* %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = load i64, i64* %5
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %25
br label %51
32: ; preds = %25
%33 = load i64, i64* %5
%34 = load i64, i64* %9
%35 = call i32 @values_close(i64 %33, i64 %34, i32 3)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %32
br label %51
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = call i64 @cg_read_key_long(i8* %39, 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 %40, i64* %8
%41 = load i64, i64* %8
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
br label %51
44: ; preds = %38
%45 = load i64, i64* %8
%46 = load i64, i64* %9
%47 = call i32 @values_close(i64 %45, i64 %46, i32 3)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %44
br label %51
50: ; preds = %44
store i32 0, i32* %10
br label %51
51: ; preds = %50, %49, %43, %37, %31
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
%54 = load i32, i32* %10
ret i32 %54
}

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"anon \00"
define i32 @alloc_anon_50M_check(i8* %0, i8* nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(52428800) i8* @malloc(i64 52428800)
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ 0, %2 ], [ %21, %4 ]
%6 = getelementptr inbounds i8, i8* %3, i64 %5
store i8 0, i8* %6
%7 = or i64 %5, 4096
%8 = getelementptr inbounds i8, i8* %3, i64 %7
store i8 0, i8* %8
%9 = or i64 %5, 8192
%10 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 0, i8* %10
%11 = or i64 %5, 12288
%12 = getelementptr inbounds i8, i8* %3, i64 %11
store i8 0, i8* %12
%13 = or i64 %5, 16384
%14 = getelementptr inbounds i8, i8* %3, i64 %13
store i8 0, i8* %14
%15 = or i64 %5, 20480
%16 = getelementptr inbounds i8, i8* %3, i64 %15
store i8 0, i8* %16
%17 = or i64 %5, 24576
%18 = getelementptr inbounds i8, i8* %3, i64 %17
store i8 0, i8* %18
%19 = or i64 %5, 28672
%20 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 0, i8* %20
%21 = add nuw nsw i64 %5, 32768
%22 = icmp ult i64 %19, 52424704
br i1 %22, label %4, label %23
23: ; preds = %4
%24 = tail call i64 @cg_read_long(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%25 = icmp ult i64 %24, 52428800
br i1 %25, label %36, label %26
26: ; preds = %23
%27 = tail call i32 @values_close(i64 52428800, i64 %24, i32 3)
%28 = icmp eq i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = 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))
%31 = icmp slt i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = tail call i32 @values_close(i64 %30, i64 %24, i32 3)
%34 = icmp eq i32 %33, 0
%35 = sext i1 %34 to i32
br label %36
36: ; preds = %32, %29, %26, %23
%37 = phi i32 [ -1, %23 ], [ -1, %29 ], [ -1, %26 ], [ %35, %32 ]
%38 = tail call i32 @free(i8* %3)
ret i32 %37
}