#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int fts_info;
  int /*<<< orphan*/ fts_path;
};
typedef TYPE_1__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
#define FTS_DP 129
#define FTS_F 128
int /*<<< orphan*/ FTS_PHYSICAL;
int errno;
int /*<<< orphan*/ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int /*<<< orphan*/, int /*<<< orphan*/);
TYPE_1__ *fts_read(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(int /*<<< orphan*/);
int PBRemoveDirectory(const char *inPath) {
  FTS *ftsp;
  FTSENT *tFile;
  char *tPath[2] = {(char *)inPath, NULL};
  if ((ftsp = fts_open(tPath, FTS_PHYSICAL, 0)) == NULL) {
    return 1;
  }
  while ((tFile = fts_read(ftsp)) != NULL) {
    switch (tFile->fts_info) {
    case FTS_DP:
    case FTS_F:
      if (remove(tFile->fts_path) != 0) {
        fts_close(ftsp);
        return errno;
      }
      break;
    default:
      break;
    }
  }
  fts_close(ftsp);
  return 0;
}


x86 assembly (clang, -O0):
<PBRemoveDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <fts_open@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118a <PBRemoveDirectory+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    120b <PBRemoveDirectory+0xcb>
jmp    118f <PBRemoveDirectory+0x4f>
mov    -0x18(%rbp),%rdi
call   1050 <fts_read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fb <PBRemoveDirectory+0xbb>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     11f1 <PBRemoveDirectory+0xb1>
jmp    11bd <PBRemoveDirectory+0x7d>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <remove@plt>
cmp    $0x0,%eax
je     11ec <PBRemoveDirectory+0xac>
mov    -0x18(%rbp),%rdi
call   1040 <fts_close@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120b <PBRemoveDirectory+0xcb>
jmp    11f6 <PBRemoveDirectory+0xb6>
jmp    11f6 <PBRemoveDirectory+0xb6>
jmp    118f <PBRemoveDirectory+0x4f>
mov    -0x18(%rbp),%rdi
call   1040 <fts_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PBRemoveDirectory>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1060 <fts_open@plt>
test   %rax,%rax
je     11b5 <PBRemoveDirectory+0x75>
mov    %rax,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <fts_read@plt>
test   %rax,%rax
je     11a9 <PBRemoveDirectory+0x69>
mov    (%rax),%ecx
and    $0xfffffffe,%ecx
cmp    $0x80,%ecx
jne    1170 <PBRemoveDirectory+0x30>
mov    0x4(%rax),%edi
call   1030 <remove@plt>
test   %eax,%eax
je     1170 <PBRemoveDirectory+0x30>
mov    %rbx,%rdi
call   1040 <fts_close@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
jmp    11ba <PBRemoveDirectory+0x7a>
mov    %rbx,%rdi
call   1040 <fts_close@plt>
xor    %eax,%eax
jmp    11ba <PBRemoveDirectory+0x7a>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@FTS_PHYSICAL = global i32 0
@errno = global i32 0
define i32 @PBRemoveDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.TYPE_3__*
%6 = alloca [2 x i8*]
store i8* %0, i8** %3
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%8 = load i8*, i8** %3
store i8* %8, i8** %7
%9 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* null, i8** %9
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%11 = load i32, i32* @FTS_PHYSICAL
%12 = call i32* @fts_open(i8** %10, i32 %11, i32 0)
store i32* %12, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %40
15: ; preds = %1
br label %16
16: ; preds = %36, %15
%17 = load i32*, i32** %4
%18 = call %struct.TYPE_3__* @fts_read(i32* %17)
store %struct.TYPE_3__* %18, %struct.TYPE_3__** %5
%19 = icmp ne %struct.TYPE_3__* %18, null
br i1 %19, label %20, label %37
20: ; preds = %16
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 0
%23 = load i32, i32* %22
switch i32 %23, label %35 [
i32 129, label %24
i32 128, label %24
]
24: ; preds = %20, %20
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 @remove(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32*, i32** %4
%32 = call i32 @fts_close(i32* %31)
%33 = load i32, i32* @errno
store i32 %33, i32* %2
br label %40
34: ; preds = %24
br label %36
35: ; preds = %20
br label %36
36: ; preds = %35, %34
br label %16
37: ; preds = %16
%38 = load i32*, i32** %4
%39 = call i32 @fts_close(i32* %38)
store i32 0, i32* %2
br label %40
40: ; preds = %37, %30, %14
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@FTS_PHYSICAL = global i32 0
@errno = global i32 0
define i32 @PBRemoveDirectory(i8* %0) {
%2 = alloca [2 x i8*]
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %4
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %5
%6 = load i32, i32* @FTS_PHYSICAL
%7 = call i32* @fts_open(i8** %4, i32 %6, i32 0)
%8 = icmp eq i32* %7, null
br i1 %8, label %31, label %9
9: ; preds = %1
%10 = call %struct.TYPE_3__* @fts_read(i32* %7)
%11 = icmp eq %struct.TYPE_3__* %10, null
br i1 %11, label %29, label %12
12: ; preds = %9, %26
%13 = phi %struct.TYPE_3__* [ %27, %26 ], [ %10, %9 ]
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, -2
%17 = icmp eq i32 %16, 128
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i64 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 @remove(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = call i32 @fts_close(i32* %7)
%25 = load i32, i32* @errno
br label %31
26: ; preds = %12, %18
%27 = call %struct.TYPE_3__* @fts_read(i32* %7)
%28 = icmp eq %struct.TYPE_3__* %27, null
br i1 %28, label %29, label %12
29: ; preds = %26, %9
%30 = call i32 @fts_close(i32* %7)
br label %31
31: ; preds = %1, %29, %23
%32 = phi i32 [ %25, %23 ], [ 0, %29 ], [ 1, %1 ]
ret i32 %32
}