#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 */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ WEXITED;
scalar_t__ clone_into_cgroup(int);
int /*<<< orphan*/ clone_reap(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int dirfd_open_opath(char const *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int clone_into_cgroup_run_wait(const char *cgroup) {
  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)
    return -1;
  if (pid == 0)
    exit(EXIT_SUCCESS);
  (void)clone_reap(pid, WEXITED);
  return 0;
}


x86 assembly (clang, -O0):
<clone_into_cgroup_run_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <dirfd_open_opath@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117e <clone_into_cgroup_run_wait+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <clone_into_cgroup_run_wait+0xad>
mov    -0x14(%rbp),%edi
call   1060 <clone_into_cgroup@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11b4 <clone_into_cgroup_run_wait+0x64>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x24(%rbp),%ecx
mov    0x2e26(%rip),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
jge    11cb <clone_into_cgroup_run_wait+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <clone_into_cgroup_run_wait+0xad>
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <clone_into_cgroup_run_wait+0x94>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1040 <clone_reap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clone_into_cgroup_run_wait>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1050 <dirfd_open_opath@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11a0 <clone_into_cgroup_run_wait+0x50>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <clone_into_cgroup@plt>
mov    %rax,%r14
mov    0x2e5f(%rip),%r15
mov    (%r15),%r12d
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r12d,(%r15)
test   %r14,%r14
js     11a0 <clone_into_cgroup_run_wait+0x50>
je     11ab <clone_into_cgroup_run_wait+0x5b>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <clone_reap@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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