#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int rmdir(char const *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strerror(scalar_t__);
char *strutils_cat(int, char *, char const *, int /*<<< orphan*/);
int unlink(char *);
int file_rmdir_recursive(const char *rpath) {
  struct stat statbuf;
  struct dirent *f = NULL;
  DIR *dir = NULL;
  char *fpath = NULL;
  errno = 0;
  if (access(rpath, F_OK) != 0) {
    fprintf(stderr,
            "%s: "
            "file: access()"
            ": %s\n",
            "file", strerror(errno));
    ;
    return 1;
  }
  errno = 0;
  dir = opendir(rpath);
  if (!dir) {
    fprintf(stderr,
            "%s: "
            "file: opendir()"
            ": %s\n",
            "file", strerror(errno));
    ;
    return 1;
  }
  errno = 0;
  while ((f = readdir(dir))) {
    if (strcmp(f->d_name, "..") == 0 || strcmp(f->d_name, ".") == 0) {
      continue;
    }
    fpath = strutils_cat(2, "/", rpath, f->d_name);
    if (!fpath) {
      fprintf(stderr,
              "%s: "
              "Failed to construct filepath for unlink.\n",
              "file");
      ;
      closedir(dir);
      return 1;
    }
    errno = 0;
    if (stat(fpath, &statbuf) == -1) {
      fprintf(stderr,
              "%s: "
              "stat()"
              ": %s\n",
              "file", strerror(errno));
      ;
      free(fpath);
      closedir(dir);
      return 1;
    }
    if (S_ISDIR(statbuf.st_mode)) {
      file_rmdir_recursive(fpath);
    } else {
      if (unlink(fpath) == -1) {
        fprintf(stderr,
                "%s: "
                "unlink()"
                ": %s\n",
                "file", strerror(errno));
        ;
        free(fpath);
        closedir(dir);
        return 1;
      }
    }
  }
  if (errno != 0) {
    fprintf(stderr,
            "%s: "
            "readdir()"
            ": %s\n",
            "file", strerror(errno));
    ;
    free(fpath);
    closedir(dir);
    return 1;
  }
  free(fpath);
  closedir(dir);
  errno = 0;
  if (rmdir(rpath) == -1) {
    fprintf(stderr,
            "%s: "
            "rmdir()"
            ": %s\n",
            "file", strerror(errno));
    ;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<file_rmdir_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2dcd(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
call   10f0 <access@plt>
cmp    $0x0,%rax
je     1270 <file_rmdir_recursive+0x90>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
lea    0xdaa(%rip),%rsi
lea    0xdbb(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
mov    0x2d61(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d8 <file_rmdir_recursive+0xf8>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rcx
lea    0xd5f(%rip),%rsi
lea    0xd53(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
mov    0x2cf9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     149f <file_rmdir_recursive+0x2bf>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1335 <file_rmdir_recursive+0x155>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xd11(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    133a <file_rmdir_recursive+0x15a>
jmp    12e6 <file_rmdir_recursive+0x106>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    $0x2,%edi
lea    0xce9(%rip),%rsi
call   10e0 <strutils_cat@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1397 <file_rmdir_recursive+0x1b7>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
lea    0xc9d(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
mov    0x2c3a(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    140f <file_rmdir_recursive+0x22f>
mov    0x2c1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2c0a(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rcx
lea    0xc86(%rip),%rsi
lea    0xc2e(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
mov    -0x18(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     142f <file_rmdir_recursive+0x24f>
mov    -0x30(%rbp),%rdi
call   10d0 <file_rmdir_recursive@plt>
jmp    149a <file_rmdir_recursive+0x2ba>
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1495 <file_rmdir_recursive+0x2b5>
mov    0x2b98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2b84(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rcx
lea    0xc10(%rip),%rsi
lea    0xba8(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
jmp    149a <file_rmdir_recursive+0x2ba>
jmp    12e6 <file_rmdir_recursive+0x106>
mov    0x2b32(%rip),%rax
cmpq   $0x0,(%rax)
je     1504 <file_rmdir_recursive+0x324>
mov    0x2b29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b15(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rcx
lea    0xbb3(%rip),%rsi
lea    0xb39(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
mov    0x2abb(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <rmdir@plt>
cmp    $0xffffffff,%eax
jne    1578 <file_rmdir_recursive+0x398>
mov    0x2aa3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2a8f(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rcx
lea    0xb40(%rip),%rsi
lea    0xab3(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157f <file_rmdir_recursive+0x39f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_rmdir_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    0x2de0(%rip),%r14
movq   $0x0,(%r14)
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   10f0 <access@plt>
test   %rax,%rax
je     1251 <file_rmdir_recursive+0x71>
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   1100 <strerror@plt>
lea    0xdd6(%rip),%rsi
lea    0xde7(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movq   $0x0,(%r14)
mov    %r15,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1299 <file_rmdir_recursive+0xb9>
mov    %rax,%rbx
movq   $0x0,(%r14)
mov    %rax,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     12b6 <file_rmdir_recursive+0xd6>
mov    %rax,%rbp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xda9(%rip),%r12
lea    0xda3(%rip),%r13
jmp    1374 <file_rmdir_recursive+0x194>
mov    0x2d40(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   1100 <strerror@plt>
lea    0xd6c(%rip),%rsi
jmp    122a <file_rmdir_recursive+0x4a>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    (%r14),%rdi
test   %rdi,%rdi
je     1304 <file_rmdir_recursive+0x124>
mov    0x2d14(%rip),%rax
mov    (%rax),%ebp
call   1100 <strerror@plt>
lea    0xdb1(%rip),%rsi
lea    0xd37(%rip),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1080 <closedir@plt>
jmp    123d <file_rmdir_recursive+0x5d>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1080 <closedir@plt>
movq   $0x0,(%r14)
mov    %r15,%rdi
call   1060 <rmdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1242 <file_rmdir_recursive+0x62>
mov    0x2ca7(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   1100 <strerror@plt>
lea    0xd54(%rip),%rsi
jmp    122a <file_rmdir_recursive+0x4a>
call   10d0 <file_rmdir_recursive@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10c0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12bd <file_rmdir_recursive+0xdd>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1360 <file_rmdir_recursive+0x180>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1360 <file_rmdir_recursive+0x180>
mov    0x0(%rbp),%ecx
mov    $0x2,%edi
lea    0xc96(%rip),%rsi
mov    %r15,%rdx
call   10e0 <strutils_cat@plt>
test   %rax,%rax
je     1411 <file_rmdir_recursive+0x231>
mov    %rax,%rbp
movq   $0x0,(%r14)
mov    %rax,%rdi
lea    0x10(%rsp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1434 <file_rmdir_recursive+0x254>
mov    0x10(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
jne    134f <file_rmdir_recursive+0x16f>
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1360 <file_rmdir_recursive+0x180>
mov    0x2be5(%rip),%rax
mov    (%rax),%ebp
mov    (%r14),%rdi
call   1100 <strerror@plt>
lea    0xc6d(%rip),%rsi
jmp    12da <file_rmdir_recursive+0xfa>
mov    0x2bc8(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
lea    0xbf0(%rip),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    12f7 <file_rmdir_recursive+0x117>
mov    0x2ba5(%rip),%rax
mov    %rbp,%r15
mov    (%rax),%ebp
mov    (%r14),%rdi
call   1100 <strerror@plt>
lea    0xc1a(%rip),%rsi
lea    0xbc2(%rip),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15,%rdi
jmp    12f2 <file_rmdir_recursive+0x112>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@errno = global i64 0
@F_OK = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: file: access(): %s\0A\00"
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [25 x i8] c"%s: file: opendir(): %s\0A\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [46 x i8] c"%s: Failed to construct filepath for unlink.\0A\00"
@.str.7 = [16 x i8] c"%s: stat(): %s\0A\00"
@.str.8 = [18 x i8] c"%s: unlink(): %s\0A\00"
@.str.9 = [19 x i8] c"%s: readdir(): %s\0A\00"
@.str.10 = [17 x i8] c"%s: rmdir(): %s\0A\00"
define i32 @file_rmdir_recursive(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store %struct.dirent* null, %struct.dirent** %5
store i32* null, i32** %6
store i8* null, i8** %7
store i64 0, i64* @errno
%8 = load i8*, i8** %3
%9 = load i32, i32* @F_OK
%10 = call i64 @access(i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i64, i64* @errno
%15 = call i8* @strerror(i64 %14)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %2
br label %120
17: ; preds = %1
store i64 0, i64* @errno
%18 = load i8*, i8** %3
%19 = call i32* @opendir(i8* %18)
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i64, i64* @errno
%25 = call i8* @strerror(i64 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %2
br label %120
27: ; preds = %17
store i64 0, i64* @errno
br label %28
28: ; preds = %93, %44, %27
%29 = load i32*, i32** %6
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %5
%31 = icmp ne %struct.dirent* %30, null
br i1 %31, label %32, label %94
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %5
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i64 @strcmp(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %44, label %38
38: ; preds = %32
%39 = load %struct.dirent*, %struct.dirent** %5
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i64 @strcmp(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38, %32
br label %28
45: ; preds = %38
%46 = load i8*, i8** %3
%47 = load %struct.dirent*, %struct.dirent** %5
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @strutils_cat(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %46, i32 %49)
store i8* %50, i8** %7
%51 = load i8*, i8** %7
%52 = icmp ne i8* %51, null
br i1 %52, label %58, label %53
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%56 = load i32*, i32** %6
%57 = call i32 @closedir(i32* %56)
store i32 1, i32* %2
br label %120
58: ; preds = %45
store i64 0, i64* @errno
%59 = load i8*, i8** %7
%60 = call i32 @stat(i8* %59, %struct.stat* %4)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %71
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i64, i64* @errno
%65 = call i8* @strerror(i64 %64)
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = load i8*, i8** %7
%68 = call i32 @free(i8* %67)
%69 = load i32*, i32** %6
%70 = call i32 @closedir(i32* %69)
store i32 1, i32* %2
br label %120
71: ; preds = %58
%72 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i64 @S_ISDIR(i32 %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i8*, i8** %7
%78 = call i32 @file_rmdir_recursive(i8* %77)
br label %93
79: ; preds = %71
%80 = load i8*, i8** %7
%81 = call i32 @unlink(i8* %80)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %92
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = load i64, i64* @errno
%86 = call i8* @strerror(i64 %85)
%87 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %86)
%88 = load i8*, i8** %7
%89 = call i32 @free(i8* %88)
%90 = load i32*, i32** %6
%91 = call i32 @closedir(i32* %90)
store i32 1, i32* %2
br label %120
92: ; preds = %79
br label %93
93: ; preds = %92, %76
br label %28
94: ; preds = %28
%95 = load i64, i64* @errno
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %106
97: ; preds = %94
%98 = load i32, i32* @stderr
%99 = load i64, i64* @errno
%100 = call i8* @strerror(i64 %99)
%101 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %100)
%102 = load i8*, i8** %7
%103 = call i32 @free(i8* %102)
%104 = load i32*, i32** %6
%105 = call i32 @closedir(i32* %104)
store i32 1, i32* %2
br label %120
106: ; preds = %94
%107 = load i8*, i8** %7
%108 = call i32 @free(i8* %107)
%109 = load i32*, i32** %6
%110 = call i32 @closedir(i32* %109)
store i64 0, i64* @errno
%111 = load i8*, i8** %3
%112 = call i32 @rmdir(i8* %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %119
114: ; preds = %106
%115 = load i32, i32* @stderr
%116 = load i64, i64* @errno
%117 = call i8* @strerror(i64 %116)
%118 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %117)
store i32 1, i32* %2
br label %120
119: ; preds = %106
store i32 0, i32* %2
br label %120
120: ; preds = %119, %114, %97, %83, %62, %53, %22, %12
%121 = load i32, i32* %2
ret i32 %121
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@errno = global i64 0
@F_OK = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: file: access(): %s\0A\00"
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [25 x i8] c"%s: file: opendir(): %s\0A\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [46 x i8] c"%s: Failed to construct filepath for unlink.\0A\00"
@.str.7 = [16 x i8] c"%s: stat(): %s\0A\00"
@.str.8 = [18 x i8] c"%s: unlink(): %s\0A\00"
@.str.9 = [19 x i8] c"%s: readdir(): %s\0A\00"
@.str.10 = [17 x i8] c"%s: rmdir(): %s\0A\00"
define i32 @file_rmdir_recursive(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
store i64 0, i64* @errno
%4 = load i32, i32* @F_OK
%5 = tail call i64 @access(i8* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i64, i64* @errno
%10 = tail call i8* @strerror(i64 %9)
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %98
12: ; preds = %1
store i64 0, i64* @errno
%13 = tail call i32* @opendir(i8* %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %98
20: ; preds = %12
store i64 0, i64* @errno
%21 = tail call %struct.dirent* @readdir(i32* %13)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %78, label %23
23: ; preds = %20
%24 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %25
25: ; preds = %23, %75
%26 = phi %struct.dirent* [ %21, %23 ], [ %76, %75 ]
%27 = phi i8* [ null, %23 ], [ %43, %75 ]
br label %28
28: ; preds = %25, %38
%29 = phi %struct.dirent* [ %26, %25 ], [ %39, %38 ]
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%31 = load i32, i32* %30
%32 = tail call i64 @strcmp(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %28
%35 = load i32, i32* %30
%36 = tail call i64 @strcmp(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34, %28
%39 = tail call %struct.dirent* @readdir(i32* %13)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %78, label %28
41: ; preds = %34
%42 = load i32, i32* %30
%43 = tail call i8* @strutils_cat(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %0, i32 %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 @closedir(i32* %13)
br label %98
49: ; preds = %41
store i64 0, i64* @errno
%50 = call i32 @stat(i8* %43, %struct.stat* %2)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %59
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i64, i64* @errno
%55 = tail call i8* @strerror(i64 %54)
%56 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = tail call i32 @free(i8* %43)
%58 = tail call i32 @closedir(i32* %13)
br label %98
59: ; preds = %49
%60 = load i32, i32* %24
%61 = tail call i64 @S_ISDIR(i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = tail call i32 @file_rmdir_recursive(i8* %43)
br label %75
65: ; preds = %59
%66 = tail call i32 @unlink(i8* %43)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = load i64, i64* @errno
%71 = tail call i8* @strerror(i64 %70)
%72 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %71)
%73 = tail call i32 @free(i8* %43)
%74 = tail call i32 @closedir(i32* %13)
br label %98
75: ; preds = %65, %63
%76 = tail call %struct.dirent* @readdir(i32* %13)
%77 = icmp eq %struct.dirent* %76, null
br i1 %77, label %78, label %25
78: ; preds = %75, %38, %20
%79 = phi i8* [ null, %20 ], [ %27, %38 ], [ %43, %75 ]
%80 = load i64, i64* @errno
%81 = icmp eq i64 %80, 0
br i1 %81, label %88, label %82
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = tail call i8* @strerror(i64 %80)
%85 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %84)
%86 = tail call i32 @free(i8* %79)
%87 = tail call i32 @closedir(i32* %13)
br label %98
88: ; preds = %78
%89 = tail call i32 @free(i8* %79)
%90 = tail call i32 @closedir(i32* %13)
store i64 0, i64* @errno
%91 = tail call i32 @rmdir(i8* %0)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %98
93: ; preds = %88
%94 = load i32, i32* @stderr
%95 = load i64, i64* @errno
%96 = tail call i8* @strerror(i64 %95)
%97 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %96)
br label %98
98: ; preds = %88, %93, %82, %68, %52, %45, %15, %7
%99 = phi i32 [ 1, %7 ], [ 1, %52 ], [ 1, %68 ], [ 1, %45 ], [ 1, %82 ], [ 1, %93 ], [ 1, %15 ], [ 0, %88 ]
ret i32 %99
}