// File: 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
subq $0x90, %rsp
movq %rdx, -0x88(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq 0x670b(%rip), %rdi      # 0xdfd0
movq 0x66e4(%rip), %rsi      # 0xdfb0
callq 0x21f0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq 0x66c6(%rip), %rsi      # 0xdfb0
callq 0x21f0
movl $0x6, -0x1c(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x7270
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x7790
movl %eax, -0x44(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x69b0
leaq -0x58(%rbp), %rdi
callq 0x68c0
movq %rax, -0x60(%rbp)
movq 0x669a(%rip), %rdi      # 0xdfd0
leaq 0x1a6f(%rip), %rsi      # 0x93ac
callq 0x21d0
movq %rax, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x68e0
movq -0x90(%rbp), %rdi
movl %eax, %esi
callq 0x2310
movq %rax, %rdi
leaq 0x1a4d(%rip), %rsi      # 0x93b7
callq 0x21d0
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
cmpq %rcx, %rax
ja 0x7a00
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl 0x4(%rax,%rcx), %eax
movl %eax, -0x6c(%rbp)
movq 0x6620(%rip), %rdi      # 0xdfd0
leaq 0x1a03(%rip), %rsi      # 0x93ba
callq 0x21d0
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0x2310
movq %rax, %rdi
leaq 0x19eb(%rip), %rsi      # 0x93bc
callq 0x21d0
movq %rax, %rdi
movl -0x6c(%rbp), %esi
callq 0x2310
movq %rax, %rdi
leaq 0x19d4(%rip), %rsi      # 0x93bf
callq 0x21d0
movslq -0x64(%rbp), %rax
addq $0x8, %rax
movl %eax, -0x64(%rbp)
jmp 0x7976
leaq -0x58(%rbp), %rdi
callq 0x68e0
cmpl -0x44(%rbp), %eax
jne 0x7a10
jmp 0x7a64
leaq -0x58(%rbp), %rdi
callq 0x68e0
movl %eax, %esi
leaq -0x40(%rbp), %rdi
callq 0x6d10
leaq -0x58(%rbp), %rdi
callq 0x68e0
movl %eax, %edx
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x69e0
movq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x657d(%rip), %rdi      # 0xdfd0
movq 0x6556(%rip), %rsi      # 0xdfb0
callq 0x21f0
jmp 0x7922
leaq -0x58(%rbp), %rdi
callq 0x68e0
movl %eax, %esi
leaq -0x40(%rbp), %rdi
callq 0x6d10
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x73a0
movq 0x6544(%rip), %rdi      # 0xdfd0
movq 0x651d(%rip), %rsi      # 0xdfb0
callq 0x21f0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)