#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_anon(char const *, void *);
int getppid();
int /*<<< orphan*/ sleep(int);
int alloc_anon_noexit(const char *cgroup, void *arg) {
  int ppid = getppid();
  if (alloc_anon(cgroup, arg))
    return -1;
  while (getppid() == ppid)
    sleep(1);
  return 0;
}


x86 assembly (clang, -O0):
<alloc_anon_noexit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getppid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <alloc_anon@plt>
cmp    $0x0,%rax
je     116d <alloc_anon_noexit+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <alloc_anon_noexit+0x68>
jmp    1172 <alloc_anon_noexit+0x42>
mov    $0x0,%al
call   1040 <getppid@plt>
cmp    -0x1c(%rbp),%eax
jne    1191 <alloc_anon_noexit+0x61>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1172 <alloc_anon_noexit+0x42>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_anon_noexit>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <getppid@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <alloc_anon@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1185 <alloc_anon_noexit+0x55>
xor    %eax,%eax
call   1040 <getppid@plt>
mov    $0x0,%ebp
cmp    %ebx,%eax
jne    1185 <alloc_anon_noexit+0x55>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <getppid@plt>
cmp    %ebx,%eax
je     1170 <alloc_anon_noexit+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @alloc_anon_noexit(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i32 (...) @getppid()
store i32 %7, i32* %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i64 @alloc_anon(i8* %8, i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %21
13: ; preds = %2
br label %14
14: ; preds = %18, %13
%15 = call i32 (...) @getppid()
%16 = load i32, i32* %6
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @sleep(i32 1)
br label %14
20: ; preds = %14
store i32 0, i32* %3
br label %21
21: ; preds = %20, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @alloc_anon_noexit(i8* %0, i8* %1) {
%3 = tail call i32 (...) @getppid()
%4 = tail call i64 @alloc_anon(i8* %0, i8* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = tail call i32 (...) @getppid()
%8 = icmp eq i32 %7, %3
br i1 %8, label %9, label %13
9: ; preds = %6, %9
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 (...) @getppid()
%12 = icmp eq i32 %11, %3
br i1 %12, label %9, label %13
13: ; preds = %9, %6, %2
%14 = phi i32 [ -1, %2 ], [ 0, %6 ], [ 0, %9 ]
ret i32 %14
}