// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_verify
static int mpm_verify(struct multiboot *mboot,
                      struct databuf *dbuf, int memtype)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "verifing flash" : "verifing eeprom";

    uint16_t pos = 0;
    uint8_t comp[READ_BLOCK_SIZE];

    while (pos < dbuf->length)
    {
        mboot->progress_cb(progress_msg, pos, dbuf->length);

        uint16_t len = MIN(READ_BLOCK_SIZE, dbuf->length - pos);
        if (mpm_read_memory(mpm, comp, len, memtype, pos))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        if (memcmp(comp, dbuf->data + pos, len) != 0x00)
        {
            mboot->progress_cb(progress_msg, -1, -1);
            fprintf(stderr, "verify failed at page 0x%04x!!\n", pos);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

    mboot->progress_cb(progress_msg, pos, dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %edx
leaq 0x3996(%rip), %rax      # 0xb572
leaq 0x3980(%rip), %rcx      # 0xb563
cmpl $0x1, %edx
cmoveq %rcx, %rax
movq %rax, -0x30(%rbp)
movw $0x0, -0x32(%rbp)
movzwl -0x32(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x7d27
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movzwl -0x32(%rbp), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
callq *%rax
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movzwl -0x32(%rbp), %eax
subl %eax, %ecx
movl $0x100, %eax            # imm = 0x100
cmpl %ecx, %eax
jae 0x7c41
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x148(%rbp)
jmp 0x7c54
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movzwl -0x32(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x148(%rbp)
movl -0x148(%rbp), %eax
movw %ax, -0x142(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movw -0x142(%rbp), %cx
movl -0x1c(%rbp), %eax
movzwl %cx, %edx
movzbl %al, %ecx
movzwl -0x32(%rbp), %r8d
callq 0x8920
cmpl $0x0, %eax
je 0x7cac
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7d52
leaq -0x140(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movzwl -0x32(%rbp), %eax
cltq
addq %rax, %rsi
movzwl -0x142(%rbp), %eax
movl %eax, %edx
callq 0x2140
cmpl $0x0, %eax
je 0x7d11
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq *%rax
movq 0x8305(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movzwl -0x32(%rbp), %edx
leaq 0x43bb(%rip), %rsi      # 0xc0bc
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7d52
movzwl -0x142(%rbp), %ecx
movzwl -0x32(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x32(%rbp)
jmp 0x7bf4
movzwl -0x32(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movzwl -0x32(%rbp), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nop