// File: /workspace/github_cpp_makefile_star2_O3/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, -0x2c(%rbp)
movq %rdx, %r12
movq %rdi, %r14
leaq 0xa0(%rdi), %r15
leaq -0x60(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x70(%rbp), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x26ba
movq %r15, %rdi
movq %r13, %rsi
callq 0x2a16
testl %eax, %eax
js 0x27ec
leaq -0x40(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x26ba
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x2a16
movl %eax, %r12d
shrl $0x1f, %r12d
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x27ef
callq 0x2110
jmp 0x27ef
movb $0x1, %r12b
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x27fd
callq 0x2110
testb %r12b, %r12b
je 0x284c
movq 0x57e7(%rip), %rbx      # 0x7ff0
leaq 0x284e(%rip), %rsi      # 0x505e
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0xfffffffd, %r14d      # imm = 0xFFFFFFFD
jmp 0x28ba
leaq -0xb0(%rbp), %rsi
movq %r15, %rdi
callq 0x35de
testl %eax, %eax
jne 0x2872
leaq -0x90(%rbp), %rsi
movq %r14, %rdi
callq 0x29f4
testl %eax, %eax
je 0x28cf
movq 0x5777(%rip), %rbx      # 0x7ff0
leaq 0x2802(%rip), %rsi      # 0x5082
movl $0x34, %edx
movq %rbx, %rdi
callq 0x2160
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, -0x2c(%rbp)
je 0x2951
leaq 0x27db(%rip), %rdi      # 0x50b7
xorl %eax, %eax
callq 0x2050
leaq 0x27db(%rip), %rbx      # 0x50c5
xorl %r14d, %r14d
movzbl -0xb0(%rbp,%r14), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
incq %r14
cmpq $0x20, %r14
jne 0x28ed
movl $0xa, %edi
callq 0x21b0
leaq 0x27b0(%rip), %rdi      # 0x50ca
xorl %eax, %eax
callq 0x2050
leaq 0x279d(%rip), %rbx      # 0x50c5
xorl %r14d, %r14d
movzbl -0x90(%rbp,%r14), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
incq %r14
cmpq $0x20, %r14
jne 0x292b
movl $0xa, %edi
callq 0x21b0
movdqu -0xb0(%rbp), %xmm0
movdqu -0xa0(%rbp), %xmm1
movdqu -0x90(%rbp), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu -0x80(%rbp), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %eax
movq 0x564b(%rip), %rbx      # 0x7fd0
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x29ab
leaq 0x275e(%rip), %rsi      # 0x50f1
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x2160
movl $0x1, %r14d
jmp 0x2893
leaq 0x2726(%rip), %rsi      # 0x50d8
movl $0x18, %edx
movq %rbx, %rdi
callq 0x2160
xorl %r14d, %r14d
jmp 0x2893
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x29dd
callq 0x2110
jmp 0x29dd
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x29eb
callq 0x2110
movq %r14, %rdi
callq 0x2220
nop