#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 /*<<< orphan*/ 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) {
    cg_killall(cgroup);
    usleep(100);
    goto retry;
  }
  if (ret && errno == ENOENT)
    ret = 0;
  return ret;
}


x86 assembly (clang, -O0):
<cg_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rmdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1184 <cg_destroy+0x54>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jne    1184 <cg_destroy+0x54>
mov    -0x8(%rbp),%rdi
call   1040 <cg_killall@plt>
mov    $0x64,%edi
call   1050 <usleep@plt>
jmp    113c <cg_destroy+0xc>
cmpl   $0x0,-0xc(%rbp)
je     11af <cg_destroy+0x7f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <cg_destroy+0x7f>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%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    %r14d,%r14d
test   %eax,%eax
je     1198 <cg_destroy+0x68>
mov    0x2e93(%rip),%r15
mov    (%r15),%rcx
mov    0x2e81(%rip),%rbp
cmp    0x0(%rbp),%rcx
jne    1187 <cg_destroy+0x57>
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <cg_killall@plt>
mov    $0x64,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
call   1030 <rmdir@plt>
test   %eax,%eax
je     1198 <cg_destroy+0x68>
mov    (%r15),%rcx
cmp    0x0(%rbp),%rcx
je     1160 <cg_destroy+0x30>
mov    0x2e3a(%rip),%rdx
xor    %r14d,%r14d
cmp    (%rdx),%rcx
cmovne %eax,%r14d
mov    %r14d,%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 i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %13, %1
%5 = load i8*, i8** %2
%6 = call i32 @rmdir(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %4
%10 = load i64, i64* @errno
%11 = load i64, i64* @EBUSY
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = call i32 @cg_killall(i8* %14)
%16 = call i32 @usleep(i32 100)
br label %4
17: ; preds = %9, %4
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %3
br label %25
25: ; preds = %24, %20, %17
%26 = load i32, i32* %3
ret i32 %26
}

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 %23, 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 %17
8: ; preds = %12
%9 = load i64, i64* @errno
%10 = load i64, i64* @EBUSY
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %4, %8
%13 = tail call i32 @cg_killall(i8* %0)
%14 = tail call i32 @usleep(i32 100)
%15 = tail call i32 @rmdir(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %23, label %8
17: ; preds = %8, %4
%18 = phi i32 [ %2, %4 ], [ %15, %8 ]
%19 = phi i64 [ %5, %4 ], [ %9, %8 ]
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
%22 = select i1 %21, i32 0, i32 %18
br label %23
23: ; preds = %12, %1, %17
%24 = phi i32 [ %22, %17 ], [ 0, %1 ], [ 0, %12 ]
ret i32 %24
}