// File: /workspace/github_cpp_makefile_star2_O1/rocket323[P]fishdb/./pager.cpp
// Function: fishdb::Pager::ReadPage(long)
std::shared_ptr<MemPage> Pager::ReadPage(int64_t page_no)
{
    char buf[PG_SIZE * 2];
    // if page_no invalid, return nil
    if (page_no <= 0) return nil;
    int64_t offset = page_no * PG_SIZE;
    if (offset + PG_SIZE > m_file_size) return nil;

    auto mp = std::make_shared<MemPage>();
    auto header = &mp->header;
    fseek(m_file, offset, SEEK_SET);
    fread((void *)header, sizeof(PageHeader), 1, m_file);
    fread((void *)buf, PAGE_CAPA, 1, m_file);
    mp->Feed(buf, PAGE_CAPA);
    if (mp->header.page_no != page_no)
    {
        auto p = std::make_shared<MemPage>();
        p->header.page_no = page_no;
        p->header.page_cnt = 1;
        p->header.of_page_no = -1;
        p->header.next_free = -1;
        return p;
    }
    return mp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rdi, %rbx
testq %rdx, %rdx
jle 0x67ee
movq %rdx, %r12
movq %rsi, %r13
movq %rdx, %r15
shlq $0x9, %r15
leaq 0x200(%r15), %rax
cmpq 0x40(%rsi), %rax
jle 0x6824
movq 0x59fb(%rip), %rax      # 0xc1f0
movq %rax, (%rbx)
movq 0x59f9(%rip), %rax      # 0xc1f8
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x6994
movq 0x57bd(%rip), %rcx      # 0xbfd0
cmpb $0x0, (%rcx)
je 0x68f5
incl 0x8(%rax)
jmp 0x6994
movl $0xa0, %edi
callq 0x21f0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x54c2(%rip), %rax      # 0xbd08
movq %rax, (%r14)
leaq 0x10(%r14), %rdi
movq %rdi, -0x30(%rbp)
movl $0x90, %edx
xorl %esi, %esi
callq 0x2120
leaq 0x48(%r14), %rax
movq %rax, 0x38(%r14)
movq $0x0, 0x40(%r14)
movb $0x0, 0x48(%r14)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x58(%r14)
movdqu %xmm0, 0x68(%r14)
movdqu %xmm0, 0x78(%r14)
movq 0x38(%r13), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2220
movq 0x38(%r13), %rcx
movl $0x28, %esi
movl $0x1, %edx
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x22b0
movq 0x38(%r13), %rcx
movq %r15, %r13
leaq -0x430(%rbp), %r15
movl $0x1d8, %esi            # imm = 0x1D8
movl $0x1, %edx
movq %r15, %rdi
callq 0x22b0
movq %r13, %rdi
movq %r15, %rsi
movl $0x1d8, %edx            # imm = 0x1D8
callq 0x741a
cmpq %r12, (%r13)
jne 0x68fe
movq %r13, (%rbx)
movq %r14, 0x8(%rbx)
xorl %r14d, %r14d
jmp 0x6987
lock
incl 0x8(%rax)
jmp 0x6994
movq $0x0, (%rbx)
movl $0xa0, %edi
callq 0x21f0
movq %rax, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r15)
leaq 0x53e1(%rip), %rax      # 0xbd08
movq %rax, (%r15)
leaq 0x10(%r15), %r13
movl $0x90, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2120
movq %r15, %rax
addq $0x48, %rax
movq %rax, 0x38(%r15)
movq $0x0, 0x40(%r15)
movb $0x0, 0x48(%r15)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x58(%r15)
movdqu %xmm0, 0x68(%r15)
movdqu %xmm0, 0x78(%r15)
movq %r15, 0x8(%rbx)
movq %r13, (%rbx)
movq %r12, 0x10(%r15)
movw $0x1, 0x34(%r15)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x20(%r15)
testq %r14, %r14
je 0x6994
movq %r14, %rdi
callq 0x277e
movq %rbx, %rax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r14, %rdi
callq 0x277e
movq %rbx, %rdi
callq 0x2300