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

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rmdir(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ unlink(char *);
void rmtempdir(char *path, int rm_dir) {
  struct dirent *ent;
  DIR *dir = opendir(path);
  while ((ent = readdir(dir))) {
    char child[1024];
    if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
      continue;
    sprintf(child, "%s/%s", path, ent->d_name);
    if (ent->d_type == DT_DIR)
      rmtempdir(child, 1);
    else
      unlink(child);
  }
  closedir(dir);
  if (rm_dir)
    rmdir(path);
}


x86 assembly (clang, -O0):
<rmtempdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1250 <rmtempdir+0xd0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     11ee <rmtempdir+0x6e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe20(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11f3 <rmtempdir+0x73>
jmp    119f <rmtempdir+0x1f>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdf7(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    123f <rmtempdir+0xbf>
lea    -0x420(%rbp),%rdi
mov    $0x1,%esi
call   1080 <rmtempdir@plt>
jmp    124b <rmtempdir+0xcb>
lea    -0x420(%rbp),%rdi
call   1030 <unlink@plt>
jmp    119f <rmtempdir+0x1f>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
cmpl   $0x0,-0xc(%rbp)
je     126c <rmtempdir+0xec>
mov    -0x8(%rbp),%rdi
call   1050 <rmdir@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmtempdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,%r15
call   1040 <opendir@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     123a <rmtempdir+0xba>
mov    %rax,%r13
lea    0xe46(%rip),%rbx
lea    0x10(%rsp),%r14
jmp    11e0 <rmtempdir+0x60>
mov    %r14,%rdi
call   1030 <unlink@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     123a <rmtempdir+0xba>
mov    0x0(%r13),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11d0 <rmtempdir+0x50>
mov    %r12,%rdi
lea    0xe03(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11d0 <rmtempdir+0x50>
mov    %r14,%rdi
lea    0xdf3(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   10a0 <sprintf@plt>
mov    0x8(%r13),%rax
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%rax
jne    11c2 <rmtempdir+0x42>
mov    %r14,%rdi
mov    $0x1,%esi
call   1080 <rmtempdir@plt>
jmp    11d0 <rmtempdir+0x50>
mov    %rbp,%rdi
call   1060 <closedir@plt>
cmpl   $0x0,0xc(%rsp)
je     1251 <rmtempdir+0xd1>
mov    %r15,%rdi
call   1050 <rmdir@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i64 0
define void @rmtempdir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %6
br label %10
10: ; preds = %44, %26, %2
%11 = load i32*, i32** %6
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %5
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %5
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load %struct.dirent*, %struct.dirent** %5
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20, %14
br label %10
27: ; preds = %20
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = load i8*, i8** %3
%30 = load %struct.dirent*, %struct.dirent** %5
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %32)
%34 = load %struct.dirent*, %struct.dirent** %5
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = load i64, i64* @DT_DIR
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
br label %44
41: ; preds = %27
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = call i32 @unlink(i8* %42)
br label %44
44: ; preds = %41, %39
br label %10
45: ; preds = %10
%46 = load i32*, i32** %6
%47 = call i32 @closedir(i32* %46)
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i8*, i8** %3
%52 = call i32 @rmdir(i8* %51)
br label %53
53: ; preds = %50, %45
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i64 0
define void @rmtempdir(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32* @opendir(i8* %0)
%5 = call %struct.dirent* @readdir(i32* %4)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %30, label %7
7: ; preds = %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %7, %27
%10 = phi %struct.dirent* [ %5, %7 ], [ %28, %27 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %9
%16 = call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %15
%19 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %12)
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 1
%21 = load i64, i64* %20
%22 = load i64, i64* @DT_DIR
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
br label %27
25: ; preds = %18
%26 = call i32 @unlink(i8* %8)
br label %27
27: ; preds = %24, %25, %9, %15
%28 = call %struct.dirent* @readdir(i32* %4)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %9
30: ; preds = %27, %2
%31 = call i32 @closedir(i32* %4)
%32 = icmp eq i32 %1, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @rmdir(i8* %0)
br label %35
35: ; preds = %33, %30
ret void
}