// File: /workspace/github_cpp_makefile_star2_O2/ruankotovich[P]B-Tree/src/seek2.cpp
// Function: main
int main(int argc, char** argv)
{
    SecondaryBTreeDataMap searchKey;

    if (argc > 1) {
        std::memcpy(searchKey.key, argv[1], SECONDARY_KEY_LENGTH);
    } else {
        std::string buffer;
        std::getline(std::cin, buffer);
        std::memcpy(searchKey.key, buffer.c_str(), SECONDARY_KEY_LENGTH);
        std::cout << "\"" << buffer << "\"\n";
    }

    SecondaryBTree btree;

    Article_t a;
    FILE* indexFile = fopen("files/secondaryindex.block", "rb");

    btree.readRoot(indexFile);

    if (indexFile != NULL) {
        auto result = btree.getArticle(searchKey, &a, indexFile);

        if (result.first) {
            cout << a.toString();
            cout << "\n\nNumber of block read in PrimaryBTree Index to find the record: " << result.second + 1;
            fseek(indexFile, 0, SEEK_END);
            cout << "\n\nTotal number of blocks in primary index file: " << ((ftell(indexFile) / sizeof(AbstractBlock_t))) << "\n";
        } else {
            cout << "Record not found.\n";
        }
    } else {
        cout << "There isn't a primary index file.\n";
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xbf0, %rsp            # imm = 0xBF0
cmpl $0x2, %edi
jl 0x16f6
movq 0x8(%rsi), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
jmp 0x1774
leaq 0x2b0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x38cf(%rip), %rdi      # 0x4fe0
leaq 0x2a0(%rsp), %rsi
callq 0x1050
movq 0x2a0(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
movq 0x3894(%rip), %rdi      # 0x4fd0
leaq 0x19d0(%rip), %rsi      # 0x3113
callq 0x10d0
leaq 0x2a0(%rsp), %rsi
movq %rax, %rdi
callq 0x10c0
leaq 0x18c2(%rip), %rsi      # 0x3021
movq %rax, %rdi
callq 0x10d0
leaq 0x2a0(%rsp), %rdi
callq 0x1060
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x1a4c
leaq 0x2a0(%rsp), %rdi
callq 0x27b0
leaq 0x188c(%rip), %rdi      # 0x3024
leaq 0x18a0(%rip), %rsi      # 0x303f
callq 0x1110
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x1ace
testq %rbx, %rbx
je 0x187d
leaq 0x158(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
movq %rbx, %rcx
callq 0x2406
movq %rax, %r14
testb $0x1, %r14b
je 0x188d
leaq 0x8(%rsp), %r15
leaq 0x2a0(%rsp), %rsi
movq %r15, %rdi
callq 0x283c
movq 0x37cf(%rip), %rdi      # 0x4fd0
movq %r15, %rsi
callq 0x10c0
shrq $0x20, %r14
leaq 0x8(%rsp), %rdi
callq 0x1060
movq 0x37b2(%rip), %r15      # 0x4fd0
leaq 0x181d(%rip), %rsi      # 0x3042
movq %r15, %rdi
callq 0x10d0
incl %r14d
movq %rax, %rdi
movl %r14d, %esi
callq 0x1170
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
leaq 0x1835(%rip), %rsi      # 0x3084
movq %r15, %rdi
callq 0x10d0
movq %rax, %r14
movq %rbx, %rdi
callq 0x1030
shrq $0xc, %rax
movq %r14, %rdi
movq %rax, %rsi
callq 0x1070
leaq 0x1890(%rip), %rsi      # 0x3108
movq %rax, %rdi
jmp 0x189b
movq 0x374c(%rip), %rdi      # 0x4fd0
leaq 0x183d(%rip), %rsi      # 0x30c8
jmp 0x189b
movq 0x373c(%rip), %rdi      # 0x4fd0
leaq 0x181a(%rip), %rsi      # 0x30b5
callq 0x10d0
xorl %eax, %eax
addq $0xbf0, %rsp            # imm = 0xBF0
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x18c4
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
callq 0x1060
movq %rbx, %rdi
callq 0x1180
nopl (%rax)