// File: cpearce[P]OggIndex/src/Utils.cpp
// Function: IsPageAtOffset(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, long, ogg_page*)
bool
IsPageAtOffset(const string& filename, ogg_int64_t offset, ogg_page* page)
{
  ifstream file(filename.c_str(), ios::in | ios::binary);
  assert(file);
  file.seekg((std::streamoff)offset, ios_base::beg);
  char* buf = new char[max(page->body_len, page->header_len)];
  file.read(buf, page->header_len);
  assert(file.gcount() == page->header_len);
  if (memcmp(buf, page->header, page->header_len) != 0) {
    cerr << "Incorrect page offset calculation for page at offset "
         << offset << endl;
    delete[] buf;
    return false;
  }
  
  file.read(buf, page->body_len);
  assert(file.gcount() == page->body_len);
  if (memcmp(buf, page->body, page->body_len) != 0) {
    cerr << "Incorrect page offset calculation for page at offset "
         << offset << endl;
    delete[] buf;
    return false;
  }

  delete[] buf;
  return true;
}

// Assembly:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, 0x298(%rsp)
movq %rsi, 0x290(%rsp)
movq %rdx, 0x288(%rsp)
movq 0x298(%rsp), %rdi
callq 0x5180
movq %rax, 0x58(%rsp)
movl $0x8, %edi
movl $0x4, %esi
callq 0xe9f0
movq 0x58(%rsp), %rsi
movl %eax, %edx
leaq 0x80(%rsp), %rdi
callq 0x5840
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x80(%rsp,%rax), %rdi
callq 0x5510
movb %al, 0x63(%rsp)
jmp 0x16353
movb 0x63(%rsp), %al
testb $0x1, %al
jne 0x1635d
jmp 0x1635f
jmp 0x1639e
leaq 0x7bde(%rip), %rdi      # 0x1df44
leaq 0x810e(%rip), %rsi      # 0x1e47b
movl $0xc1, %edx
leaq 0x82b7(%rip), %rcx      # 0x1e630
callq 0x5280
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x50e0
jmp 0x1663e
movq 0x290(%rsp), %rsi
leaq 0x80(%rsp), %rdi
xorl %edx, %edx
callq 0x5570
jmp 0x163b7
movq 0x288(%rsp), %rsi
movq %rsi, %rdi
addq $0x18, %rdi
addq $0x8, %rsi
callq 0x170e0
movq %rax, 0x50(%rsp)
jmp 0x163d6
movq 0x50(%rsp), %rax
movq (%rax), %rdi
callq 0x5030
movq %rax, 0x48(%rsp)
jmp 0x163ea
movq 0x48(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rsi
movq 0x288(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x80(%rsp), %rdi
callq 0x5520
jmp 0x16414
leaq 0x80(%rsp), %rdi
callq 0x58d0
movq %rax, 0x40(%rsp)
jmp 0x16428
movq 0x40(%rsp), %rax
movq 0x288(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1643d
jmp 0x1645c
leaq 0x8229(%rip), %rdi      # 0x1e66d
leaq 0x8030(%rip), %rsi      # 0x1e47b
movl $0xc5, %edx
leaq 0x81d9(%rip), %rcx      # 0x1e630
callq 0x5280
movq 0x68(%rsp), %rdi
movq 0x288(%rsp), %rax
movq (%rax), %rsi
movq 0x288(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0x51c0
cmpl $0x0, %eax
je 0x164f7
movq 0x11b67(%rip), %rdi     # 0x27ff0
leaq 0x81ff(%rip), %rsi      # 0x1e68f
callq 0x53d0
movq %rax, 0x38(%rsp)
jmp 0x1649c
movq 0x38(%rsp), %rdi
movq 0x290(%rsp), %rsi
callq 0x5810
movq %rax, 0x30(%rsp)
jmp 0x164b5
movq 0x30(%rsp), %rdi
movq 0x11aff(%rip), %rsi     # 0x27fc0
callq 0x5430
jmp 0x164c8
movq 0x68(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x164e2
movq 0x28(%rsp), %rdi
callq 0x5540
movb $0x0, 0x2a7(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x16620
movq 0x68(%rsp), %rsi
movq 0x288(%rsp), %rax
movq 0x18(%rax), %rdx
leaq 0x80(%rsp), %rdi
callq 0x5520
jmp 0x16517
leaq 0x80(%rsp), %rdi
callq 0x58d0
movq %rax, 0x20(%rsp)
jmp 0x1652b
movq 0x20(%rsp), %rax
movq 0x288(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x16540
jmp 0x1655f
leaq 0x817e(%rip), %rdi      # 0x1e6c5
leaq 0x7f2d(%rip), %rsi      # 0x1e47b
movl $0xce, %edx
leaq 0x80d6(%rip), %rcx      # 0x1e630
callq 0x5280
movq 0x68(%rsp), %rdi
movq 0x288(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x288(%rsp), %rax
movq 0x18(%rax), %rdx
callq 0x51c0
cmpl $0x0, %eax
je 0x165f8
movq 0x11a63(%rip), %rdi     # 0x27ff0
leaq 0x80fb(%rip), %rsi      # 0x1e68f
callq 0x53d0
movq %rax, 0x18(%rsp)
jmp 0x165a0
movq 0x18(%rsp), %rdi
movq 0x290(%rsp), %rsi
callq 0x5810
movq %rax, 0x10(%rsp)
jmp 0x165b9
movq 0x10(%rsp), %rdi
movq 0x119fb(%rip), %rsi     # 0x27fc0
callq 0x5430
jmp 0x165cc
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x165e6
movq 0x8(%rsp), %rdi
callq 0x5540
movb $0x0, 0x2a7(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x16620
movq 0x68(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x16610
movq (%rsp), %rdi
callq 0x5540
movb $0x1, 0x2a7(%rsp)
movl $0x1, 0x64(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x50e0
movb 0x2a7(%rsp), %al
andb $0x1, %al
addq $0x2a8, %rsp            # imm = 0x2A8
retq
movq 0x78(%rsp), %rdi
callq 0x57d0
nopl (%rax,%rax)