// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x4073(%rip), %r12      # 0x7fc8
movq %r12, %rdi
callq 0x2110
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rbx
callq 0x21a0
movq %rax, %rdi
callq 0x2110
leaq -0x80(%rbp), %r12
movq %r12, %rdi
movq %r14, -0x38(%rbp)
movq %r14, %rsi
movq %r15, %rdx
callq 0x3c22
movq %r12, %rdi
xorl %esi, %esi
callq 0x3e6f
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x371a
movq %r14, %rdi
callq 0x36b6
movq %rax, %r13
movq %rbx, %r12
movq %rbx, %rdi
leaq 0x13eb(%rip), %rsi      # 0x53a8
callq 0x21d0
movq %rax, %rbx
movq %r14, %rdi
callq 0x36c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x2290
movq %rax, %rdi
leaq 0x13d2(%rip), %rsi      # 0x53b3
callq 0x21d0
xorl %r15d, %r15d
movslq %r15d, %r15
cmpq $0x11, %r15
jae 0x4044
movl (%r13,%r15), %r14d
movl 0x4(%r13,%r15), %ebx
movq %r12, %rdi
leaq 0x13b0(%rip), %rsi      # 0x53b6
callq 0x21d0
movq %rax, %rdi
movl %r14d, %esi
callq 0x2290
movq %rax, %rdi
leaq 0x1398(%rip), %rsi      # 0x53b8
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2290
movq %rax, %rdi
leaq 0x1382(%rip), %rsi      # 0x53bb
callq 0x21d0
addq $0x8, %r15
jmp 0x3fe9
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x36c0
movl %eax, %r13d
movq %r14, %rdi
callq 0x36c0
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
movl %eax, %esi
callq 0x3902
cmpl -0x2c(%rbp), %r13d
je 0x409d
movq %r14, %rdi
callq 0x36c0
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x3736
movups -0x60(%rbp), %xmm0
movaps %xmm0, -0x50(%rbp)
movq %r12, %rbx
movq %r12, %rdi
callq 0x2110
jmp 0x3fa5
leaq -0x80(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x3cdc
movq 0x3f17(%rip), %rdi      # 0x7fc8
callq 0x2110
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq