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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
scalar_t__ strcmp(char *, char *);
int removeAllFileOfDirectory(char const *directory) {
  DIR *theFolder = opendir(directory);
  struct dirent *next_file;
  char filepath[256];
  while ((next_file = readdir(theFolder)) != NULL) {
    if (strcmp(next_file->d_name, ".") == 0 ||
        strcmp(next_file->d_name, "..") == 0) {
      continue;
    }
    sprintf(filepath, "%s/%s", directory, next_file->d_name);
    int ret = remove(filepath);
    if (ret != 0) {
      return 0;
    }
  }
  closedir(theFolder);
  return 1;
}


x86 assembly (clang, -O0):
<removeAllFileOfDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1220 <removeAllFileOfDirectory+0xc0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11cd <removeAllFileOfDirectory+0x6d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d2 <removeAllFileOfDirectory+0x72>
jmp    117c <removeAllFileOfDirectory+0x1c>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xe18(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <remove@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     121b <removeAllFileOfDirectory+0xbb>
movl   $0x0,-0x4(%rbp)
jmp    1230 <removeAllFileOfDirectory+0xd0>
jmp    117c <removeAllFileOfDirectory+0x1c>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeAllFileOfDirectory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11f8 <removeAllFileOfDirectory+0x98>
mov    %rax,%r13
lea    0xe6e(%rip),%r15
lea    0xe66(%rip),%r12
mov    %rsp,%rbp
jmp    11b0 <removeAllFileOfDirectory+0x50>
nop
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     11f8 <removeAllFileOfDirectory+0x98>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <removeAllFileOfDirectory+0x40>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <removeAllFileOfDirectory+0x40>
mov    0x0(%r13),%rcx
mov    %rbp,%rdi
lea    0xe23(%rip),%rsi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <remove@plt>
test   %eax,%eax
je     11a0 <removeAllFileOfDirectory+0x40>
xor    %eax,%eax
jmp    1205 <removeAllFileOfDirectory+0xa5>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @removeAllFileOfDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %4
br label %10
10: ; preds = %39, %26, %1
%11 = load i32*, i32** %4
%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 %40
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 i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
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 i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20, %14
br label %10
27: ; preds = %20
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, 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 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = call i32 @remove(i8* %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %27
store i32 0, i32* %2
br label %43
39: ; preds = %27
br label %10
40: ; preds = %10
%41 = load i32*, i32** %4
%42 = call i32 @closedir(i32* %41)
store i32 1, i32* %2
br label %43
43: ; preds = %40, %38
%44 = load i32, i32* %2
ret i32 %44
}

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