#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;
  char const *fts_accpath;
  char const *fts_path;
  int /*<<< orphan*/ fts_errno;
};
typedef TYPE_1__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
#define FTS_D 139
#define FTS_DC 138
#define FTS_DEFAULT 137
#define FTS_DNR 136
#define FTS_DOT 135
#define FTS_DP 134
#define FTS_ERR 133
#define FTS_F 132
int FTS_NOCHDIR;
#define FTS_NS 131
#define FTS_NSOK 130
int FTS_PHYSICAL;
#define FTS_SL 129
#define FTS_SLNONE 128
int FTS_XDEV;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int, int /*<<< orphan*/ *);
TYPE_1__ *fts_read(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int rm_tree(const char *path) {
  int result = 0;
  FTS *fts = NULL;
  FTSENT *p = NULL;
  char *files[] = {(char *)path, NULL};
  fts = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
  if (!fts) {
    fprintf(stderr, "%s: fts_open failed: %s\n", path, strerror(errno));
    return -1;
  }
  while ((p = fts_read(fts)) != NULL) {
    switch (p->fts_info) {
    case FTS_DNR:
    case FTS_ERR:
    case FTS_NS:
      fprintf(stderr, "%s: fts_read error: %s\n", p->fts_accpath,
              strerror(p->fts_errno));
      break;
    case FTS_DC:
    case FTS_DOT:
    case FTS_NSOK:
      break;
    case FTS_D:
      break;
    case FTS_DP:
    case FTS_F:
    case FTS_SL:
    case FTS_SLNONE:
    case FTS_DEFAULT:
      if (remove(p->fts_accpath) < 0) {
        fprintf(stderr, "%s: Failed to remove: %s\n", p->fts_path,
                strerror(errno));
        result = -1;
      }
      break;
    }
  }
  fts_close(fts);
  return result;
}


x86 assembly (clang, -O0):
<rm_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e46(%rip),%rax
or     (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <fts_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1211 <rm_tree+0xb1>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe30(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <rm_tree+0x1b4>
jmp    1216 <rm_tree+0xb6>
mov    -0x20(%rbp),%rdi
call   1050 <fts_read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1305 <rm_tree+0x1a5>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0xb,%eax
ja     1300 <rm_tree+0x1a0>
mov    -0x58(%rbp),%rax
lea    0xdb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%edi
call   1080 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xdbb(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1300 <rm_tree+0x1a0>
jmp    1300 <rm_tree+0x1a0>
jmp    1300 <rm_tree+0x1a0>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <remove@plt>
cmp    $0x0,%eax
jge    12fb <rm_tree+0x19b>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd72(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    1300 <rm_tree+0x1a0>
jmp    1216 <rm_tree+0xb6>
mov    -0x20(%rbp),%rdi
call   1040 <fts_close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_tree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    0x2e4c(%rip),%rax
mov    0x2e6d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movq   $0x0,0x8(%rsp)
mov    0x2e29(%rip),%rax
or     (%rax),%esi
xor    %r14d,%r14d
mov    %rsp,%rdi
xor    %edx,%edx
call   1060 <fts_open@plt>
test   %rax,%rax
je     1292 <rm_tree+0x132>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <fts_read@plt>
test   %rax,%rax
je     1288 <rm_tree+0x128>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    $0x253,%r12d
jmp    11f4 <rm_tree+0x94>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <fts_read@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1288 <rm_tree+0x128>
mov    (%rbx),%eax
add    $0xffffff80,%eax
cmp    $0x9,%eax
ja     11e0 <rm_tree+0x80>
bt     %eax,%r12d
jae    1250 <rm_tree+0xf0>
mov    0x8(%rbx),%rdi
call   1030 <remove@plt>
test   %eax,%eax
jns    11e0 <rm_tree+0x80>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rbx),%rbx
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %ebp,%edi
lea    0xdfc(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    11e0 <rm_tree+0x80>
nopl   0x0(%rax,%rax,1)
mov    $0x128,%ecx
bt     %eax,%ecx
jae    11e0 <rm_tree+0x80>
mov    0x2d77(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%r15
mov    0x18(%rbx),%edi
call   1080 <strerror@plt>
mov    %ebp,%edi
lea    0xda1(%rip),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
jmp    11e0 <rm_tree+0x80>
mov    %r13,%rdi
call   1040 <fts_close@plt>
jmp    12c3 <rm_tree+0x163>
mov    0x2d3f(%rip),%rax
mov    (%rax),%ebp
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd50(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8*, i8*, i32 }
@FTS_NOCHDIR = global i32 0
@FTS_PHYSICAL = global i32 0
@FTS_XDEV = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: fts_open failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [24 x i8] c"%s: fts_read error: %s\0A\00"
@.str.2 = [26 x i8] c"%s: Failed to remove: %s\0A\00"
define i32 @rm_tree(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.TYPE_3__*
%7 = alloca [2 x i8*]
store i8* %0, i8** %3
store i32 0, i32* %4
store i32* null, i32** %5
store %struct.TYPE_3__* null, %struct.TYPE_3__** %6
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%9 = load i8*, i8** %3
store i8* %9, i8** %8
%10 = getelementptr inbounds i8*, i8** %8, i64 1
store i8* null, i8** %10
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%12 = load i32, i32* @FTS_NOCHDIR
%13 = load i32, i32* @FTS_PHYSICAL
%14 = or i32 %12, %13
%15 = load i32, i32* @FTS_XDEV
%16 = or i32 %14, %15
%17 = call i32* @fts_open(i8** %11, i32 %16, i32* null)
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
store i32 -1, i32* %2
br label %67
26: ; preds = %1
br label %27
27: ; preds = %62, %26
%28 = load i32*, i32** %5
%29 = call %struct.TYPE_3__* @fts_read(i32* %28)
store %struct.TYPE_3__* %29, %struct.TYPE_3__** %6
%30 = icmp ne %struct.TYPE_3__* %29, null
br i1 %30, label %31, label %63
31: ; preds = %27
%32 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i32 0, i32 0
%34 = load i32, i32* %33
switch i32 %34, label %62 [
i32 136, label %35
i32 133, label %35
i32 131, label %35
i32 138, label %45
i32 135, label %45
i32 130, label %45
i32 139, label %46
i32 134, label %47
i32 132, label %47
i32 129, label %47
i32 128, label %47
i32 137, label %47
]
35: ; preds = %31, %31, %31
%36 = load i32, i32* @stderr
%37 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 1
%39 = load i8*, i8** %38
%40 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %40, i32 0, i32 3
%42 = load i32, i32* %41
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %43)
br label %62
45: ; preds = %31, %31, %31
br label %62
46: ; preds = %31
br label %62
47: ; preds = %31, %31, %31, %31, %31
%48 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %48, i32 0, i32 1
%50 = load i8*, i8** %49
%51 = call i32 @remove(i8* %50)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 2
%57 = load i8*, i8** %56
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* %59)
store i32 -1, i32* %4
br label %61
61: ; preds = %53, %47
br label %62
62: ; preds = %31, %61, %46, %45, %35
br label %27
63: ; preds = %27
%64 = load i32*, i32** %5
%65 = call i32 @fts_close(i32* %64)
%66 = load i32, i32* %4
store i32 %66, i32* %2
br label %67
67: ; preds = %63, %20
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8*, i8*, i32 }
@FTS_NOCHDIR = global i32 0
@FTS_PHYSICAL = global i32 0
@FTS_XDEV = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: fts_open failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [24 x i8] c"%s: fts_read error: %s\0A\00"
@.str.2 = [26 x i8] c"%s: Failed to remove: %s\0A\00"
define i32 @rm_tree(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_NOCHDIR
%7 = load i32, i32* @FTS_PHYSICAL
%8 = or i32 %7, %6
%9 = load i32, i32* @FTS_XDEV
%10 = or i32 %8, %9
%11 = call i32* @fts_open(i8** %4, i32 %10, i32* null)
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = call %struct.TYPE_3__* @fts_read(i32* %11)
%15 = icmp eq %struct.TYPE_3__* %14, null
br i1 %15, label %50, label %21
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %19)
br label %53
21: ; preds = %13, %46
%22 = phi %struct.TYPE_3__* [ %48, %46 ], [ %14, %13 ]
%23 = phi i32 [ %47, %46 ], [ 0, %13 ]
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 0
%25 = load i32, i32* %24
switch i32 %25, label %46 [
i32 136, label %26
i32 133, label %26
i32 131, label %26
i32 128, label %34
i32 129, label %34
i32 132, label %34
i32 137, label %34
i32 134, label %34
]
26: ; preds = %21, %21, %21
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 3
%31 = load i32, i32* %30
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %32)
br label %46
34: ; preds = %21, %21, %21, %21, %21
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 1
%36 = load i8*, i8** %35
%37 = call i32 @remove(i8* %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 2
%42 = load i8*, i8** %41
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %44)
br label %46
46: ; preds = %34, %39, %21, %26
%47 = phi i32 [ %23, %21 ], [ -1, %39 ], [ %23, %34 ], [ %23, %26 ]
%48 = call %struct.TYPE_3__* @fts_read(i32* %11)
%49 = icmp eq %struct.TYPE_3__* %48, null
br i1 %49, label %50, label %21
50: ; preds = %46, %13
%51 = phi i32 [ 0, %13 ], [ %47, %46 ]
%52 = call i32 @fts_close(i32* %11)
br label %53
53: ; preds = %50, %16
%54 = phi i32 [ %51, %50 ], [ -1, %16 ]
ret i32 %54
}