// File: williewillus[P]panda_scratchpad/src/checker/DiskContents.cpp
// Function: DiskContents::deleteFiles(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_ofstream<char, std::char_traits<char>>&)
bool DiskContents::deleteFiles(string path, ofstream &diff_file) {
  if (path.empty()) {
    return true;
  }

  if (isEmptyDirOrFile(path) == true) {
    if (path.compare("/mnt/pmem0") == 0) {
      return true;
    }
    if (isFile(path) == true) {
      return (unlink(path.c_str()) == 0);
    } else {
      return (rmdir(path.c_str()) == 0);
    }
  }

  DIR *directory = opendir(path.c_str());
  if (directory == NULL) {
    cout << "Couldn't open the directory " << path << endl;
    diff_file << "Couldn't open the directory " << path << endl;
    return false;
  }

  struct dirent *dir_entry;
  while (dir_entry = readdir(directory)) {
    if ((strcmp(dir_entry->d_name, ".") == 0) ||
        (strcmp(dir_entry->d_name, "..") == 0)) {
      continue;
    }

    string subpath = path + "/" + string(dir_entry->d_name);
    bool subpathIsFile = isFile(subpath);
    bool res = deleteFiles(subpath, diff_file);
    if (!res) {
      closedir(directory);
      diff_file << "Couldn't remove directory " << subpath << " " << strerror(errno) << endl;
      cout << "Couldn't remove directory " << subpath << " " << strerror(errno) << endl;
      return res;
    }

    if (!subpathIsFile) {
      if (rmdir(subpath.c_str()) < 0) {
        diff_file << "Couldn't remove directory " << subpath << " "  << strerror(errno) << endl;
        cout << "Couldn't remove directory " << subpath << " " << strerror(errno) << endl;
        return false;
      }
    }
  }
  closedir(directory);
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rsi, -0x150(%rbp)
movq %rdi, %rax
movq -0x150(%rbp), %rdi
movq %rdi, -0x148(%rbp)
movq %rax, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
callq 0x6830
testb $0x1, %al
jne 0x21a15
jmp 0x21a1e
movb $0x1, -0x1(%rbp)
jmp 0x220ca
movq -0x148(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x6240
movq -0x160(%rbp), %rdi
callq 0x218b0
movb %al, -0x151(%rbp)
jmp 0x21a49
movb -0x151(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x164(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x69d8
movl -0x164(%rbp), %eax
cmpl $0x1, %eax
jne 0x21b5f
movq -0x148(%rbp), %rdi
leaq 0x3923(%rip), %rsi      # 0x253a3
callq 0x6170
cmpl $0x0, %eax
jne 0x21aad
movb $0x1, -0x1(%rbp)
jmp 0x220ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x69d8
jmp 0x220d8
movq -0x148(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x6240
movq -0x170(%rbp), %rdi
callq 0x21930
movb %al, -0x165(%rbp)
jmp 0x21ad8
movb -0x165(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x174(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x69d8
movl -0x174(%rbp), %eax
cmpl $0x1, %eax
jne 0x21b3b
movq -0x148(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
callq 0x62a0
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x220ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x69d8
jmp 0x220d8
movq -0x148(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
callq 0x6230
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x220ca
movq -0x148(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
callq 0x6750
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x21be6
movq 0x1343b(%rip), %rdi     # 0x34fc0
leaq 0x3dd8(%rip), %rsi      # 0x25964
callq 0x6520
movq -0x148(%rbp), %rsi
movq %rax, %rdi
callq 0x64a0
movq %rax, %rdi
movq 0x133ee(%rip), %rsi     # 0x34f98
callq 0x6580
movq -0x20(%rbp), %rdi
leaq 0x3daa(%rip), %rsi      # 0x25964
callq 0x6520
movq -0x148(%rbp), %rsi
movq %rax, %rdi
callq 0x64a0
movq %rax, %rdi
movq 0x133c0(%rip), %rsi     # 0x34f98
callq 0x6580
movb $0x0, -0x1(%rbp)
jmp 0x220ca
jmp 0x21be8
movq -0x78(%rbp), %rdi
callq 0x6780
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x220bd
movq -0x80(%rbp), %rdi
addq $0x13, %rdi
leaq 0x3c22(%rip), %rsi      # 0x25830
callq 0x66b0
cmpl $0x0, %eax
je 0x21c31
movq -0x80(%rbp), %rdi
addq $0x13, %rdi
leaq 0x3c08(%rip), %rsi      # 0x2582f
callq 0x66b0
cmpl $0x0, %eax
jne 0x21c33
jmp 0x21be8
movq -0x148(%rbp), %rsi
leaq 0x3bc9(%rip), %rdx      # 0x2580a
leaq -0xc0(%rbp), %rdi
callq 0x226a0
movq -0x80(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x188(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x68b0
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x6670
jmp 0x21c8b
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x1c340
jmp 0x21ca7
leaq -0xe0(%rbp), %rdi
callq 0x69d8
leaq -0xe1(%rbp), %rdi
callq 0x6590
leaq -0xc0(%rbp), %rdi
callq 0x69d8
leaq -0x108(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6240
jmp 0x21ce0
leaq -0x108(%rbp), %rdi
callq 0x21930
movb %al, -0x189(%rbp)
jmp 0x21cf4
leaq -0x108(%rbp), %rdi
callq 0x69d8
movb -0x189(%rbp), %al
andb $0x1, %al
movb %al, -0xe2(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6240
jmp 0x21d23
movq -0x140(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq -0x130(%rbp), %rsi
callq 0x219d0
movb %al, -0x18a(%rbp)
jmp 0x21d42
leaq -0x130(%rbp), %rdi
callq 0x69d8
movb -0x18a(%rbp), %al
andb $0x1, %al
movb %al, -0x109(%rbp)
testb $0x1, -0x109(%rbp)
jne 0x21f33
movq -0x78(%rbp), %rdi
callq 0x67e0
jmp 0x21d74
movq -0x20(%rbp), %rdi
leaq 0x3c02(%rip), %rsi      # 0x25981
callq 0x6520
movq %rax, -0x198(%rbp)
jmp 0x21d8d
movq -0x198(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x64a0
movq %rax, -0x1a0(%rbp)
jmp 0x21da9
movq -0x1a0(%rbp), %rdi
leaq 0x3aa0(%rip), %rsi      # 0x25857
callq 0x6520
movq %rax, -0x1a8(%rbp)
jmp 0x21dc5
callq 0x6070
movl (%rax), %edi
callq 0x61b0
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0x6520
movq %rax, -0x1b0(%rbp)
jmp 0x21de9
movq -0x1b0(%rbp), %rdi
movq 0x131a1(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x21dfe
movq 0x131bb(%rip), %rdi     # 0x34fc0
leaq 0x3b75(%rip), %rsi      # 0x25981
callq 0x6520
movq %rax, -0x1b8(%rbp)
jmp 0x21e1a
movq -0x1b8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x64a0
movq %rax, -0x1c0(%rbp)
jmp 0x21e36
movq -0x1c0(%rbp), %rdi
leaq 0x3a13(%rip), %rsi      # 0x25857
callq 0x6520
movq %rax, -0x1c8(%rbp)
jmp 0x21e52
callq 0x6070
movl (%rax), %edi
callq 0x61b0
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x6520
movq %rax, -0x1d0(%rbp)
jmp 0x21e76
movq -0x1d0(%rbp), %rdi
movq 0x13114(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x21e8b
movb -0x109(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x134(%rbp)
jmp 0x22090
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x21ecb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x69d8
leaq -0xe1(%rbp), %rdi
callq 0x6590
leaq -0xc0(%rbp), %rdi
callq 0x69d8
jmp 0x220d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x220af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x69d8
jmp 0x220af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x69d8
jmp 0x220af
testb $0x1, -0xe2(%rbp)
jne 0x22086
leaq -0xa0(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
callq 0x6230
cmpl $0x0, %eax
jge 0x22084
movq -0x20(%rbp), %rdi
leaq 0x3a19(%rip), %rsi      # 0x25981
callq 0x6520
movq %rax, -0x1d8(%rbp)
jmp 0x21f76
movq -0x1d8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x64a0
movq %rax, -0x1e0(%rbp)
jmp 0x21f92
movq -0x1e0(%rbp), %rdi
leaq 0x38b7(%rip), %rsi      # 0x25857
callq 0x6520
movq %rax, -0x1e8(%rbp)
jmp 0x21fae
callq 0x6070
movl (%rax), %edi
callq 0x61b0
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x6520
movq %rax, -0x1f0(%rbp)
jmp 0x21fd2
movq -0x1f0(%rbp), %rdi
movq 0x12fb8(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x21fe7
movq 0x12fd2(%rip), %rdi     # 0x34fc0
leaq 0x398c(%rip), %rsi      # 0x25981
callq 0x6520
movq %rax, -0x1f8(%rbp)
jmp 0x22003
movq -0x1f8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x64a0
movq %rax, -0x200(%rbp)
jmp 0x2201f
movq -0x200(%rbp), %rdi
leaq 0x382a(%rip), %rsi      # 0x25857
callq 0x6520
movq %rax, -0x208(%rbp)
jmp 0x2203b
callq 0x6070
movl (%rax), %edi
callq 0x61b0
movq -0x208(%rbp), %rdi
movq %rax, %rsi
callq 0x6520
movq %rax, -0x210(%rbp)
jmp 0x2205f
movq -0x210(%rbp), %rdi
movq 0x12f2b(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x22074
movb $0x0, -0x1(%rbp)
movl $0x1, -0x134(%rbp)
jmp 0x22090
jmp 0x22086
movl $0x0, -0x134(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x69d8
movl -0x134(%rbp), %eax
testl %eax, %eax
je 0x220aa
jmp 0x220a8
jmp 0x220ca
jmp 0x21be8
leaq -0xa0(%rbp), %rdi
callq 0x69d8
jmp 0x220d8
movq -0x78(%rbp), %rdi
callq 0x67e0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x68a0
nopw %cs:(%rax,%rax)