#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 */
int MAP_ANON;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int getppid();
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ sleep(int);
scalar_t__ touch_anon(char *, size_t);
int alloc_and_touch_anon_noexit(const char *cgroup, void *arg) {
  int ppid = getppid();
  size_t size = (size_t)arg;
  void *buf;
  buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
  if (buf == MAP_FAILED)
    return -1;
  if (touch_anon((char *)buf, size)) {
    munmap(buf, size);
    return -1;
  }
  while (getppid() == ppid)
    sleep(1);
  munmap(buf, size);
  return 0;
}


x86 assembly (clang, -O0):
<alloc_and_touch_anon_noexit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    0x2e52(%rip),%rax
or     (%rax),%edx
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
mov    0x2e38(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    11cd <alloc_and_touch_anon_noexit+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <alloc_and_touch_anon_noexit+0xe5>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <touch_anon@plt>
cmp    $0x0,%rax
je     11fd <alloc_and_touch_anon_noexit+0xad>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <munmap@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <alloc_and_touch_anon_noexit+0xe5>
jmp    1202 <alloc_and_touch_anon_noexit+0xb2>
mov    $0x0,%al
call   1060 <getppid@plt>
cmp    -0x1c(%rbp),%eax
jne    1221 <alloc_and_touch_anon_noexit+0xd1>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1202 <alloc_and_touch_anon_noexit+0xb2>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_and_touch_anon_noexit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %eax,%ebp
mov    0x2e8e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e4c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x2e1f(%rip),%rax
cmp    (%rax),%r15
je     11f2 <alloc_and_touch_anon_noexit+0xa2>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <touch_anon@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11e5 <alloc_and_touch_anon_noexit+0x95>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
cmp    %ebp,%eax
jne    11e5 <alloc_and_touch_anon_noexit+0x95>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
cmp    %ebp,%eax
je     11d0 <alloc_and_touch_anon_noexit+0x80>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <munmap@plt>
jmp    11f7 <alloc_and_touch_anon_noexit+0xa7>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
define i32 @alloc_and_touch_anon_noexit(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i32 (...) @getppid()
store i32 %9, i32* %6
%10 = load i8*, i8** %5
%11 = ptrtoint i8* %10 to i64
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @PROT_WRITE
%15 = or i32 %13, %14
%16 = load i32, i32* @MAP_PRIVATE
%17 = load i32, i32* @MAP_ANON
%18 = or i32 %16, %17
%19 = call i8* @mmap(i32* null, i64 %12, i32 %15, i32 %18, i32 0, i32 0)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8*, i8** @MAP_FAILED
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 -1, i32* %3
br label %44
24: ; preds = %2
%25 = load i8*, i8** %8
%26 = load i64, i64* %7
%27 = call i64 @touch_anon(i8* %25, i64 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i8*, i8** %8
%31 = load i64, i64* %7
%32 = call i32 @munmap(i8* %30, i64 %31)
store i32 -1, i32* %3
br label %44
33: ; preds = %24
br label %34
34: ; preds = %38, %33
%35 = call i32 (...) @getppid()
%36 = load i32, i32* %6
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @sleep(i32 1)
br label %34
40: ; preds = %34
%41 = load i8*, i8** %8
%42 = load i64, i64* %7
%43 = call i32 @munmap(i8* %41, i64 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %40, %29, %23
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
define i32 @alloc_and_touch_anon_noexit(i8* nocapture readnone %0, i8* %1) {
%3 = tail call i32 (...) @getppid()
%4 = ptrtoint i8* %1 to i64
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANON
%10 = or i32 %9, %8
%11 = tail call i8* @mmap(i32* null, i64 %4, i32 %7, i32 %10, i32 0, i32 0)
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %27, label %14
14: ; preds = %2
%15 = tail call i64 @touch_anon(i8* %11, i64 %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = tail call i32 (...) @getppid()
%19 = icmp eq i32 %18, %3
br i1 %19, label %20, label %24
20: ; preds = %17, %20
%21 = tail call i32 @sleep(i32 1)
%22 = tail call i32 (...) @getppid()
%23 = icmp eq i32 %22, %3
br i1 %23, label %20, label %24
24: ; preds = %20, %17, %14
%25 = phi i32 [ -1, %14 ], [ 0, %17 ], [ 0, %20 ]
%26 = tail call i32 @munmap(i8* %11, i64 %4)
br label %27
27: ; preds = %24, %2
%28 = phi i32 [ -1, %2 ], [ %25, %24 ]
ret i32 %28
}