// File: /workspace/github_cpp_makefile_star2_O3/Dwijesh522[P]DBMS_assignment_3/linear_search.cpp
// Function: printAnswers(FileManager&, char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void printAnswers(FileManager &fm, char *file_path, string title) {
    /*
     *	This function prints all integers stored in the file in pairs
     *	This function is mainly written for matching our answer with
     *	ground truth answer provided by TAs. Call this funtion on both
     *	files one after another and check correctness manually.
     */
    cout << endl << title << endl;
    int integers_per_page = PAGE_CONTENT_SIZE / sizeof(int);
    FileHandler file_handler = fm.OpenFile(file_path);
    int last_page_num = getLastPageNumber(file_handler, /*keep pinned*/ false);
    PageHandler page_handler = file_handler.FirstPage(); // pinned

    while (true) {
        char *data = page_handler.GetData();
        cout << "page number: " << page_handler.GetPageNum() << ": ";
        for (int i=0; i<=(integers_per_page-2)*sizeof(int); i+= 2*sizeof(int)) {
            // read two integers in pair starting from location i
            int first_num, sec_num;
            memcpy(&first_num, &data[i], sizeof(int));
            memcpy(&sec_num, &data[i+sizeof(int)], sizeof(int));
            cout << "(" << first_num <<", " << sec_num << ") ";
        }
        if (page_handler.GetPageNum() == last_page_num) break;
        file_handler.UnpinPage(page_handler.GetPageNum()); // unpinned
        page_handler = file_handler.NextPage(page_handler.GetPageNum()); // pinned
        cout << endl;
    }
    file_handler.UnpinPage(page_handler.GetPageNum());
    fm.CloseFile(file_handler);
    cout << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq 0x3fca(%rip), %r13      # 0x7fd0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rax, %rdi
callq 0x21e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq %r12, -0x38(%rbp)
movq %r12, %rsi
movq %r14, %rdx
callq 0x3c40
movq %r15, %rdi
xorl %esi, %esi
callq 0x3f20
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x36ee
leaq 0x131b(%rip), %r15      # 0x53bb
movq %r12, %rdi
callq 0x3684
movq %rax, -0x40(%rbp)
movl $0xd, %edx
movq %r13, %rdi
leaq 0x12ed(%rip), %rsi      # 0x53a8
callq 0x21e0
movq %r12, %rdi
callq 0x368e
movq %r13, %rdi
movl %eax, %esi
callq 0x22a0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x12d2(%rip), %rsi      # 0x53b3
callq 0x21e0
movq $-0x8, %r12
movq -0x40(%rbp), %rax
movl 0x8(%rax,%r12), %r14d
movq %r15, %rbx
movl 0xc(%rax,%r12), %r15d
movl $0x1, %edx
movq %r13, %rdi
leaq 0x12a9(%rip), %rsi      # 0x53b6
callq 0x21e0
movq %r13, %rdi
movl %r14d, %esi
callq 0x22a0
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
leaq 0x1289(%rip), %rsi      # 0x53b8
callq 0x21e0
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %r15
callq 0x22a0
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21e0
addq $0x8, %r12
cmpq $0x9, %r12
jb 0x40ed
movq %r13, %rbx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
callq 0x368e
movl %eax, %r13d
movq %r12, %rdi
callq 0x368e
leaq -0x80(%rbp), %r14
movq %r14, %rdi
movl %eax, %esi
callq 0x38f4
cmpl -0x2c(%rbp), %r13d
je 0x41d7
movq %r12, %rdi
callq 0x368e
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x370c
movups -0x60(%rbp), %xmm0
movaps %xmm0, -0x50(%rbp)
movq %rbx, %r13
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
jmp 0x40a0
leaq -0x80(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x3d08
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq