// File: /workspace/github_cpp_makefile_star2_O1/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 0x1891
movq 0x8(%rsi), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
jmp 0x1954
leaq 0x2b0(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
movq 0x3730(%rip), %rdi      # 0x4fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %edx
movq 0x3715(%rip), %rdi      # 0x4fe0
leaq 0x2a0(%rsp), %rsi
callq 0x11a0
movq 0x2a0(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
movq 0x36da(%rip), %rdi      # 0x4fd0
leaq 0x1816(%rip), %rsi      # 0x3113
movl $0x1, %edx
callq 0x1100
movq 0x2a0(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
movq 0x36b2(%rip), %rdi      # 0x4fd0
callq 0x1100
leaq 0x16f7(%rip), %rsi      # 0x3021
movl $0x2, %edx
movq %rax, %rdi
callq 0x1100
movq 0x2a0(%rsp), %rdi
cmpq %r14, %rdi
je 0x1954
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x10e0
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x1c8c
leaq 0x2a0(%rsp), %rdi
callq 0x2ab0
leaq 0x16ac(%rip), %rdi      # 0x3024
leaq 0x16c0(%rip), %rsi      # 0x303f
callq 0x1110
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x1d10
testq %rbx, %rbx
je 0x1a80
leaq 0x158(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
movq %rbx, %rcx
callq 0x2768
movq %rax, %r14
testb $0x1, %r14b
je 0x1a95
leaq 0x8(%rsp), %r15
leaq 0x2a0(%rsp), %rsi
movq %r15, %rdi
callq 0x2b3c
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x35e8(%rip), %rdi      # 0x4fd0
callq 0x1100
shrq $0x20, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1a0c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x10e0
movq 0x35bd(%rip), %r15      # 0x4fd0
leaq 0x1628(%rip), %rsi      # 0x3042
movl $0x41, %edx
movq %r15, %rdi
callq 0x1100
incl %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0x1170
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x10f0
leaq 0x1639(%rip), %rsi      # 0x3084
movl $0x30, %edx
movq %r15, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x1030
shrq $0xc, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x1070
leaq 0x1692(%rip), %rsi      # 0x3108
movl $0x1, %edx
movq %rax, %rdi
jmp 0x1aa8
movq 0x3549(%rip), %rdi      # 0x4fd0
leaq 0x163a(%rip), %rsi      # 0x30c8
movl $0x22, %edx
jmp 0x1aa8
movq 0x3534(%rip), %rdi      # 0x4fd0
leaq 0x1612(%rip), %rsi      # 0x30b5
movl $0x12, %edx
callq 0x1100
xorl %eax, %eax
addq $0xbf0, %rsp            # imm = 0xBF0
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1af4
movq 0x18(%rsp), %rsi
jmp 0x1aec
movq %rax, %rbx
movq 0x2a0(%rsp), %rdi
cmpq %r14, %rdi
je 0x1af4
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1180