#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ clone_into_cgroup(int);
int /*<<< orphan*/ close(int);
int dirfd_open_opath(char const *);
int errno;
int /*<<< orphan*/ exit(int);
int clone_into_cgroup_run_nowait(const char *cgroup,
                                 int (*fn)(const char *cgroup, void *arg),
                                 void *arg) {
  int cgroup_fd;
  pid_t pid;
  cgroup_fd = dirfd_open_opath(cgroup);
  if (cgroup_fd < 0)
    return -1;
  pid = clone_into_cgroup(cgroup_fd);
  if (cgroup_fd >= 0) {
    int _e_ = errno;
    close(cgroup_fd);
    errno = _e_;
  };
  if (pid == 0)
    exit(fn(cgroup, arg));
  return pid;
}


x86 assembly (clang, -O0):
<clone_into_cgroup_run_nowait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dirfd_open_opath@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1176 <clone_into_cgroup_run_nowait+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <clone_into_cgroup_run_nowait+0x93>
mov    -0x24(%rbp),%edi
call   1050 <clone_into_cgroup@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11ac <clone_into_cgroup_run_nowait+0x6c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
mov    -0x34(%rbp),%ecx
mov    0x2e36(%rip),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    11cc <clone_into_cgroup_run_nowait+0x8c>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   *%rax
mov    %eax,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clone_into_cgroup_run_nowait>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <dirfd_open_opath@plt>
test   %eax,%eax
js     1199 <clone_into_cgroup_run_nowait+0x59>
mov    %eax,%ebp
mov    %rbx,(%rsp)
mov    %eax,%edi
call   1050 <clone_into_cgroup@plt>
mov    %rax,%rbx
mov    0x2e6c(%rip),%r13
mov    0x0(%r13),%r14d
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r14d,0x0(%r13)
test   %rbx,%rbx
jne    119e <clone_into_cgroup_run_nowait+0x5e>
mov    %r12,%rdi
mov    (%rsp),%rsi
call   *%r15
mov    %eax,%edi
call   1060 <exit@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @clone_into_cgroup_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 i64
%10 = alloca i32
store i8* %0, i8** %5
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = call i32 @dirfd_open_opath(i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %38
16: ; preds = %3
%17 = load i32, i32* %8
%18 = call i64 @clone_into_cgroup(i32 %17)
store i64 %18, i64* %9
%19 = load i32, i32* %8
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @errno
store i32 %22, i32* %10
%23 = load i32, i32* %8
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %10
store i32 %25, i32* @errno
br label %26
26: ; preds = %21, %16
%27 = load i64, i64* %9
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%31 = load i8*, i8** %5
%32 = load i8*, i8** %7
%33 = call i32 %30(i8* %31, i8* %32)
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = load i64, i64* %9
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
br label %38
38: ; preds = %35, %15
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @clone_into_cgroup_run_nowait(i8* %0, i32 (i8*, i8*)* nocapture %1, i8* %2) {
%4 = tail call i32 @dirfd_open_opath(i8* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i64 @clone_into_cgroup(i32 %4)
%8 = load i32, i32* @errno
%9 = tail call i32 @close(i32 %4)
store i32 %8, i32* @errno
%10 = icmp eq i64 %7, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 %1(i8* %0, i8* %2)
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6
%15 = trunc i64 %7 to i32
br label %16
16: ; preds = %3, %14
%17 = phi i32 [ %15, %14 ], [ -1, %3 ]
ret i32 %17
}