// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x938, %rsp            # imm = 0x938
movq %r9, %rbx
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r13
addq $0x8, %rdi
addq $0x8, %rsi
callq 0x5040
testl %eax, %eax
je 0xf747
leaq 0x2bc9(%rip), %rsi      # 0x121b2
leaq -0x78(%rbp), %rdi
movq %r12, %rdx
callq 0xbd84
addq $0x28, %r13
leaq -0x98(%rbp), %rdi
movq %r13, %rsi
callq 0x5580
leaq -0x58(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movq %r12, %rdx
callq 0x1026b
leaq -0x958(%rbp), %rdi
callq 0xe0e0
leaq -0x790(%rbp), %rdi
callq 0xe0e0
movq -0x78(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0x5420
movl %eax, %r13d
cmpl $-0x1, %eax
jne 0xf66e
leaq 0x307c(%rip), %rsi      # 0x126ce
movq %rbx, %rdi
callq 0x5480
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x5410
movq %rax, %rdi
callq 0x5240
movq -0x58(%rbp), %rdi
leaq -0x538(%rbp), %rsi
callq 0x5420
cmpl $-0x1, %eax
je 0xf74b
cmpl $-0x1, %r13d
je 0xf76e
leaq -0x4a8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x56e0
leaq -0x2a0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x56e0
movq -0x4a8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x488(%rbp,%rax)
jne 0xf6e5
movq -0x2a0(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x280(%rbp,%rax)
je 0xf7ba
movq 0xa8d4(%rip), %rdi      # 0x19fc0
leaq 0x2ff4(%rip), %rsi      # 0x126e7
callq 0x5480
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x5410
leaq 0x2ffe(%rip), %rsi      # 0x12709
movq %rax, %rdi
callq 0x5480
movq 0xa8a6(%rip), %rdi      # 0x19fc0
leaq -0x58(%rbp), %rsi
callq 0x5410
movq %rax, %rdi
callq 0x5240
xorl %ebx, %ebx
leaq -0x2a0(%rbp), %rdi
callq 0x5110
leaq -0x4a8(%rbp), %rdi
callq 0x5110
jmp 0xf770
movb $0x1, %bl
jmp 0xf7a6
leaq 0x2f7c(%rip), %rsi      # 0x126ce
movq %rbx, %rdi
callq 0x5480
leaq -0x58(%rbp), %rsi
movq %rax, %rdi
callq 0x5410
movq %rax, %rdi
callq 0x5240
xorl %ebx, %ebx
leaq -0x790(%rbp), %rdi
callq 0xe164
leaq -0x958(%rbp), %rdi
callq 0xe164
leaq -0x58(%rbp), %rdi
callq 0x58a8
leaq -0x98(%rbp), %rdi
callq 0x58a8
leaq -0x78(%rbp), %rdi
callq 0x58a8
movl %ebx, %eax
addq $0x938, %rsp            # imm = 0x938
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r15d, %r13
leaq -0x4a8(%rbp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x5570
leaq -0x2a0(%rbp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x5570
leal 0x1(%r14), %eax
cmpl $-0x1, %r14d
pushq $-0x1
popq %rcx
cmovgel %eax, %ecx
movslq %ecx, %r13
movq %r13, %rdi
callq 0x5030
movq %rax, -0x38(%rbp)
movq %r13, %rdi
callq 0x5030
movq %rax, -0x30(%rbp)
movslq %r14d, %r13
leaq -0x4a8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x5500
leaq -0x2a0(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
callq 0x5500
leaq -0x4a8(%rbp), %rdi
callq 0x50a0
leaq -0x2a0(%rbp), %rdi
callq 0x50a0
xorl %eax, %eax
movq -0x38(%rbp), %rdi
movb %al, (%rdi,%r13)
movq -0x30(%rbp), %rsi
movb %al, (%rsi,%r13)
callq 0x55b0
testl %eax, %eax
je 0xf947
leaq 0x2ea0(%rip), %rsi      # 0x1270f
movq %rbx, %rdi
callq 0x5480
leaq 0x2db1(%rip), %rsi      # 0x1262f
movq %rax, %rdi
callq 0x5480
movq %rax, %rdi
callq 0x5240
leaq 0x2e90(%rip), %rsi      # 0x12725
movq %rbx, %rdi
callq 0x5480
movq %rax, %rdi
movq %r12, %rsi
callq 0x5410
leaq 0x2e90(%rip), %rsi      # 0x1273f
movq %rax, %rdi
callq 0x5480
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5770
leaq 0x2e7d(%rip), %rsi      # 0x12746
movq %rax, %rdi
callq 0x5480
movq %rax, %rdi
movl %r14d, %esi
callq 0x5770
movq %rax, %rdi
callq 0x5240
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x5410
leaq 0x2e5b(%rip), %rsi      # 0x12752
movq %rax, %rdi
callq 0x5480
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x5480
movq %rax, %rdi
callq 0x5240
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x5410
leaq 0x2e2c(%rip), %rsi      # 0x12752
movq %rax, %rdi
callq 0x5480
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x5480
movq %rax, %rdi
callq 0x5240
jmp 0xf72b
movb $0x1, %bl
jmp 0xf72d
jmp 0xf96d
movq %rax, %rbx
jmp 0xf97c
jmp 0xf98a
jmp 0xf96d
movq %rax, %rbx
jmp 0xf999
movq %rax, %rbx
jmp 0xf9a5
movq %rax, %rbx
jmp 0xf9ae
movq %rax, %rbx
jmp 0xf9ba
movq %rax, %rbx
leaq -0x2a0(%rbp), %rdi
callq 0x5110
leaq -0x4a8(%rbp), %rdi
callq 0x5110
jmp 0xf98d
movq %rax, %rbx
leaq -0x790(%rbp), %rdi
callq 0xe164
leaq -0x958(%rbp), %rdi
callq 0xe164
leaq -0x58(%rbp), %rdi
callq 0x58a8
leaq -0x98(%rbp), %rdi
callq 0x58a8
leaq -0x78(%rbp), %rdi
callq 0x58a8
movq %rbx, %rdi
callq 0x5780