// File: /workspace/github_cpp_makefile_star2_O2/adamjanovsky[P]PA193_test_parser_monero/src/parser.cpp
// Function: Parser::validate_block(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
int Parser::validate_block(string lower_filename, string higher_filename, bool print_hashes /* = false */) {
    // Initialize the blocks from given filenames
    if(lower_block.init_from_file(lower_filename) < 0 or
       higher_block.init_from_file(higher_filename) < 0) {
        std::cerr << "Parser: Failed to initialize block." << std::endl;
        return ERR_PARSER_FAILED_TO_INIT;
    }

    // Get the block hash and block id from the next block
    hash::hash_t lower_hash;
    hash::hash_t higher_prev_id;
    if(lower_block.get_block_hash(lower_hash) or higher_block.get_prev_id(higher_prev_id)) {
        std::cerr << "Parser: Failed to obtain hash result of lower block." << std::endl;
        return ERR_PARSER_FAILED_TO_VALIDATE;
    }

    // Print the hashes if desired
    if (print_hashes) {
        printf("Lower hash:  ");
        for(int i = 0; i < lower_hash.size(); i++) printf("%02x", lower_hash[i]);
        printf("\n");
        printf("Higher hash: ");
        for(int i = 0; i < higher_prev_id.size(); i++) printf("%02x", higher_prev_id[i]);
        printf("\n");
    }
    
    // Compare the hash values to validate the block
    if (memcmp(lower_hash.data(), higher_prev_id.data(), lower_hash.size()) == 0) {
        std::cout << "OK - The block is valid." << std::endl;
        return OK;
    } else {
        std::cout << "ERR - The block is not valid." << std::endl;
        return ERR_PARSER_BLOCK_INVALID;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, %ebx
movq %rdx, %r12
movq %rdi, %r14
leaq 0xa0(%rdi), %r15
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0x21c0
movq %r15, %rdi
movq %r13, %rsi
callq 0x2820
testl %eax, %eax
js 0x26d6
leaq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x21c0
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x2820
movl %eax, %r12d
leaq -0x48(%rbp), %rdi
callq 0x2090
leaq -0x68(%rbp), %rdi
callq 0x2090
testl %r12d, %r12d
js 0x26df
leaq -0xa8(%rbp), %rsi
movq %r15, %rdi
callq 0x305a
testl %eax, %eax
jne 0x26b6
leaq -0x88(%rbp), %rsi
movq %r14, %rdi
callq 0x27fc
testl %eax, %eax
je 0x2711
movq 0x5933(%rip), %rdi      # 0x7ff0
leaq 0x2994(%rip), %rsi      # 0x5058
callq 0x2120
pushq $-0x1
popq %rbx
movq %rax, %rdi
callq 0x20a0
jmp 0x26fd
leaq -0x68(%rbp), %rdi
callq 0x2090
movq 0x590a(%rip), %rdi      # 0x7ff0
leaq 0x2947(%rip), %rsi      # 0x5034
callq 0x2120
movq %rax, %rdi
callq 0x20a0
pushq $-0x3
popq %rbx
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %bl, %bl
je 0x2791
leaq 0x2971(%rip), %rdi      # 0x508d
xorl %eax, %eax
callq 0x2040
leaq 0x2971(%rip), %rbx      # 0x509b
xorl %r14d, %r14d
cmpq $0x20, %r14
je 0x274b
movzbl -0xa8(%rbp,%r14), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2040
incq %r14
jmp 0x272d
pushq $0xa
popq %rdi
callq 0x21d0
leaq 0x2946(%rip), %rdi      # 0x50a0
xorl %eax, %eax
callq 0x2040
leaq 0x2933(%rip), %rbx      # 0x509b
xorl %r14d, %r14d
cmpq $0x20, %r14
je 0x2789
movzbl -0x88(%rbp,%r14), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2040
incq %r14
jmp 0x276b
pushq $0xa
popq %rdi
callq 0x21d0
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
pushq $0x20
popq %rdx
callq 0x2150
movq 0x5822(%rip), %rdi      # 0x7fd0
testl %eax, %eax
je 0x27c5
leaq 0x290e(%rip), %rsi      # 0x50c7
callq 0x2120
pushq $0x1
jmp 0x26cb
leaq 0x28e2(%rip), %rsi      # 0x50ae
callq 0x2120
xorl %ebx, %ebx
jmp 0x26cc
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2090
jmp 0x27e9
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2240
nop