// File: williewillus[P]panda_scratchpad/src/checker/DiskContents.cpp
// Function: DiskContents::compare_file_contents(DiskContents&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int, std::basic_ofstream<char, std::char_traits<char>>&)
bool DiskContents::compare_file_contents(DiskContents &compare_disk, string path,
    int offset, int length, ofstream &diff_file) {
  bool retValue = true;
  if (disk_path.compare(compare_disk.disk_path) == 0) {
    return retValue;
  }

  string base_path = "/mnt/pmem0" + path;
  /*if (compare_disk.mount_disk() != 0) {
    cout << "Mounting " << compare_disk.disk_path << " failed" << endl;
    return false;
  }*/
  string compare_disk_mount_point(compare_disk.get_mount_point());
  string compare_path = compare_disk_mount_point + path;

  fileAttributes base_fa, compare_fa;
  bool failed_stat = false;
  struct stat base_statbuf, compare_statbuf;
  if (stat(base_path.c_str(), &base_statbuf) == -1) {
    diff_file << "Failed stating the file " << base_path << endl;
    failed_stat = true;
  }
  if (stat(compare_path.c_str(), &compare_statbuf) == -1) {
    diff_file << "Failed stating the file " << compare_path << endl;
    failed_stat = true;
  }

  if (failed_stat) {
    //compare_disk.unmount_and_delete_mount_point();
    return false;
  }

  std::ifstream f1(base_path, std::ios::binary);
  std::ifstream f2(compare_path, std::ios::binary);

  if (!f1 || !f2) {
    cout << "Error opening input file streams " << base_path  << " and ";
    cout << compare_path << endl;
    //compare_disk.unmount_and_delete_mount_point();
    return false;
  }

  f1.seekg(offset, std::ifstream::beg);
  f2.seekg(offset, std::ifstream::beg);

  char * buffer_f1 = new char[length + 1];
  char * buffer_f2 = new char[length + 1];

  f1.read(buffer_f1, length);
  f2.read(buffer_f2, length);
  f1.close();
  f2.close();

  buffer_f1[length] = '\0';
  buffer_f2[length] = '\0';

  if (strcmp(buffer_f1, buffer_f2) == 0) {
    //compare_disk.unmount_and_delete_mount_point();
    return true;
  }

  diff_file << __func__ << " failed" << endl;
  diff_file << "Content Mismatch of file " << path << " from ";
  diff_file << offset << " of length " << length << endl;
  diff_file << base_path << " has " << buffer_f1 << endl;
  diff_file << compare_path << " has " << buffer_f2 << endl;
  //compare_disk.unmount_and_delete_mount_point();
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa50, %rsp            # imm = 0xA50
movq %rdx, -0x990(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movb $0x1, -0x31(%rbp)
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
callq 0x6050
cmpl $0x0, %eax
jne 0x211f4
movb -0x31(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x2188a
movq -0x990(%rbp), %rdx
leaq 0x41a1(%rip), %rsi      # 0x253a3
leaq -0x58(%rbp), %rdi
callq 0x18c40
movq -0x18(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x1ff50
jmp 0x2121a
movq -0x990(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x22a00
jmp 0x21233
leaq -0x270(%rbp), %rdi
callq 0x1ed20
jmp 0x21241
leaq -0x438(%rbp), %rdi
callq 0x1ed20
jmp 0x2124f
movb $0x0, -0x439(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x64b0
cmpl $-0x1, %eax
jne 0x2132b
movq -0x30(%rbp), %rdi
leaq 0x463f(%rip), %rsi      # 0x258c1
callq 0x6520
movq %rax, -0x998(%rbp)
jmp 0x21290
movq -0x998(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x64a0
movq %rax, -0x9a0(%rbp)
jmp 0x212a9
movq -0x9a0(%rbp), %rdi
movq 0x13ce1(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x212be
movb $0x1, -0x439(%rbp)
jmp 0x2132b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2187f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x21876
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2186a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2185e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x21852
leaq -0xa8(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
leaq -0x560(%rbp), %rsi
callq 0x64b0
cmpl $-0x1, %eax
jne 0x2139c
movq -0x30(%rbp), %rdi
leaq 0x456b(%rip), %rsi      # 0x258c1
callq 0x6520
movq %rax, -0x9a8(%rbp)
jmp 0x21364
movq -0x9a8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x64a0
movq %rax, -0x9b0(%rbp)
jmp 0x21380
movq -0x9b0(%rbp), %rdi
movq 0x13c0a(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x21395
movb $0x1, -0x439(%rbp)
testb $0x1, -0x439(%rbp)
je 0x213b8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x564(%rbp)
jmp 0x2181a
leaq -0x770(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x4, %edx
callq 0x67f0
jmp 0x213cf
leaq -0x978(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
callq 0x67f0
jmp 0x213e9
movq -0x770(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x770(%rbp,%rax), %rdi
callq 0x6270
movb %al, -0x9b1(%rbp)
jmp 0x21409
movb -0x9b1(%rbp), %al
testb $0x1, %al
jne 0x21444
jmp 0x21415
movq -0x978(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x978(%rbp,%rax), %rdi
callq 0x6270
movb %al, -0x9b2(%rbp)
jmp 0x21435
movb -0x9b2(%rbp), %al
testb $0x1, %al
jne 0x21444
jmp 0x21506
movq 0x13b75(%rip), %rdi     # 0x34fc0
leaq 0x4488(%rip), %rsi      # 0x258da
callq 0x6520
movq %rax, -0x9c0(%rbp)
jmp 0x21460
movq -0x9c0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x64a0
movq %rax, -0x9c8(%rbp)
jmp 0x21479
movq -0x9c8(%rbp), %rdi
leaq 0x4475(%rip), %rsi      # 0x258fc
callq 0x6520
jmp 0x2148e
movq 0x13b2b(%rip), %rdi     # 0x34fc0
leaq -0xa8(%rbp), %rsi
callq 0x64a0
movq %rax, -0x9d0(%rbp)
jmp 0x214aa
movq -0x9d0(%rbp), %rdi
movq 0x13ae0(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x214bf
movb $0x0, -0x1(%rbp)
movl $0x1, -0x564(%rbp)
jmp 0x217f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2180c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x978(%rbp), %rdi
callq 0x6140
jmp 0x2180c
movslq -0x24(%rbp), %rsi
leaq -0x770(%rbp), %rdi
xorl %edx, %edx
callq 0x6650
jmp 0x2151a
movslq -0x24(%rbp), %rsi
leaq -0x978(%rbp), %rdi
xorl %edx, %edx
callq 0x6650
jmp 0x2152e
movl -0x28(%rbp), %eax
incl %eax
movslq %eax, %rdi
testq %rdi, %rdi
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x6030
movq %rax, -0x9d8(%rbp)
jmp 0x21552
movq -0x9d8(%rbp), %rax
movq %rax, -0x980(%rbp)
movl -0x28(%rbp), %eax
incl %eax
movslq %eax, %rdi
testq %rdi, %rdi
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x6030
movq %rax, -0x9e0(%rbp)
jmp 0x21584
movq -0x9e0(%rbp), %rax
movq %rax, -0x988(%rbp)
movq -0x980(%rbp), %rsi
movslq -0x28(%rbp), %rdx
leaq -0x770(%rbp), %rdi
callq 0x65d0
jmp 0x215ab
movq -0x988(%rbp), %rsi
movslq -0x28(%rbp), %rdx
leaq -0x978(%rbp), %rdi
callq 0x65d0
jmp 0x215c4
leaq -0x770(%rbp), %rdi
callq 0x60d0
jmp 0x215d2
leaq -0x978(%rbp), %rdi
callq 0x60d0
jmp 0x215e0
movq -0x980(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x988(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x980(%rbp), %rdi
movq -0x988(%rbp), %rsi
callq 0x66b0
cmpl $0x0, %eax
jne 0x21629
movb $0x1, -0x1(%rbp)
movl $0x1, -0x564(%rbp)
jmp 0x217f2
movq -0x30(%rbp), %rdi
leaq 0x42ce(%rip), %rsi      # 0x25902
callq 0x6520
movq %rax, -0x9e8(%rbp)
jmp 0x21642
movq -0x9e8(%rbp), %rdi
leaq 0x41cf(%rip), %rsi      # 0x2581f
callq 0x6520
movq %rax, -0x9f0(%rbp)
jmp 0x2165e
movq -0x9f0(%rbp), %rdi
movq 0x1392c(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x21673
movq -0x30(%rbp), %rdi
leaq 0x429a(%rip), %rsi      # 0x25918
callq 0x6520
movq %rax, -0x9f8(%rbp)
jmp 0x2168c
movq -0x990(%rbp), %rsi
movq -0x9f8(%rbp), %rdi
callq 0x64a0
movq %rax, -0xa00(%rbp)
jmp 0x216a8
movq -0xa00(%rbp), %rdi
leaq 0x427c(%rip), %rsi      # 0x25932
callq 0x6520
jmp 0x216bd
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x6890
movq %rax, -0xa08(%rbp)
jmp 0x216d2
movq -0xa08(%rbp), %rdi
leaq 0x4259(%rip), %rsi      # 0x25939
callq 0x6520
movq %rax, -0xa10(%rbp)
jmp 0x216ee
movq -0xa10(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x6890
movq %rax, -0xa18(%rbp)
jmp 0x21706
movq -0xa18(%rbp), %rdi
movq 0x13884(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x2171b
movq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x64a0
movq %rax, -0xa20(%rbp)
jmp 0x21731
movq -0xa20(%rbp), %rdi
leaq 0x4206(%rip), %rsi      # 0x25945
callq 0x6520
movq %rax, -0xa28(%rbp)
jmp 0x2174d
movq -0xa28(%rbp), %rdi
movq -0x980(%rbp), %rsi
callq 0x6520
movq %rax, -0xa30(%rbp)
jmp 0x21769
movq -0xa30(%rbp), %rdi
movq 0x13821(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x2177e
movq -0x30(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x64a0
movq %rax, -0xa38(%rbp)
jmp 0x21797
movq -0xa38(%rbp), %rdi
leaq 0x41a0(%rip), %rsi      # 0x25945
callq 0x6520
movq %rax, -0xa40(%rbp)
jmp 0x217b3
movq -0xa40(%rbp), %rdi
movq -0x988(%rbp), %rsi
callq 0x6520
movq %rax, -0xa48(%rbp)
jmp 0x217cf
movq -0xa48(%rbp), %rdi
movq 0x137bb(%rip), %rsi     # 0x34f98
callq 0x6580
jmp 0x217e4
movb $0x0, -0x1(%rbp)
movl $0x1, -0x564(%rbp)
leaq -0x978(%rbp), %rdi
callq 0x6140
leaq -0x770(%rbp), %rdi
callq 0x6140
jmp 0x2181a
leaq -0x770(%rbp), %rdi
callq 0x6140
jmp 0x21852
leaq -0x438(%rbp), %rdi
callq 0x1edf0
leaq -0x270(%rbp), %rdi
callq 0x1edf0
leaq -0xa8(%rbp), %rdi
callq 0x69d8
leaq -0x78(%rbp), %rdi
callq 0x69d8
leaq -0x58(%rbp), %rdi
callq 0x69d8
jmp 0x2188a
leaq -0x438(%rbp), %rdi
callq 0x1edf0
leaq -0x270(%rbp), %rdi
callq 0x1edf0
leaq -0xa8(%rbp), %rdi
callq 0x69d8
leaq -0x78(%rbp), %rdi
callq 0x69d8
leaq -0x58(%rbp), %rdi
callq 0x69d8
jmp 0x21898
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa50, %rsp            # imm = 0xA50
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x68a0
nopw %cs:(%rax,%rax)