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

/* Variables and functions */
int PATH_MAX;
int S_IFDIR;
int S_IFMT;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int errno;
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
scalar_t__ readdir(int /*<<< orphan*/ *);
scalar_t__ rmdir(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int);
scalar_t__ unlink(char *);
int rmobj(char *obj, char **errmsg) {
  int ret_val = 0;
  DIR *dir;
  struct dirent *dir_ent;
  char dirobj[PATH_MAX];
  struct stat statbuf;
  static char err_msg[1024];
  if (lstat(obj, &statbuf) < 0) {
    if (errmsg != NULL) {
      sprintf(err_msg, "lstat(%s) failed; errno=%d: %s", obj, errno,
              strerror(errno));
      *errmsg = err_msg;
    }
    return -1;
  }
  if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
    if (!strcmp(obj, "/")) {
      if (errmsg != NULL) {
        sprintf(err_msg, "Cannot remove /");
        *errmsg = err_msg;
      }
      return -1;
    }
    if ((dir = opendir(obj)) == NULL) {
      if (rmdir(obj) != 0) {
        if (errmsg != NULL) {
          sprintf(err_msg, "rmdir(%s) failed; errno=%d: %s", obj, errno,
                  strerror(errno));
          *errmsg = err_msg;
        }
        return -1;
      } else {
        return 0;
      }
    }
    for (dir_ent = (struct dirent *)readdir(dir); dir_ent != NULL;
         dir_ent = (struct dirent *)readdir(dir)) {
      if (!strcmp(dir_ent->d_name, ".") || !strcmp(dir_ent->d_name, ".."))
        continue;
      sprintf(dirobj, "%s/%s", obj, dir_ent->d_name);
      if (rmobj(dirobj, errmsg) != 0)
        ret_val = -1;
    }
    closedir(dir);
    if (ret_val == -1)
      return -1;
    if (lstat(obj, &statbuf) < 0) {
      if (errmsg != NULL) {
        sprintf(err_msg, "lstat(%s) failed; errno=%d: %s", obj, errno,
                strerror(errno));
        *errmsg = err_msg;
      }
      return -1;
    }
    if (statbuf.st_nlink >= 3) {
      if (unlink(obj) < 0) {
        if (errmsg != NULL) {
          sprintf(err_msg, "unlink(%s) failed; errno=%d: %s", obj, errno,
                  strerror(errno));
          *errmsg = err_msg;
        }
        return -1;
      }
    } else {
      if (rmdir(obj) < 0) {
        if (errmsg != NULL) {
          sprintf(err_msg, "remove(%s) failed; errno=%d: %s", obj, errno,
                  strerror(errno));
          *errmsg = err_msg;
        }
        return -1;
      }
    }
  } else {
    if (unlink(obj) < 0) {
      if (errmsg != NULL) {
        sprintf(err_msg, "unlink(%s) failed; errno=%d: %s", obj, errno,
                strerror(errno));
        *errmsg = err_msg;
      }
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<rmobj>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1070 <lstat@plt>
cmp    $0x0,%rax
jge    126a <rmobj+0xca>
cmpq   $0x0,-0x18(%rbp)
je     1257 <rmobj+0xb7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x68(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
mov    %rax,%r8
lea    0x2e55(%rip),%rdi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2e3c(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
mov    -0x48(%rbp),%eax
mov    0x2d64(%rip),%rcx
and    (%rcx),%eax
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%eax
jne    1610 <rmobj+0x470>
mov    -0x10(%rbp),%rdi
lea    0xd9d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12df <rmobj+0x13f>
cmpq   $0x0,-0x18(%rbp)
je     12cc <rmobj+0x12c>
lea    0x2de0(%rip),%rdi
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2dc7(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1389 <rmobj+0x1e9>
mov    -0x10(%rbp),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
je     1376 <rmobj+0x1d6>
cmpq   $0x0,-0x18(%rbp)
je     1363 <rmobj+0x1c3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x78(%rbp),%rdx
mov    -0x6c(%rbp),%ecx
mov    %rax,%r8
lea    0x2d49(%rip),%rdi
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2d30(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
mov    -0x28(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     142f <rmobj+0x28f>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xca0(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
je     13d9 <rmobj+0x239>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xc83(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    13de <rmobj+0x23e>
jmp    141d <rmobj+0x27d>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xc5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <rmobj@plt>
cmp    $0x0,%eax
je     1418 <rmobj+0x278>
movl   $0xffffffff,-0x1c(%rbp)
jmp    141d <rmobj+0x27d>
mov    -0x28(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x30(%rbp)
jmp    1396 <rmobj+0x1f6>
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1455 <rmobj+0x2b5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1070 <lstat@plt>
cmp    $0x0,%rax
jge    14df <rmobj+0x33f>
cmpq   $0x0,-0x18(%rbp)
je     14cc <rmobj+0x32c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x88(%rbp),%rdx
mov    -0x7c(%rbp),%ecx
mov    %rax,%r8
lea    0x2be0(%rip),%rdi
lea    0xb49(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2bc7(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
cmpl   $0x3,-0x44(%rbp)
jl     157a <rmobj+0x3da>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1575 <rmobj+0x3d5>
cmpq   $0x0,-0x18(%rbp)
je     1562 <rmobj+0x3c2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x2ab7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2aa8(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x98(%rbp),%rdx
mov    -0x8c(%rbp),%ecx
mov    %rax,%r8
lea    0x2b4a(%rip),%rdi
lea    0xb0a(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2b31(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
jmp    160b <rmobj+0x46b>
mov    -0x10(%rbp),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
jge    1606 <rmobj+0x466>
cmpq   $0x0,-0x18(%rbp)
je     15f3 <rmobj+0x453>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2a26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x2a17(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xa8(%rbp),%rdx
mov    -0x9c(%rbp),%ecx
mov    %rax,%r8
lea    0x2ab9(%rip),%rdi
lea    0xa99(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2aa0(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
jmp    160b <rmobj+0x46b>
jmp    16a1 <rmobj+0x501>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    169c <rmobj+0x4fc>
cmpq   $0x0,-0x18(%rbp)
je     1689 <rmobj+0x4e9>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2990(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2981(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xb8(%rbp),%rdx
mov    -0xac(%rbp),%ecx
mov    %rax,%r8
lea    0x2a23(%rip),%rdi
lea    0x9e3(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
lea    0x2a0a(%rip),%rcx
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16af <rmobj+0x50f>
jmp    16a1 <rmobj+0x501>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmobj>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rsi
call   1070 <lstat@plt>
test   %rax,%rax
js     137a <rmobj+0x1da>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
and    -0x30(%rbp),%eax
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%eax
jne    1343 <rmobj+0x1a3>
lea    0xe28(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     12af <rmobj+0x10f>
mov    %r15,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12e6 <rmobj+0x146>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1320 <rmobj+0x180>
mov    %r15,-0x38(%rbp)
mov    %r14,-0x40(%rbp)
lea    0xe06(%rip),%r13
xor    %r15d,%r15d
jmp    125d <rmobj+0xbd>
xchg   %ax,%ax
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     12cb <rmobj+0x12b>
mov    (%rax),%r14
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1250 <rmobj+0xb0>
mov    %r14,%rdi
lea    0xdd5(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1250 <rmobj+0xb0>
mov    %rbx,%rdi
lea    0xdc5(%rip),%rsi
mov    -0x38(%rbp),%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <rmobj@plt>
neg    %eax
sbb    %eax,%eax
or     %eax,%r15d
jmp    1250 <rmobj+0xb0>
test   %r14,%r14
je     13b6 <rmobj+0x216>
movups 0xd60(%rip),%xmm0
movaps %xmm0,0x2dca(%rip)
jmp    13ac <rmobj+0x20c>
mov    %r12,%rdi
call   1060 <closedir@plt>
cmp    $0xffffffff,%r15d
mov    -0x40(%rbp),%r14
mov    -0x38(%rbp),%r15
jne    1328 <rmobj+0x188>
jmp    13b6 <rmobj+0x216>
mov    %r15,%rdi
call   1050 <rmdir@plt>
test   %rax,%rax
je     1401 <rmobj+0x261>
test   %r14,%r14
je     13b6 <rmobj+0x216>
mov    0x2cc9(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0x2d79(%rip),%rdi
lea    0xd11(%rip),%rsi
jmp    139d <rmobj+0x1fd>
mov    %r12,%rdi
call   1060 <closedir@plt>
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   1070 <lstat@plt>
test   %rax,%rax
js     137a <rmobj+0x1da>
cmpl   $0x3,-0x2c(%rbp)
jl     13ca <rmobj+0x22a>
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    13bb <rmobj+0x21b>
test   %r14,%r14
je     13b6 <rmobj+0x216>
mov    0x2c6f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0x2d1f(%rip),%rdi
lea    0xcdf(%rip),%rsi
jmp    139d <rmobj+0x1fd>
test   %r14,%r14
je     13b6 <rmobj+0x216>
mov    0x2c4a(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0x2cfa(%rip),%rdi
lea    0xc63(%rip),%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0x2cdd(%rip),%rax
mov    %rax,(%r14)
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1050 <rmdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    13bb <rmobj+0x21b>
test   %r14,%r14
je     13b6 <rmobj+0x216>
mov    0x2be8(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0x2c98(%rip),%rdi
lea    0xc78(%rip),%rsi
jmp    139d <rmobj+0x1fd>
xor    %eax,%eax
jmp    13bb <rmobj+0x21b>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32 }
@PATH_MAX = global i32 0
@rmobj.err_msg = internal global [1024 x i8] zeroinitializer
@.str = [31 x i8] c"lstat(%s) failed; errno=%d: %s\00"
@errno = global i32 0
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [16 x i8] c"Cannot remove /\00"
@.str.3 = [31 x i8] c"rmdir(%s) failed; errno=%d: %s\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [32 x i8] c"unlink(%s) failed; errno=%d: %s\00"
@.str.8 = [32 x i8] c"remove(%s) failed; errno=%d: %s\00"
define i32 @rmobj(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.stat
%12 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i8*, i8** %4
%18 = call i64 @lstat(i8* %17, %struct.stat* %11)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = icmp ne i8** %21, null
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* @errno
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25, i8* %27)
%29 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %29
br label %30
30: ; preds = %23, %20
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
31: ; preds = %2
%32 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @S_IFMT
%35 = and i32 %33, %34
%36 = load i32, i32* @S_IFDIR
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %162
38: ; preds = %31
%39 = load i8*, i8** %4
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %38
%43 = load i8**, i8*** %5
%44 = icmp ne i8** %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%47 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %47
br label %48
48: ; preds = %45, %42
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
49: ; preds = %38
%50 = load i8*, i8** %4
%51 = call i32* @opendir(i8* %50)
store i32* %51, i32** %7
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %69
53: ; preds = %49
%54 = load i8*, i8** %4
%55 = call i64 @rmdir(i8* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = load i8**, i8*** %5
%59 = icmp ne i8** %58, null
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i8*, i8** %4
%62 = load i32, i32* @errno
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %61, i32 %62, i8* %64)
%66 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %66
br label %67
67: ; preds = %60, %57
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
68: ; preds = %53
store i32 0, i32* %3
store i32 1, i32* %12
br label %179
69: ; preds = %49
%70 = load i32*, i32** %7
%71 = call i64 @readdir(i32* %70)
%72 = inttoptr i64 %71 to %struct.dirent*
store %struct.dirent* %72, %struct.dirent** %8
br label %73
73: ; preds = %100, %69
%74 = load %struct.dirent*, %struct.dirent** %8
%75 = icmp ne %struct.dirent* %74, null
br i1 %75, label %76, label %104
76: ; preds = %73
%77 = load %struct.dirent*, %struct.dirent** %8
%78 = getelementptr inbounds %struct.dirent, %struct.dirent* %77, i32 0, i32 0
%79 = load i8*, i8** %78
%80 = call i32 @strcmp(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %76
%83 = load %struct.dirent*, %struct.dirent** %8
%84 = getelementptr inbounds %struct.dirent, %struct.dirent* %83, i32 0, i32 0
%85 = load i8*, i8** %84
%86 = call i32 @strcmp(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%87 = icmp ne i32 %86, 0
br i1 %87, label %89, label %88
88: ; preds = %82, %76
br label %100
89: ; preds = %82
%90 = load i8*, i8** %4
%91 = load %struct.dirent*, %struct.dirent** %8
%92 = getelementptr inbounds %struct.dirent, %struct.dirent* %91, i32 0, i32 0
%93 = load i8*, i8** %92
%94 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %90, i8* %93)
%95 = load i8**, i8*** %5
%96 = call i32 @rmobj(i8* %16, i8** %95)
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %89
store i32 -1, i32* %6
br label %99
99: ; preds = %98, %89
br label %100
100: ; preds = %99, %88
%101 = load i32*, i32** %7
%102 = call i64 @readdir(i32* %101)
%103 = inttoptr i64 %102 to %struct.dirent*
store %struct.dirent* %103, %struct.dirent** %8
br label %73
104: ; preds = %73
%105 = load i32*, i32** %7
%106 = call i32 @closedir(i32* %105)
%107 = load i32, i32* %6
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %110
109: ; preds = %104
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
110: ; preds = %104
%111 = load i8*, i8** %4
%112 = call i64 @lstat(i8* %111, %struct.stat* %11)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %125
114: ; preds = %110
%115 = load i8**, i8*** %5
%116 = icmp ne i8** %115, null
br i1 %116, label %117, label %124
117: ; preds = %114
%118 = load i8*, i8** %4
%119 = load i32, i32* @errno
%120 = load i32, i32* @errno
%121 = call i8* @strerror(i32 %120)
%122 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %118, i32 %119, i8* %121)
%123 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %123
br label %124
124: ; preds = %117, %114
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
125: ; preds = %110
%126 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%127 = load i32, i32* %126
%128 = icmp sge i32 %127, 3
br i1 %128, label %129, label %145
129: ; preds = %125
%130 = load i8*, i8** %4
%131 = call i64 @unlink(i8* %130)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %144
133: ; preds = %129
%134 = load i8**, i8*** %5
%135 = icmp ne i8** %134, null
br i1 %135, label %136, label %143
136: ; preds = %133
%137 = load i8*, i8** %4
%138 = load i32, i32* @errno
%139 = load i32, i32* @errno
%140 = call i8* @strerror(i32 %139)
%141 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %137, i32 %138, i8* %140)
%142 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %142
br label %143
143: ; preds = %136, %133
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
144: ; preds = %129
br label %161
145: ; preds = %125
%146 = load i8*, i8** %4
%147 = call i64 @rmdir(i8* %146)
%148 = icmp slt i64 %147, 0
br i1 %148, label %149, label %160
149: ; preds = %145
%150 = load i8**, i8*** %5
%151 = icmp ne i8** %150, null
br i1 %151, label %152, label %159
152: ; preds = %149
%153 = load i8*, i8** %4
%154 = load i32, i32* @errno
%155 = load i32, i32* @errno
%156 = call i8* @strerror(i32 %155)
%157 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %153, i32 %154, i8* %156)
%158 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %158
br label %159
159: ; preds = %152, %149
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
160: ; preds = %145
br label %161
161: ; preds = %160, %144
br label %178
162: ; preds = %31
%163 = load i8*, i8** %4
%164 = call i64 @unlink(i8* %163)
%165 = icmp slt i64 %164, 0
br i1 %165, label %166, label %177
166: ; preds = %162
%167 = load i8**, i8*** %5
%168 = icmp ne i8** %167, null
br i1 %168, label %169, label %176
169: ; preds = %166
%170 = load i8*, i8** %4
%171 = load i32, i32* @errno
%172 = load i32, i32* @errno
%173 = call i8* @strerror(i32 %172)
%174 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %170, i32 %171, i8* %173)
%175 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %175
br label %176
176: ; preds = %169, %166
store i32 -1, i32* %3
store i32 1, i32* %12
br label %179
177: ; preds = %162
br label %178
178: ; preds = %177, %161
store i32 0, i32* %3
store i32 1, i32* %12
br label %179
179: ; preds = %178, %176, %159, %143, %124, %109, %68, %67, %48, %30
%180 = load i8*, i8** %9
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@rmobj.err_msg = internal global [1024 x i8] zeroinitializer
@.str = [31 x i8] c"lstat(%s) failed; errno=%d: %s\00"
@errno = global i32 0
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [16 x i8] c"Cannot remove /\00"
@.str.3 = [31 x i8] c"rmdir(%s) failed; errno=%d: %s\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [32 x i8] c"unlink(%s) failed; errno=%d: %s\00"
@.str.8 = [32 x i8] c"remove(%s) failed; errno=%d: %s\00"
define i32 @rmobj(i8* %0, i8** %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.stat* %3 to i8*
%8 = call i64 @lstat(i8* %0, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = icmp eq i8** %1, null
br i1 %11, label %110, label %12
12: ; preds = %10
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %13, i8* %14)
br label %109
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @S_IFMT
%20 = and i32 %19, %18
%21 = load i32, i32* @S_IFDIR
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %100
23: ; preds = %16
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = icmp eq i8** %1, null
br i1 %27, label %110, label %28
28: ; preds = %26
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(16) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* align 1 dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 16, i1 false)
br label %109
29: ; preds = %23
%30 = tail call i32* @opendir(i8* %0)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = tail call i64 @rmdir(i8* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %110, label %35
35: ; preds = %32
%36 = icmp eq i8** %1, null
br i1 %36, label %110, label %37
37: ; preds = %35
%38 = load i32, i32* @errno
%39 = tail call i8* @strerror(i32 %38)
%40 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %38, i8* %39)
br label %109
41: ; preds = %29
%42 = tail call i64 @readdir(i32* %30)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @closedir(i32* %30)
br label %69
46: ; preds = %41, %62
%47 = phi i32 [ %63, %62 ], [ 0, %41 ]
%48 = phi i64 [ %64, %62 ], [ %42, %41 ]
%49 = inttoptr i64 %48 to %struct.dirent*
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i64 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %46
%55 = call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%56 = icmp eq i32 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %51)
%59 = call i32 @rmobj(i8* %6, i8** %1)
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, i32 %47, i32 -1
br label %62
62: ; preds = %57, %46, %54
%63 = phi i32 [ %47, %54 ], [ %47, %46 ], [ %61, %57 ]
%64 = call i64 @readdir(i32* %30)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %46
66: ; preds = %62
%67 = call i32 @closedir(i32* %30)
%68 = icmp eq i32 %63, -1
br i1 %68, label %110, label %69
69: ; preds = %44, %66
%70 = call i64 @lstat(i8* %0, %struct.stat* %3)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %69
%73 = icmp eq i8** %1, null
br i1 %73, label %110, label %74
74: ; preds = %72
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %75, i8* %76)
br label %109
78: ; preds = %69
%79 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%80 = load i32, i32* %79
%81 = icmp sgt i32 %80, 2
br i1 %81, label %82, label %91
82: ; preds = %78
%83 = call i64 @unlink(i8* %0)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %110
85: ; preds = %82
%86 = icmp eq i8** %1, null
br i1 %86, label %110, label %87
87: ; preds = %85
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 %88, i8* %89)
br label %109
91: ; preds = %78
%92 = call i64 @rmdir(i8* %0)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %110
94: ; preds = %91
%95 = icmp eq i8** %1, null
br i1 %95, label %110, label %96
96: ; preds = %94
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %0, i32 %97, i8* %98)
br label %109
100: ; preds = %16
%101 = tail call i64 @unlink(i8* %0)
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %110
103: ; preds = %100
%104 = icmp eq i8** %1, null
br i1 %104, label %110, label %105
105: ; preds = %103
%106 = load i32, i32* @errno
%107 = tail call i8* @strerror(i32 %106)
%108 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 %106, i8* %107)
br label %109
109: ; preds = %12, %28, %37, %74, %87, %96, %105
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @rmobj.err_msg, i64 0, i64 0), i8** %1
br label %110
110: ; preds = %109, %91, %82, %100, %103, %94, %85, %72, %66, %32, %35, %26, %10
%111 = phi i32 [ -1, %10 ], [ -1, %26 ], [ -1, %35 ], [ 0, %32 ], [ -1, %66 ], [ -1, %72 ], [ -1, %85 ], [ -1, %94 ], [ -1, %103 ], [ 0, %100 ], [ 0, %82 ], [ 0, %91 ], [ -1, %109 ]
ret i32 %111
}