#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 */
int EXIT_FAILURE;
scalar_t__ cg_write(char const *, char *, char *);
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 = 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    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11df <cg_run_nowait+0x8f>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%ecx
mov    $0x40,%esi
lea    0xe67(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1050 <cg_write@plt>
cmp    $0x0,%rax
je     11ca <cg_run_nowait+0x7a>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x70,%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
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     117b <cg_run_nowait+0x2b>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe77(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1050 <cg_write@plt>
test   %rax,%rax
jne    11c2 <cg_run_nowait+0x72>
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r15
mov    %eax,%edi
call   1060 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.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 i8*
%5 = alloca i32 (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [64 x i8]
store i8* %0, i8** %4
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %5
store i8* %2, i8** %6
%9 = call i32 (...) @fork()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %3
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%14 = call i32 (...) @getpid()
%15 = call i32 @snprintf(i8* %13, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%18 = call i64 @cg_write(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %5
%25 = load i8*, i8** %4
%26 = load i8*, i8** %6
%27 = call i32 %24(i8* %25, i8* %26)
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %3
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@.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*)* nocapture %1, i8* %2) {
%4 = alloca [64 x i8]
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %3
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = tail call i32 (...) @getpid()
%10 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i64 @cg_write(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = call i32 %1(i8* %0, i8* %2)
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
ret i32 %5
}