#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ ENOSYS;
int EXIT_FAILURE;
scalar_t__ cg_write(char const *, char *, char *);
int clone_into_cgroup_run_nowait(char const *, int (*)(char const *, void *),
                                 void *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int cg_run_nowait(const char *cgroup, int (*fn)(const char *cgroup, void *arg),
                  void *arg) {
  int pid;
  pid = clone_into_cgroup_run_nowait(cgroup, fn, arg);
  if (pid > 0)
    return pid;
  if (pid < 0 && errno != ENOSYS)
    return -1;
  pid = fork();
  if (pid == 0) {
    char buf[64];
    snprintf(buf, sizeof(buf), "%d", getpid());
    if (cg_write(cgroup, "cgroup.procs", buf))
      exit(EXIT_FAILURE);
    exit(fn(cgroup, arg));
  }
  return pid;
}


x86 assembly (clang, -O0):
<cg_run_nowait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <clone_into_cgroup_run_nowait@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11a0 <cg_run_nowait+0x40>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <cg_run_nowait+0xf1>
cmpl   $0x0,-0x24(%rbp)
jge    11d0 <cg_run_nowait+0x70>
mov    0x2e27(%rip),%rax
mov    (%rax),%rax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
je     11d0 <cg_run_nowait+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <cg_run_nowait+0xf1>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    124b <cg_run_nowait+0xeb>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%ecx
mov    $0x40,%esi
lea    0xdfb(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xdea(%rip),%rsi
call   1050 <cg_write@plt>
cmp    $0x0,%rax
je     1236 <cg_run_nowait+0xd6>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   *%rax
mov    %eax,%edi
call   1070 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_run_nowait>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <clone_into_cgroup_run_nowait@plt>
test   %eax,%eax
jg     11a5 <cg_run_nowait+0x45>
jns    119a <cg_run_nowait+0x3a>
mov    0x2e52(%rip),%rax
mov    (%rax),%rcx
mov    0x2e58(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    11a5 <cg_run_nowait+0x45>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11b1 <cg_run_nowait+0x51>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe41(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1050 <cg_write@plt>
test   %rax,%rax
jne    11f8 <cg_run_nowait+0x98>
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r15
mov    %eax,%edi
call   1070 <exit@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"cgroup.procs\00"
@EXIT_FAILURE = global i32 0
define i32 @cg_run_nowait(i8* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [64 x i8]
store i8* %0, i8** %5
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%12 = load i8*, i8** %7
%13 = call i32 @clone_into_cgroup_run_nowait(i8* %10, i32 (i8*, i8*)* %11, i8* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %8
store i32 %17, i32* %4
br label %49
18: ; preds = %3
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i64, i64* @errno
%23 = load i64, i64* @ENOSYS
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -1, i32* %4
br label %49
26: ; preds = %21, %18
%27 = call i32 (...) @fork()
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %26
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%32 = call i32 (...) @getpid()
%33 = call i32 @snprintf(i8* %31, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%36 = call i64 @cg_write(i8* %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%43 = load i8*, i8** %5
%44 = load i8*, i8** %7
%45 = call i32 %42(i8* %43, i8* %44)
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %26
%48 = load i32, i32* %8
store i32 %48, i32* %4
br label %49
49: ; preds = %47, %25, %16
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"cgroup.procs\00"
@EXIT_FAILURE = global i32 0
define i32 @cg_run_nowait(i8* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca [64 x i8]
%5 = tail call i32 @clone_into_cgroup_run_nowait(i8* %0, i32 (i8*, i8*)* %1, i8* %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %3
%8 = icmp slt i32 %5, 0
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOSYS
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9, %7
%14 = tail call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%18 = tail call i32 (...) @getpid()
%19 = call i32 @snprintf(i8* %17, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i64 @cg_write(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = call i32 %1(i8* %0, i8* %2)
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %13, %9, %3
%29 = phi i32 [ %5, %3 ], [ -1, %9 ], [ %14, %13 ]
ret i32 %29
}