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


x86 assembly (clang, -O0):
<alloc_anon_50M_check_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x3200000,-0x20(%rbp)
03
movl   $0xffffffff,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    11ab <alloc_anon_50M_check_swap+0x6b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x30(%rbp)
jmp    117c <alloc_anon_50M_check_swap+0x3c>
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1040 <cg_read_long@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e5 <alloc_anon_50M_check_swap+0xa5>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1060 <values_close@plt>
cmp    $0x0,%eax
jne    11ea <alloc_anon_50M_check_swap+0xaa>
jmp    1234 <alloc_anon_50M_check_swap+0xf4>
mov    -0x8(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <cg_read_long@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1228 <alloc_anon_50M_check_swap+0xe8>
mov    -0x38(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1060 <values_close@plt>
cmp    $0x0,%eax
jne    122d <alloc_anon_50M_check_swap+0xed>
jmp    1234 <alloc_anon_50M_check_swap+0xf4>
movl   $0x0,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_anon_50M_check_swap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x3200000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0xfffffffffffff000,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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_swap+0x30>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1040 <cg_read_long@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     121e <alloc_anon_50M_check_swap+0xde>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1060 <values_close@plt>
test   %eax,%eax
je     121e <alloc_anon_50M_check_swap+0xde>
lea    0xe19(%rip),%rsi
mov    %r14,%rdi
call   1040 <cg_read_long@plt>
test   %rax,%rax
je     121e <alloc_anon_50M_check_swap+0xde>
add    %rbp,%rax
mov    $0x3200000,%esi
mov    %rax,%rdi
mov    $0x3,%edx
call   1060 <values_close@plt>
cmp    $0x1,%eax
sbb    %r12d,%r12d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"memory.current\00"
@.str.1 = [20 x i8] c"memory.swap.current\00"
define i32 @alloc_anon_50M_check_swap(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %4
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %5
store i64 52428800, i64* %6
store i32 -1, i32* %11
%14 = load i64, i64* %6
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
store i8* %16, i8** %8
br label %17
17: ; preds = %25, %2
%18 = load i8*, i8** %8
%19 = load i8*, i8** %7
%20 = load i64, i64* %6
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = icmp ult i8* %18, %21
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8*, i8** %8
store i8 0, i8* %24
br label %25
25: ; preds = %23
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 4096
store i8* %27, i8** %8
br label %17
28: ; preds = %17
%29 = load i8*, i8** %3
%30 = call i64 @cg_read_long(i8* %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 %30, i64* %9
%31 = load i64, i64* %9
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i64, i64* %9
%35 = load i64, i64* %5
%36 = call i32 @values_close(i64 %34, i64 %35, i32 3)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %33, %28
br label %53
39: ; preds = %33
%40 = load i8*, i8** %3
%41 = call i64 @cg_read_long(i8* %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i64 %41, i64* %10
%42 = load i64, i64* %10
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i64, i64* %9
%46 = load i64, i64* %10
%47 = add nsw i64 %45, %46
%48 = load i64, i64* %6
%49 = call i32 @values_close(i64 %47, i64 %48, i32 3)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %44, %39
br label %53
52: ; preds = %44
store i32 0, i32* %11
br label %53
53: ; preds = %52, %51, %38
%54 = load i8*, i8** %7
%55 = call i32 @free(i8* %54)
%56 = load i32, i32* %11
ret i32 %56
}

LLVM IR (-O2):
@.str = [15 x i8] c"memory.current\00"
@.str.1 = [20 x i8] c"memory.swap.current\00"
define i32 @alloc_anon_50M_check_swap(i8* %0, i8* %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 eq i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %23
%27 = ptrtoint i8* %1 to i64
%28 = tail call i32 @values_close(i64 %24, i64 %27, i32 3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = tail call i64 @cg_read_long(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = add nsw i64 %31, %24
%35 = tail call i32 @values_close(i64 %34, i64 52428800, i32 3)
%36 = icmp eq i32 %35, 0
%37 = sext i1 %36 to i32
br label %38
38: ; preds = %33, %30, %23, %26
%39 = phi i32 [ -1, %30 ], [ -1, %26 ], [ -1, %23 ], [ %37, %33 ]
%40 = tail call i32 @free(i8* %3)
ret i32 %39
}