#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__ EBUSY;
scalar_t__ ENOENT;
int cg_killall(char const *);
scalar_t__ errno;
int rmdir(char const *);
int /*<<< orphan*/ usleep(int);
int cg_destroy(const char *cgroup) {
  int ret;
retry:
  ret = rmdir(cgroup);
  if (ret && errno == EBUSY) {
    ret = cg_killall(cgroup);
    if (ret)
      return ret;
    usleep(100);
    goto retry;
  }
  if (ret && errno == ENOENT)
    ret = 0;
  return ret;
}


x86 assembly (clang, -O0):
<cg_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <rmdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119c <cg_destroy+0x6c>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <cg_destroy+0x6c>
mov    -0x10(%rbp),%rdi
call   1040 <cg_killall@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118d <cg_destroy+0x5d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <cg_destroy+0x9d>
mov    $0x64,%edi
call   1050 <usleep@plt>
jmp    113c <cg_destroy+0xc>
cmpl   $0x0,-0x14(%rbp)
je     11c7 <cg_destroy+0x97>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    11c7 <cg_destroy+0x97>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_destroy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <rmdir@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     119d <cg_destroy+0x6d>
mov    0x2e94(%rip),%r14
mov    (%r14),%rcx
mov    0x2e82(%rip),%r15
cmp    (%r15),%rcx
jne    118a <cg_destroy+0x5a>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <cg_killall@plt>
test   %eax,%eax
jne    119b <cg_destroy+0x6b>
mov    $0x64,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <rmdir@plt>
test   %eax,%eax
je     119d <cg_destroy+0x6d>
mov    (%r14),%rcx
cmp    (%r15),%rcx
je     1160 <cg_destroy+0x30>
mov    0x2e37(%rip),%rdx
xor    %ebp,%ebp
cmp    (%rdx),%rcx
cmovne %eax,%ebp
jmp    119d <cg_destroy+0x6d>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EBUSY = global i64 0
@ENOENT = global i64 0
define i32 @cg_destroy(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
br label %5
5: ; preds = %21, %1
%6 = load i8*, i8** %3
%7 = call i32 @rmdir(i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = load i64, i64* @EBUSY
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32 @cg_killall(i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %33
21: ; preds = %14
%22 = call i32 @usleep(i32 100)
br label %5
23: ; preds = %10, %5
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOENT
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %4
br label %31
31: ; preds = %30, %26, %23
%32 = load i32, i32* %4
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %19
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
@EBUSY = global i64 0
@ENOENT = global i64 0
define i32 @cg_destroy(i8* %0) {
%2 = tail call i32 @rmdir(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %25, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EBUSY
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %19
8: ; preds = %15
%9 = load i64, i64* @errno
%10 = load i64, i64* @EBUSY
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %4, %8
%13 = tail call i32 @cg_killall(i8* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = tail call i32 @usleep(i32 100)
%17 = tail call i32 @rmdir(i8* %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %8
19: ; preds = %8, %4
%20 = phi i32 [ %2, %4 ], [ %17, %8 ]
%21 = phi i64 [ %5, %4 ], [ %9, %8 ]
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %21, %22
%24 = select i1 %23, i32 0, i32 %20
br label %25
25: ; preds = %12, %15, %1, %19
%26 = phi i32 [ %24, %19 ], [ 0, %1 ], [ %13, %12 ], [ 0, %15 ]
ret i32 %26
}