#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*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int delete_directory(char *dir_to_del) {
  int status = 0;
  struct dirent *d = NULL;
  DIR *dir = NULL;
  char buf[256];
  if ((dir_to_del == NULL) || (*dir_to_del == '\0')) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 454,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/DEPRECATED_Q2/AUX/auxil.c");
      };
      status = -1;
      goto BYE;
    };
  }
  dir = opendir(dir_to_del);
  if (dir == NULL) {
    return status;
  }
  for (;;) {
    d = readdir(dir);
    if (d == NULL) {
      break;
    }
    if (strcmp(d->d_name, ".") == 0) {
      continue;
    }
    if (strcmp(d->d_name, "..") == 0) {
      continue;
    }
    sprintf(buf, "%s/%s", dir_to_del, d->d_name);
    remove(buf);
  }
  closedir(dir);
  remove(dir_to_del);
BYE:
  return status;
}


x86 assembly (clang, -O0):
<delete_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b1 <delete_directory+0x41>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11de <delete_directory+0x6e>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x1c6,%edx
lea    0xe49(%rip),%rcx
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    12a8 <delete_directory+0x138>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1201 <delete_directory+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ae <delete_directory+0x13e>
jmp    1206 <delete_directory+0x96>
mov    -0x28(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1223 <delete_directory+0xb3>
jmp    1296 <delete_directory+0x126>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1245 <delete_directory+0xd5>
jmp    1206 <delete_directory+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe59(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1267 <delete_directory+0xf7>
jmp    1206 <delete_directory+0x96>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xe2f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   1030 <remove@plt>
jmp    1206 <delete_directory+0x96>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
test   %rdi,%rdi
je     122f <delete_directory+0xbf>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     122f <delete_directory+0xbf>
mov    %rbx,%rdi
call   1040 <opendir@plt>
mov    %rax,%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     1269 <delete_directory+0xf9>
mov    %rbp,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1257 <delete_directory+0xe7>
mov    %rax,%r14
lea    0xee6(%rip),%r15
lea    0xede(%rip),%r12
mov    %rsp,%r13
jmp    11f0 <delete_directory+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     1257 <delete_directory+0xe7>
mov    (%r14),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e0 <delete_directory+0x70>
mov    (%r14),%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e0 <delete_directory+0x70>
mov    (%r14),%rcx
mov    %r13,%rdi
lea    0xe92(%rip),%rsi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
mov    %r13,%rdi
call   1030 <remove@plt>
jmp    11e0 <delete_directory+0x70>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
lea    0xdd0(%rip),%rcx
mov    $0x1c6,%edx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1269 <delete_directory+0xf9>
mov    %rbp,%rdi
call   1050 <closedir@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/DEPRECATED_Q2/AUX/auxil.c\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @delete_directory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
store %struct.dirent* null, %struct.dirent** %5
store i32* null, i32** %6
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10, %1
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 454, i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %60
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = call i32* @opendir(i8* %19)
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %62
25: ; preds = %18
br label %26
26: ; preds = %46, %45, %38, %25
%27 = load i32*, i32** %6
%28 = call %struct.dirent* @readdir(i32* %27)
store %struct.dirent* %28, %struct.dirent** %5
%29 = load %struct.dirent*, %struct.dirent** %5
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %31, label %32
31: ; preds = %26
br label %55
32: ; preds = %26
%33 = load %struct.dirent*, %struct.dirent** %5
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
br label %26
39: ; preds = %32
%40 = load %struct.dirent*, %struct.dirent** %5
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
br label %26
46: ; preds = %39
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%48 = load i8*, i8** %3
%49 = load %struct.dirent*, %struct.dirent** %5
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %48, i8* %51)
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = call i32 @remove(i8* %53)
br label %26
55: ; preds = %31
%56 = load i32*, i32** %6
%57 = call i32 @closedir(i32* %56)
%58 = load i8*, i8** %3
%59 = call i32 @remove(i8* %58)
br label %60
60: ; preds = %55, %15
%61 = load i32, i32* %4
store i32 %61, i32* %2
br label %62
62: ; preds = %60, %23
%63 = load i32, i32* %2
ret i32 %63
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/DEPRECATED_Q2/AUX/auxil.c\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @delete_directory(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 454, i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str.1, i64 0, i64 0))
br label %37
11: ; preds = %5
%12 = tail call i32* @opendir(i8* %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %37, label %14
14: ; preds = %11
%15 = tail call %struct.dirent* @readdir(i32* %12)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %34, label %17
17: ; preds = %14, %31
%18 = phi %struct.dirent* [ %32, %31 ], [ %15, %14 ]
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %17
%24 = load i8*, i8** %19
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8*, i8** %19
%29 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %28)
%30 = call i32 @remove(i8* %3)
br label %31
31: ; preds = %27, %17, %23
%32 = tail call %struct.dirent* @readdir(i32* %12)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %34, label %17
34: ; preds = %31, %14
%35 = tail call i32 @closedir(i32* %12)
%36 = tail call i32 @remove(i8* %0)
br label %37
37: ; preds = %8, %34, %11
%38 = phi i32 [ 0, %11 ], [ -1, %8 ], [ 0, %34 ]
ret i32 %38
}