// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_verify
static int eprog_verify(struct multiboot *mboot,
                       struct databuf *dbuf, int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "verifing EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;
    uint8_t comp[256];

    if (eprog_set_address(p_prog, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

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

        uint8_t len = MIN(p_prog->pagesize, dbuf->length - pos);
        if (eprog_read_data(p_prog, comp, len))
        {
            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 pos 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)
leaq 0x7c3d(%rip), %rax      # 0xb9b6
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x4b40
cmpl $0x0, %eax
jge 0x3db9
movq 0xc25c(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x77a4(%rip), %rsi      # 0xb54a
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3efe
jmp 0x3dbb
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x3ed5
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
callq *%rax
movq -0x28(%rbp), %rax
movzbl 0x6a(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jae 0x3e09
movq -0x28(%rbp), %rax
movzbl 0x6a(%rax), %eax
movl %eax, -0x148(%rbp)
jmp 0x3e19
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x148(%rbp)
movl -0x148(%rbp), %eax
movb %al, -0x141(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movzbl -0x141(%rbp), %edx
callq 0x4be0
cmpl $0x0, %eax
je 0x3e62
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 0x3efe
leaq -0x140(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movl -0x34(%rbp), %eax
addq %rax, %rsi
movzbl -0x141(%rbp), %eax
movl %eax, %edx
callq 0x2140
cmpl $0x0, %eax
je 0x3ec3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq *%rax
movq 0xc152(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x76cf(%rip), %rsi      # 0xb582
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3efe
movzbl -0x141(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3dbb
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%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
nopw (%rax,%rax)