#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct FTW {
  int dummy;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ die(char *, char const *);
scalar_t__ rmdir(char const *);
scalar_t__ unlink(char const *);
int rmtree_helper(const char *fpath, const struct stat *sb,
                  int typeflag __attribute__((unused)),
                  struct FTW *ftwbuf __attribute__((unused))) {
  if (S_ISDIR(sb->st_mode)) {
    if (rmdir(fpath) < 0)
      die("Cannot rmdir %s: %m", fpath);
  } else {
    if (unlink(fpath) < 0)
      die("Cannot unlink %s: %m", fpath);
  }
  return 0;
}


x86 assembly (clang, -O0):
<rmtree_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1194 <rmtree_helper+0x54>
mov    -0x8(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    118f <rmtree_helper+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1060 <die@plt>
jmp    11bc <rmtree_helper+0x7c>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11b7 <rmtree_helper+0x77>
mov    -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1060 <die@plt>
jmp    11bc <rmtree_helper+0x7c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmtree_helper>:
push   %rbx
mov    %rdi,%rbx
mov    (%rsi),%edi
call   1050 <S_ISDIR@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1166 <rmtree_helper+0x26>
call   1040 <rmdir@plt>
test   %rax,%rax
jns    117f <rmtree_helper+0x3f>
lea    0xe9c(%rip),%rdi
jmp    1177 <rmtree_helper+0x37>
call   1030 <unlink@plt>
test   %rax,%rax
jns    117f <rmtree_helper+0x3f>
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1060 <die@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.FTW = type { i32 }
@.str = [20 x i8] c"Cannot rmdir %s: %m\00"
@.str.1 = [21 x i8] c"Cannot unlink %s: %m\00"
define i32 @rmtree_helper(i8* %0, %struct.stat* %1, i32 %2, %struct.FTW* %3) {
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32
%8 = alloca %struct.FTW*
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i32 %2, i32* %7
store %struct.FTW* %3, %struct.FTW** %8
%9 = load %struct.stat*, %struct.stat** %6
%10 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @S_ISDIR(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = call i64 @rmdir(i8* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
br label %30
22: ; preds = %4
%23 = load i8*, i8** %5
%24 = call i64 @unlink(i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = call i32 @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %22
br label %30
30: ; preds = %29, %21
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.FTW = type { i32 }
@.str = [20 x i8] c"Cannot rmdir %s: %m\00"
@.str.1 = [21 x i8] c"Cannot unlink %s: %m\00"
define i32 @rmtree_helper(i8* %0, %struct.stat* nocapture %1, i32 %2, %struct.FTW* nocapture readnone %3) {
%5 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i64 @S_ISDIR(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i64 @rmdir(i8* %0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %15, label %18
12: ; preds = %4
%13 = tail call i64 @unlink(i8* %0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %9
%16 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %12 ]
%17 = tail call i32 @die(i8* %16, i8* %0)
br label %18
18: ; preds = %15, %12, %9
ret i32 0
}