// File: /workspace/github_cpp_makefile_star2_O3/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 0x1ac1
movq 0x8(%rsi), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
jmp 0x1b84
leaq 0x2b0(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
movq 0x4500(%rip), %rdi      # 0x5fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %edx
movq 0x44e5(%rip), %rdi      # 0x5fe0
leaq 0x2a0(%rsp), %rsi
callq 0x11a0
movq 0x2a0(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movl $0x12c, %edx            # imm = 0x12C
callq 0x10a0
movq 0x44aa(%rip), %rdi      # 0x5fd0
leaq 0x25e6(%rip), %rsi      # 0x4113
movl $0x1, %edx
callq 0x1100
movq 0x2a0(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
movq 0x4482(%rip), %rdi      # 0x5fd0
callq 0x1100
leaq 0x24c7(%rip), %rsi      # 0x4021
movl $0x2, %edx
movq %rax, %rdi
callq 0x1100
movq 0x2a0(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b84
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x10e0
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x1ebc
leaq 0x2a0(%rsp), %rdi
callq 0x2c48
leaq 0x247c(%rip), %rdi      # 0x4024
leaq 0x2490(%rip), %rsi      # 0x403f
callq 0x1110
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x1f40
testq %rbx, %rbx
je 0x1cb0
leaq 0x158(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
movq %rbx, %rcx
callq 0x2920
movq %rax, %r14
testb $0x1, %r14b
je 0x1cc5
leaq 0x8(%rsp), %r15
leaq 0x2a0(%rsp), %rsi
movq %r15, %rdi
callq 0x2cd4
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x43b8(%rip), %rdi      # 0x5fd0
callq 0x1100
shrq $0x20, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c3c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x10e0
movq 0x438d(%rip), %r15      # 0x5fd0
leaq 0x23f8(%rip), %rsi      # 0x4042
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 0x2409(%rip), %rsi      # 0x4084
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 0x2462(%rip), %rsi      # 0x4108
movl $0x1, %edx
movq %rax, %rdi
jmp 0x1cd8
movq 0x4319(%rip), %rdi      # 0x5fd0
leaq 0x240a(%rip), %rsi      # 0x40c8
movl $0x22, %edx
jmp 0x1cd8
movq 0x4304(%rip), %rdi      # 0x5fd0
leaq 0x23e2(%rip), %rsi      # 0x40b5
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 0x1d24
movq 0x18(%rsp), %rsi
jmp 0x1d1c
movq %rax, %rbx
movq 0x2a0(%rsp), %rdi
cmpq %r14, %rdi
je 0x1d24
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1180