#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__ EEXIST;
scalar_t__ ENOTEMPTY;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ rmdir(char const *);
void remove_dir(const char *dirpath) {
  errno = 0;
  if (rmdir(dirpath) != 0) {
    if (errno == ENOTEMPTY || errno == EEXIST) {
      printf("Directory %s not removed: still contains files\n", dirpath);
    } else {
      printf("Directory %s not removed: no permissions OR directory in use\n",
             dirpath);
    }
  }
}


x86 assembly (clang, -O0):
<remove_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <rmdir@plt>
cmp    $0x0,%rax
je     11ab <remove_dir+0x8b>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
je     1181 <remove_dir+0x61>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <remove_dir+0x76>
mov    -0x8(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
jmp    11a6 <remove_dir+0x86>
mov    -0x8(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
jmp    11ab <remove_dir+0x8b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%r14
movq   $0x0,(%r14)
call   1030 <rmdir@plt>
test   %rax,%rax
je     117b <remove_dir+0x5b>
mov    (%r14),%rax
mov    0x2e7f(%rip),%rcx
mov    0x2e90(%rip),%rdx
cmp    (%rdx),%rax
lea    0xea6(%rip),%rdx
lea    0xecf(%rip),%rdi
cmove  %rdx,%rdi
cmp    (%rcx),%rax
cmove  %rdx,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOTEMPTY = global i64 0
@EEXIST = global i64 0
@.str = [48 x i8] c"Directory %s not removed: still contains files\0A\00"
@.str.1 = [62 x i8] c"Directory %s not removed: no permissions OR directory in use\0A\00"
define void @remove_dir(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%3 = load i8*, i8** %2
%4 = call i64 @rmdir(i8* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOTEMPTY
%9 = icmp eq i64 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10, %6
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %20
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %1
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@ENOTEMPTY = global i64 0
@EEXIST = global i64 0
@.str = [48 x i8] c"Directory %s not removed: still contains files\0A\00"
@.str.1 = [62 x i8] c"Directory %s not removed: no permissions OR directory in use\0A\00"
define void @remove_dir(i8* %0) {
store i64 0, i64* @errno
%2 = tail call i64 @rmdir(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENOTEMPTY
%7 = icmp eq i64 %5, %6
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %5, %8
%10 = select i1 %7, i1 true, i1 %9
%11 = select i1 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0)
%12 = tail call i32 @printf(i8* %11, i8* %0)
br label %13
13: ; preds = %4, %1
ret void
}