// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq %rdi, %r14
leaq 0xa0(%rdi), %r15
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x26c8
movq %r15, %rdi
movq %r12, %rsi
callq 0x2a32
movl %eax, %r12d
leaq -0x60(%rbp), %rbx
testl %eax, %eax
js 0x27eb
leaq -0x70(%rbp), %rdi
movq %rbx, (%rdi)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
callq 0x26c8
leaq -0x70(%rbp), %rsi
movq %r14, %rdi
callq 0x2a32
movl %eax, %r13d
shrl $0x1f, %r13d
jmp 0x27ee
movb $0x1, %r13b
testl %r12d, %r12d
js 0x2801
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2801
callq 0x2110
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2813
callq 0x2110
testb %r13b, %r13b
je 0x2862
movq 0x57d1(%rip), %rbx      # 0x7ff0
leaq 0x2838(%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 0x28d0
leaq -0xb0(%rbp), %rsi
movq %r15, %rdi
callq 0x35cc
testl %eax, %eax
jne 0x2888
leaq -0x90(%rbp), %rsi
movq %r14, %rdi
callq 0x2a10
testl %eax, %eax
je 0x28e5
movq 0x5761(%rip), %rbx      # 0x7ff0
leaq 0x27ec(%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 0x2967
leaq 0x27c5(%rip), %rdi      # 0x50b7
xorl %eax, %eax
callq 0x2050
leaq 0x27c5(%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 0x2903
movl $0xa, %edi
callq 0x21b0
leaq 0x279a(%rip), %rdi      # 0x50ca
xorl %eax, %eax
callq 0x2050
leaq 0x2787(%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 0x2941
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 0x5635(%rip), %rbx      # 0x7fd0
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x29c1
leaq 0x2748(%rip), %rsi      # 0x50f1
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x2160
movl $0x1, %r14d
jmp 0x28a9
leaq 0x2710(%rip), %rsi      # 0x50d8
movl $0x18, %edx
movq %rbx, %rdi
callq 0x2160
xorl %r14d, %r14d
jmp 0x28a9
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x29f3
callq 0x2110
jmp 0x29f3
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2a05
callq 0x2110
movq %r14, %rdi
callq 0x2220
nopl (%rax)