#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*/ buffer;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ ft_bzero(char *, int);
int /*<<< orphan*/ ft_sprintf(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ft_strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int remove(char *);
int stat(char *, struct stat *);
int ft_rm(char *name) {
  DIR *directory;
  struct dirent *entry;
  struct stat file_stat;
  char buffer[10024];
  if (stat(name, &file_stat) == -1)
    return (-1);
  if (S_ISREG(file_stat.st_mode))
    return (remove(name));
  ft_bzero(buffer, sizeof(buffer));
  if (!(directory = opendir(name)))
    return (-1);
  while ((entry = readdir(directory)) != NULL) {
    if (!ft_strcmp(entry->d_name, ".") || !ft_strcmp(entry->d_name, ".."))
      continue;
    ft_sprintf(buffer, "%s/%s", name, entry->d_name);
    stat(buffer, &file_stat);
    if (S_ISREG(file_stat.st_mode))
      remove(buffer);
    else if (S_ISDIR(file_stat.st_mode))
      ft_rm(buffer);
  }
  closedir(directory);
  return (remove(name));
}


x86 assembly (clang, -O0):
<ft_rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2750,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    11e1 <ft_rm+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <ft_rm+0x16c>
mov    -0x28(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1204 <ft_rm+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
mov    %eax,-0x4(%rbp)
jmp    131c <ft_rm+0x16c>
lea    -0x2750(%rbp),%rdi
mov    $0x2728,%esi
call   1040 <ft_bzero@plt>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1238 <ft_rm+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <ft_rm+0x16c>
jmp    123d <ft_rm+0x8d>
mov    -0x18(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1307 <ft_rm+0x157>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   10d0 <ft_strcmp@plt>
cmp    $0x0,%eax
je     128a <ft_rm+0xda>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   10d0 <ft_strcmp@plt>
cmp    $0x0,%eax
jne    128f <ft_rm+0xdf>
jmp    123d <ft_rm+0x8d>
lea    -0x2750(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xd5c(%rip),%rsi
call   10c0 <ft_sprintf@plt>
lea    -0x2750(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x28(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     12df <ft_rm+0x12f>
lea    -0x2750(%rbp),%rdi
call   1030 <remove@plt>
jmp    1302 <ft_rm+0x152>
mov    -0x28(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12fd <ft_rm+0x14d>
lea    -0x2750(%rbp),%rdi
call   10b0 <ft_rm@plt>
jmp    1302 <ft_rm+0x152>
jmp    123d <ft_rm+0x8d>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_rm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2738,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     12e7 <ft_rm+0x137>
mov    0x8(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     1203 <ft_rm+0x53>
mov    %r14,%rdi
add    $0x2738,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <remove@plt>
lea    0x10(%rsp),%rdi
mov    $0x2728,%esi
call   1040 <ft_bzero@plt>
mov    %r14,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     12e7 <ft_rm+0x137>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12d5 <ft_rm+0x125>
mov    %rax,%r13
lea    0xdc0(%rip),%r15
lea    0x10(%rsp),%r12
jmp    1268 <ft_rm+0xb8>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <remove@plt>
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     12d5 <ft_rm+0x125>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   10d0 <ft_strcmp@plt>
test   %eax,%eax
je     1258 <ft_rm+0xa8>
mov    0x0(%r13),%edi
lea    0xd7d(%rip),%rsi
call   10d0 <ft_strcmp@plt>
test   %eax,%eax
je     1258 <ft_rm+0xa8>
mov    0x0(%r13),%ecx
mov    %r12,%rdi
lea    0xd69(%rip),%rsi
mov    %r14,%rdx
call   10c0 <ft_sprintf@plt>
mov    %r12,%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
jne    1250 <ft_rm+0xa0>
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1258 <ft_rm+0xa8>
mov    %r12,%rdi
call   10b0 <ft_rm@plt>
jmp    1258 <ft_rm+0xa8>
mov    %rbx,%rdi
call   1070 <closedir@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x2738,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @ft_rm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca %struct.stat
%7 = alloca [10024 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @stat(i8* %8, %struct.stat* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %76
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISREG(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i32 @remove(i8* %18)
store i32 %19, i32* %2
br label %76
20: ; preds = %12
%21 = getelementptr inbounds [10024 x i8], [10024 x i8]* %7, i64 0, i64 0
%22 = call i32 @ft_bzero(i8* %21, i32 10024)
%23 = load i8*, i8** %3
%24 = call i32* @opendir(i8* %23)
store i32* %24, i32** %4
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 -1, i32* %2
br label %76
27: ; preds = %20
br label %28
28: ; preds = %70, %44, %27
%29 = load i32*, i32** %4
%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 %71
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 i32 @ft_strcmp(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
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 i32 @ft_strcmp(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %38, %32
br label %28
45: ; preds = %38
%46 = getelementptr inbounds [10024 x i8], [10024 x i8]* %7, i64 0, i64 0
%47 = load i8*, i8** %3
%48 = load %struct.dirent*, %struct.dirent** %5
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @ft_sprintf(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %47, i32 %50)
%52 = getelementptr inbounds [10024 x i8], [10024 x i8]* %7, i64 0, i64 0
%53 = call i32 @stat(i8* %52, %struct.stat* %6)
%54 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i64 @S_ISREG(i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %45
%59 = getelementptr inbounds [10024 x i8], [10024 x i8]* %7, i64 0, i64 0
%60 = call i32 @remove(i8* %59)
br label %70
61: ; preds = %45
%62 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i64 @S_ISDIR(i32 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = getelementptr inbounds [10024 x i8], [10024 x i8]* %7, i64 0, i64 0
%68 = call i32 @ft_rm(i8* %67)
br label %69
69: ; preds = %66, %61
br label %70
70: ; preds = %69, %58
br label %28
71: ; preds = %28
%72 = load i32*, i32** %4
%73 = call i32 @closedir(i32* %72)
%74 = load i8*, i8** %3
%75 = call i32 @remove(i8* %74)
store i32 %75, i32* %2
br label %76
76: ; preds = %71, %26, %17, %11
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @ft_rm(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca [10024 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [10024 x i8], [10024 x i8]* %3, i64 0, i64 0
%6 = call i32 @stat(i8* %0, %struct.stat* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %52, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @S_ISREG(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @remove(i8* %0)
br label %52
15: ; preds = %8
%16 = call i32 @ft_bzero(i8* %5, i32 10024)
%17 = call i32* @opendir(i8* %0)
%18 = icmp eq i32* %17, null
br i1 %18, label %52, label %19
19: ; preds = %15
%20 = call %struct.dirent* @readdir(i32* %17)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %49, label %22
22: ; preds = %19, %32
%23 = phi %struct.dirent* [ %33, %32 ], [ %20, %19 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @ft_strcmp(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = load i32, i32* %24
%30 = call i32 @ft_strcmp(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %42, %47, %44, %22, %28
%33 = call %struct.dirent* @readdir(i32* %17)
%34 = icmp eq %struct.dirent* %33, null
br i1 %34, label %49, label %22
35: ; preds = %28
%36 = load i32, i32* %24
%37 = call i32 @ft_sprintf(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %36)
%38 = call i32 @stat(i8* %5, %struct.stat* %2)
%39 = load i32, i32* %9
%40 = call i64 @S_ISREG(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %35
%43 = call i32 @remove(i8* %5)
br label %32
44: ; preds = %35
%45 = call i64 @S_ISDIR(i32 %39)
%46 = icmp eq i64 %45, 0
br i1 %46, label %32, label %47
47: ; preds = %44
%48 = call i32 @ft_rm(i8* %5)
br label %32
49: ; preds = %32, %19
%50 = call i32 @closedir(i32* %17)
%51 = call i32 @remove(i8* %0)
br label %52
52: ; preds = %15, %1, %49, %13
%53 = phi i32 [ %14, %13 ], [ %51, %49 ], [ -1, %1 ], [ -1, %15 ]
ret i32 %53
}