LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/pyk[P]simple-nn/deps/pcg/src/pcg-advance-32.c
// Function: pcg_advance_lcg_32
uint32_t pcg_advance_lcg_32(uint32_t state, uint32_t delta, uint32_t cur_mult,
                            uint32_t cur_plus)
{
    uint32_t acc_mult = 1u;
    uint32_t acc_plus = 0u;
    while (delta > 0) {
        if (delta & 1) {
            acc_mult *= cur_mult;
            acc_plus = acc_plus * cur_mult + cur_plus;
        }
        cur_plus = (cur_mult + 1) * cur_plus;
        cur_mult *= cur_mult;
        delta /= 2;
    }
    return acc_mult * state + acc_plus;
}

// Assembly:
testl %esi, %esi
je 0x16f2
pushq %rbx
movl $0x1, %r9d
xorl %r8d, %r8d
movl $0x1, %eax
movl %esi, %r10d
movl %r8d, %r11d
imull %edx, %r11d
addl %ecx, %r11d
testb $0x1, %sil
movl %edx, %ebx
cmovel %r9d, %ebx
cmovnel %r11d, %r8d
imull %ebx, %eax
leal 0x1(%rdx), %r11d
imull %r11d, %ecx
imull %edx, %edx
shrl %r10d
cmpl $0x1, %esi
movl %r10d, %esi
ja 0x16be
popq %rbx
jmp 0x16fa
xorl %r8d, %r8d
movl $0x1, %eax
imull %edi, %eax
addl %r8d, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_alloc
static struct multiboot * butterfly_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

    memset(mboot, 0x00, sizeof(struct multiboot));
    mboot->ops= &butterfly_ops;

    bfly_privdata_t * p_priv = malloc(sizeof(bfly_privdata_t));
    if (p_priv == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(p_priv, 0x00, sizeof(bfly_privdata_t));

    optarg_register(bfly_optargs, ARRAY_SIZE(bfly_optargs),
                    bfly_optarg_cb, (void *)p_priv);

    mboot->privdata = p_priv;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x303f
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
leaq 0xa18d(%rip), %rax      # 0xd170
movq %rax, (%rbx)
movl $0x58, %edi
callq 0x21c0
testq %rax, %rax
je 0x3037
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x50(%rax)
leaq 0xa1a3(%rip), %rdi      # 0xd1c0
leaq 0x7b2(%rip), %rdx       # 0x37d6
movl $0x4, %esi
movq %rax, %rcx
callq 0x72e0
movq %r14, 0x8(%rbx)
jmp 0x3041
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_free
static void butterfly_free(struct multiboot * p_mboot)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

    if (p_priv->p_device != NULL)
    {
        free(p_priv->p_device);
    }

    free(p_priv);
    free(p_mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3064
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_close
static int butterfly_close(struct multiboot * p_mboot)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

    if (p_priv->progmode_active)
    {
        butterfly_leave_progmode(p_priv);
    }

    butterfly_close_device(p_priv);

    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq 0x8(%rdi), %rbx
cmpb $0x0, 0x52(%rbx)
je 0x3423
cmpb $0x0, 0x4a(%rbx)
movl 0x44(%rbx), %edi
leaq 0x5066(%rip), %rax      # 0x8462
leaq 0x505d(%rip), %rsi      # 0x8460
cmoveq %rax, %rsi
movl $0x1, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x38d7
movl 0x44(%rbx), %edi
leaq 0x8(%rbx), %rdx
xorl %esi, %esi
callq 0x21f0
movl 0x44(%rbx), %edi
callq 0x2140
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_read
static int butterfly_read(struct multiboot * p_mboot,
                          struct databuf * p_dbuf,
                          int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "reading flash" : "reading eeprom";

    uint16_t pos = 0;
    uint16_t size = (memtype == 'F') ? p_priv->flashsize :
                                       p_priv->eepromsize;

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

    while (pos < size)
    {
        p_mboot->progress_cb(p_progress_msg, pos, size);

        uint16_t len = MIN(p_priv->buffersize, size - pos);
        if (butterfly_read_data(p_priv, p_dbuf->data + pos, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    p_dbuf->length = pos;

    p_mboot->progress_cb(p_progress_msg, pos, size);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %rbp
movq 0x8(%rdi), %rdi
xorl %eax, %eax
cmpl $0x46, %edx
setne %al
leaq 0x4ff9(%rip), %rcx      # 0x8464
leaq 0x5000(%rip), %r15      # 0x8472
cmoveq %rcx, %r15
movzwl 0x4e(%rdi,%rax,2), %ebx
movq %rdi, 0x20(%rsp)
callq 0x3a01
testl %eax, %eax
js 0x3547
movq %r15, 0x8(%rsp)
movq %r12, 0x10(%rsp)
leaq 0x8(%r12), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movzbl %r14b, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %r15
movzwl %r13w, %r14d
cmpw %bx, %r14w
jae 0x3520
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq *0x18(%rbp)
movq 0x20(%rsp), %rdi
movzwl 0x4c(%rdi), %eax
movq %rbp, %r12
movl %ebx, %ebp
subl %r14d, %ebp
cmpl %eax, %ebp
cmovgl %eax, %ebp
addq 0x18(%rsp), %r14
movzwl %bp, %edx
movq %r14, %rsi
movl 0x4(%rsp), %ecx
callq 0x3a84
movl %eax, %r14d
testl %eax, %eax
je 0x350b
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%r12)
jmp 0x3511
addl %r13d, %ebp
movl %ebp, %r13d
movq %r12, %rbp
testl %r14d, %r14d
je 0x34b1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3538
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq *0x18(%rbp)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2466
jmp 0x3519
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_verify
static int butterfly_verify(struct multiboot * p_mboot,
                            struct databuf * p_dbuf,
                            int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "verifing flash" : "verifing eeprom";

    uint16_t pos = 0;
    uint8_t comp[256];

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

    while (pos < p_dbuf->length)
    {
        p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);

        uint16_t len = MIN(p_priv->buffersize, p_dbuf->length - pos);
        if (butterfly_read_data(p_priv, comp, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

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

        pos += len;
    }

    p_dbuf->length = pos;

    p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %edx, %ebx
movq %rsi, %r13
movq %rdi, %r15
movq 0x8(%rdi), %rdi
cmpl $0x46, %edx
leaq 0x4f25(%rip), %rax      # 0x849a
leaq 0x4f2d(%rip), %rbp      # 0x84a9
cmoveq %rax, %rbp
movq %rdi, 0x28(%rsp)
callq 0x3a01
testl %eax, %eax
js 0x3678
movq %r15, 0x18(%rsp)
leaq 0x18(%r15), %r12
leaq 0x8(%r13), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x4(%rsp)
movzbl %bl, %eax
movl %eax, 0x14(%rsp)
leaq 0x30(%rsp), %r14
movq %r13, 0x8(%rsp)
movzwl 0x4(%rsp), %ebx
movl 0x4(%r13), %edx
cmpl %ebx, %edx
jbe 0x3661
movq %rbp, %rdi
movl %ebx, %esi
callq *(%r12)
movq 0x28(%rsp), %rdi
movzwl 0x4c(%rdi), %eax
movl 0x4(%r13), %r15d
subl %ebx, %r15d
cmpl %eax, %r15d
cmoval %eax, %r15d
movzwl %r15w, %r13d
movq %r14, %rsi
movl %r13d, %edx
movl 0x14(%rsp), %ecx
callq 0x3a84
testl %eax, %eax
je 0x361a
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *(%r12)
xorl %eax, %eax
jmp 0x363e
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x21d0
testl %eax, %eax
jne 0x3652
addl 0x4(%rsp), %r15d
movb $0x1, %al
movl %r15d, 0x4(%rsp)
movq 0x8(%rsp), %r13
testb %al, %al
leaq 0x30(%rsp), %r14
jne 0x35bd
jmp 0x367d
movq %r12, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x2482
jmp 0x3616
movl %ebx, 0x4(%r13)
movq %rbp, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x3682
callq 0x24ad
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_write
static int butterfly_write(struct multiboot * p_mboot,
                           struct databuf * p_dbuf,
                           int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "writing flash" : "writing eeprom";

    uint16_t pos = 0;

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

    while (pos < p_dbuf->length)
    {
        p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);

        uint16_t len = (memtype == 'F') ? p_priv->buffersize : WRITE_SIZE_EEPROM;

        len = MIN(len, p_dbuf->length - pos);

        if (butterfly_write_data(p_priv, p_dbuf->data + pos, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
movq 0x8(%rdi), %r15
cmpl $0x46, %edx
leaq 0x4e1e(%rip), %rax      # 0x84d8
leaq 0x4e25(%rip), %rcx      # 0x84e6
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %r15, %rdi
callq 0x3a01
testl %eax, %eax
js 0x37cf
leaq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
xorl %r12d, %r12d
movzwl %r12w, %r13d
movl 0x4(%r14), %edx
cmpl %r13d, %edx
jbe 0x37ae
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
movl $0x10, %eax
cmpl $0x46, %ebp
jne 0x3716
movzwl 0x4c(%r15), %eax
movl 0x4(%r14), %ebx
subl %r13d, %ebx
cmpl %ebx, %eax
cmovbl %eax, %ebx
addq 0x20(%rsp), %r13
movb $0x42, 0xc(%rsp)
movb %bh, 0xd(%rsp)
movb %bl, 0xe(%rsp)
movb %bpl, 0xf(%rsp)
movl 0x44(%r15), %edi
movl $0x4, %edx
leaq 0xc(%rsp), %rsi
callq 0x2090
movl 0x44(%r15), %edi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2090
movl 0x44(%r15), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x38d7
cmpl $0x1, %eax
sete %al
cmpb $0xd, 0xb(%rsp)
sete %r13b
andb %al, %r13b
je 0x3787
addl %ebx, %r12d
jmp 0x379e
movq 0x10(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rax
callq *0x18(%rax)
testb %r13b, %r13b
jne 0x36e6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x37c0
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x24c9
jmp 0x37a7
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_serial_read
static int butterfly_serial_read(int fd, void * data, int size,
                                 unsigned int timeout_ms)
{
    int pos = 0;

    while (1)
    {
        fd_set fdset;
        struct timeval timeout;
        struct timeval * p_timeout = NULL;

        FD_ZERO(&fdset);
        FD_SET(fd, &fdset);

        if (timeout_ms != 0)
        {
            p_timeout = &timeout;

            timeout.tv_sec = timeout_ms / 1000;
            timeout.tv_usec = (timeout_ms % 1000) * 1000;
        }

        int ret = select(fd +1, &fdset, NULL, NULL, p_timeout);
        if (ret == -1)
        {
            perror("select");
            return -1;
        }
        else if (ret == 0)
        {
            break;
        }
        else if (FD_ISSET(fd, &fdset))
        {
            int len = read(fd, data + pos, size - pos);
            if (len < 0)
            {
                return -1;
            }
            else
            {
                pos += len;
                if (pos == size)
                {
                    break;
                }
            }
        }
    }

    return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebx
movq %rsi, 0x8(%rsp)
movl %edi, %r15d
leal 0x3f(%r15), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %r13d
shlq %cl, %r13
sarl $0x6, %eax
movslq %eax, %r14
leal 0x1(%r15), %ebp
xorl %r12d, %r12d
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
orq %r13, 0x20(%rsp,%r14,8)
movq $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movl %ebp, %edi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x21b0
movl $0x3, %ecx
testl %eax, %eax
je 0x39c4
cmpl $-0x1, %eax
je 0x39ce
testq %r13, 0x20(%rsp,%r14,8)
je 0x39c2
movl %r12d, %esi
addq 0x8(%rsp), %rsi
movl %ebx, %eax
subl %r12d, %eax
movslq %eax, %rdx
movl %r15d, %edi
callq 0x2150
leal (%r12,%rax), %ecx
xorl %edx, %edx
cmpl %ebx, %ecx
sete %dl
testl %eax, %eax
cmovnsl %ecx, %r12d
leal (%rdx,%rdx,2), %ecx
movl $0x1, %eax
cmovsl %eax, %ecx
jmp 0x39c4
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x391a
jmp 0x39e1
leaq 0x4a82(%rip), %rdi      # 0x8457
callq 0x2230
movl $0x1, %ecx
jmp 0x39c4
cmpl $0x3, %ecx
je 0x39ec
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_set_address
static int butterfly_set_address(bfly_privdata_t * p_priv, uint16_t pos)
{
    uint8_t buffer[1];
    int result;

    (void)write(p_priv->fd, "a", 1);

    result = butterfly_serial_read(p_priv->fd, buffer, sizeof(buffer),
                                   SERIAL_TIMEOUT);
    if ((result == 1) &&
        (buffer[0] == 'Y')
       )
    {
        /* convert to word address */
        pos >>= 1;

        uint8_t cmd[3] = { 'A', pos >> 8, pos & 0xFF };
        (void)write(p_priv->fd, cmd, sizeof(cmd));

        result = butterfly_expect_cr(p_priv);
    }

    return result;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x44(%rdi), %edi
leaq 0x4a85(%rip), %rsi      # 0x8498
movl $0x1, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x38d7
cmpl $0x1, %eax
jne 0x3a7e
cmpb $0x59, 0xb(%rsp)
jne 0x3a7e
leaq 0xd(%rsp), %rsi
movw $0x41, (%rsi)
movb $0x0, 0x2(%rsi)
movl 0x44(%rbx), %edi
movl $0x3, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xc(%rsp), %rbx
movq %rbx, %rsi
movl $0x1, %edx
callq 0x38d7
cmpl $0x1, %eax
setne %al
cmpb $0xd, (%rbx)
setne %cl
orb %al, %cl
movzbl %cl, %eax
negl %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_read_data
static int butterfly_read_data(bfly_privdata_t * p_priv,
                               uint8_t * p_data, uint16_t size,
                               uint8_t memtype)
{
    int result;

    uint8_t cmd[4] = { 'g', size >> 8, size & 0xFF, memtype };
    (void)write(p_priv->fd, cmd, 4);

    result = butterfly_serial_read(p_priv->fd, p_data, size,
                                   SERIAL_TIMEOUT);
    return (result != size);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rsi
movb $0x67, (%rsi)
movb %bh, 0xd(%rsp)
movb %bl, 0x2(%rsi)
movb %cl, 0x3(%rsi)
movl 0x44(%rdi), %edi
movl $0x4, %edx
callq 0x2090
movl 0x44(%r15), %edi
movq %r14, %rsi
movl %ebx, %edx
callq 0x38d7
xorl %ecx, %ecx
cmpl %ebx, %eax
setne %cl
movl %ecx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/chipinfo_avr.c
// Function: chipinfo_get_by_signature
const avr_chipinfo_t * chipinfo_get_by_signature(const uint8_t *sig)
{
    unsigned int i;

    for (i = 0; i < ARRAY_SIZE(chips); i++)
    {
        avr_chipinfo_t *chip = &chips[i];

        if ((chip->sig[0] == sig[0]) &&
            (chip->sig[1] == sig[1]) &&
            (chip->sig[2] == sig[2])
           )
        {
            return chip;
        }
    }

    return NULL;
}

// Assembly:
movb (%rdi), %cl
xorl %edx, %edx
leaq 0x975d(%rip), %rsi      # 0xd240
cmpb %cl, (%rdx,%rsi)
jne 0x3b07
movb 0x1(%rdx,%rsi), %r8b
cmpb 0x1(%rdi), %r8b
jne 0x3b07
movb 0x2(%rdx,%rsi), %r8b
cmpb 0x2(%rdi), %r8b
jne 0x3b07
leaq (%rsi,%rdx), %rax
xorl %r8d, %r8d
jmp 0x3b0a
movb $0x1, %r8b
testb %r8b, %r8b
je 0x3b1e
addq $0x18, %rdx
cmpq $0xa8, %rdx
jne 0x3ae3
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_alloc
static struct multiboot * eprog_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

    memset(mboot, 0x00, sizeof(struct multiboot));
    mboot->ops= &eprog_ops;

    struct eprog_privdata *p_prog = malloc(sizeof(struct eprog_privdata));
    if (p_prog == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(p_prog, 0x00, sizeof(struct eprog_privdata));
    p_prog->device = NULL;

    optarg_register(eprog_optargs, ARRAY_SIZE(eprog_optargs),
                    eprog_optarg_cb, (void *)p_prog);

    mboot->privdata = p_prog;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x3bc7
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
leaq 0x978d(%rip), %rax      # 0xd2f0
movq %rax, (%rbx)
movl $0x78, %edi
callq 0x21c0
testq %rax, %rax
je 0x3bbf
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x70(%rax)
leaq 0x979b(%rip), %rdi      # 0xd340
leaq 0x6c8(%rip), %rdx       # 0x4274
movl $0x3, %esi
movq %rax, %rcx
callq 0x72e0
movq %r14, 0x8(%rbx)
jmp 0x3bc9
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_free
static void eprog_free(struct multiboot *mboot)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

    if (p_prog->device != NULL)
    {
        free(p_prog->device);
    }

    free(p_prog);
    free(mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3bec
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_close
static int eprog_close(struct multiboot *mboot)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

    if (p_prog->progmode == PROGMODE_ENABLED)
    {
        eprog_set_progmode(p_prog, PROGMODE_DISABLED);
    }

    eprog_close_device(p_prog);

    return 0;
}

// Assembly:
pushq %rbx
movq 0x8(%rdi), %rbx
cmpb $0x1, 0x70(%rbx)
jne 0x3f5c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x43f0
movq %rbx, %rdi
callq 0x43cb
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_read
static int eprog_read(struct multiboot *mboot,
                      struct databuf *dbuf, int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "reading EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;
    uint32_t size = p_prog->eprom_type * 1024;

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

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

        uint8_t len = MIN(p_prog->pagesize_max, size - pos);
        if (eprog_read_data(p_prog, dbuf->data + pos, len))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movzbl 0x69(%rdi), %ebp
movq %rdi, 0x20(%rsp)
callq 0x470b
testl %eax, %eax
js 0x4052
shll $0xa, %ebp
movq %r14, 0x8(%rsp)
leaq 0x8(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
leaq 0x4942(%rip), %r13      # 0x88f3
movq %rbx, 0x10(%rsp)
movl %ebp, %r14d
subl %r12d, %r14d
jbe 0x4029
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %r15d
movl %ebp, %edx
callq *0x18(%rbx)
movq 0x20(%rsp), %rdi
movzbl 0x68(%rdi), %eax
cmpl %eax, %r14d
cmoval %eax, %r14d
movl %r12d, %esi
addq 0x18(%rsp), %rsi
movq %rbx, %rbp
movq %r13, %rbx
movzbl %r14b, %r13d
movl %r13d, %edx
callq 0x4753
movl %eax, %r14d
testl %eax, %eax
je 0x400f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbp)
jmp 0x4012
addl %r13d, %r12d
movq %rbx, %r13
testl %r14d, %r14d
movq 0x10(%rsp), %rbx
movl %r15d, %ebp
je 0x3fb6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x4043
movq 0x8(%rsp), %rax
movl %r12d, 0x4(%rax)
leaq 0x48ba(%rip), %rdi      # 0x88f3
movl %r12d, %esi
movl %ebp, %edx
callq *0x18(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2625
jmp 0x4022
// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq %rdi, 0x18(%rsp)
callq 0x470b
testl %eax, %eax
js 0x414c
movq %rbx, 0x8(%rsp)
leaq 0x18(%rbx), %r12
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x4860(%rip), %rbx      # 0x8901
leaq 0x20(%rsp), %r13
movq %r12, (%rsp)
movl 0x4(%r14), %edx
cmpl %edx, %ebp
jae 0x4131
movq %rbx, %rdi
movl %ebp, %esi
callq *(%r12)
movq 0x18(%rsp), %rdi
movzbl 0x6a(%rdi), %eax
movl 0x4(%r14), %ecx
subl %ebp, %ecx
cmpl %eax, %ecx
cmoval %eax, %ecx
movzbl %cl, %r15d
movq %r13, %rsi
movl %r15d, %edx
callq 0x4753
testl %eax, %eax
je 0x40f7
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *(%r12)
xorl %eax, %eax
jmp 0x4116
movl %ebp, %esi
addq 0x10(%rsp), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x21d0
testl %eax, %eax
jne 0x4121
addl %r15d, %ebp
movb $0x1, %al
movq (%rsp), %r12
testb %al, %al
leaq 0x20(%rsp), %r13
jne 0x40aa
jmp 0x4151
movq (%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x2641
jmp 0x40f3
movl %ebp, 0x4(%r14)
leaq 0x47c5(%rip), %rdi      # 0x8901
movl %ebp, %esi
movl %ebp, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x4156
callq 0x2671
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_write
static int eprog_write(struct multiboot *mboot,
                       struct databuf *dbuf,
                       int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "writing EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;

    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_write_data(p_prog, dbuf->data + pos, len))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

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

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x470b
testl %eax, %eax
js 0x426d
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movl 0x4(%r14), %edx
leaq 0x4769(%rip), %rdi      # 0x8910
cmpl %edx, %r12d
jae 0x4256
movl %r12d, %esi
callq *0x18(%rbx)
movzbl 0x6a(%r15), %eax
movl 0x4(%r14), %ebp
subl %r12d, %ebp
cmpl %eax, %ebp
cmoval %eax, %ebp
movb $0x6, 0xe(%rsp)
movb %bpl, 0xf(%rsp)
movl 0x44(%r15), %edi
movl $0x2, %edx
leaq 0xe(%rsp), %rsi
callq 0x2090
movq %rax, %r13
movzbl %bpl, %ebp
testl %r13d, %r13d
jle 0x4228
movl %r12d, %esi
addq 0x10(%rsp), %rsi
movl 0x44(%r15), %edi
movq %rbp, %rdx
callq 0x2090
movq %rax, %r13
testl %r13d, %r13d
jle 0x4228
movl 0x44(%r15), %edi
movl $0x86, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x45ad
movl %eax, %r13d
sarl $0x1f, %r13d
andl %eax, %r13d
testl %r13d, %r13d
je 0x4243
leaq 0x46dc(%rip), %rdi      # 0x8910
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
jmp 0x4246
addl %ebp, %r12d
testl %r13d, %r13d
je 0x419c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x425e
movl %r12d, %esi
callq *0x18(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x268d
jmp 0x424f
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_set_progmode
static int eprog_set_progmode(struct eprog_privdata *p_prog,
                              uint8_t progmode)
{
    uint8_t request[] = { MSGTYPE_PROGMODE_REQ, 1, progmode };

    int ret = write(p_prog->fd, request, sizeof(request));
    if (ret <= 0)
    {
        return ret;
    }

    ret = eprog_recv(p_prog->fd, MSGTYPE_PROGMODE_RSP, NULL, 0);
    if (ret < 0)
    {
        return ret;
    }

    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xd(%rsp), %rax
movw $0x104, (%rax)          # imm = 0x104
movb %sil, 0x2(%rax)
movl 0x44(%rdi), %edi
movl $0x3, %edx
movq %rax, %rsi
callq 0x2090
testl %eax, %eax
jle 0x4434
movl 0x44(%rbx), %edi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x45ad
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x4434
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_set_address
static int eprog_set_address(struct eprog_privdata *p_prog,
                             uint32_t address)
{
    uint8_t request[] = { MSGTYPE_SETADDRESS_REQ, 3,
                          (address >> 16) & 0xFF,
                          (address >> 8) & 0xFF,
                          (address >> 0) & 0xFF };

    int ret = write(p_prog->fd, request, sizeof(request));
    if (ret <= 0)
    {
        return ret;
    }

    ret = eprog_recv(p_prog->fd, MSGTYPE_SETADDRESS_RSP, NULL, 0);
    if (ret < 0)
    {
        return ret;
    }

    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xb(%rsp), %rsi
movl $0x305, (%rsi)          # imm = 0x305
movb $0x0, 0x4(%rsi)
movl 0x44(%rdi), %edi
movl $0x5, %edx
callq 0x2090
testl %eax, %eax
jle 0x474d
movl 0x44(%rbx), %edi
movl $0x85, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x45ad
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x474d
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_read_data
static int eprog_read_data(struct eprog_privdata *p_prog,
                           uint8_t * data,
                           uint8_t length)
{
    uint8_t request[] = { MSGTYPE_READ_REQ, 1, length };

    int ret = write(p_prog->fd, request, sizeof(request));
    if (ret <= 0)
    {
        return ret;
    }

    ret = eprog_recv(p_prog->fd, MSGTYPE_READ_RSP, data, length);
    if (ret < 0)
    {
        return ret;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xd(%rsp), %rsi
movw $0x107, (%rsi)          # imm = 0x107
movb %bpl, 0x2(%rsi)
movl 0x44(%rdi), %edi
movl $0x3, %edx
callq 0x2090
testl %eax, %eax
jle 0x47a0
movl 0x44(%r14), %edi
movzbl %bpl, %ecx
movl $0x87, %esi
movq %rbx, %rdx
callq 0x45ad
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x47a0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/filedata.c
// Function: dbuf_alloc
struct databuf * dbuf_alloc(uint32_t size)
{
    struct databuf *dbuf = malloc(sizeof(struct databuf) + size);
    if (dbuf == NULL)
    {
        perror("dbuf_alloc");
        return NULL;
    }

    memset(dbuf->data, 0xFF, size);
    dbuf->size = size;
    dbuf->length = 0;
    return dbuf;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edi, %ebp
movl %edi, %r14d
leaq 0x8(%r14), %rdi
callq 0x21c0
testq %rax, %rax
je 0x47eb
movq %rax, %rbx
movq %rax, %rdi
addq $0x8, %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x2120
movl %ebp, (%rbx)
movl $0x0, 0x4(%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x412c(%rip), %rdi      # 0x891e
callq 0x2230
xorl %ebx, %ebx
jmp 0x47e3
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/filedata.c
// Function: file_getsize
int file_getsize(const char *filename, uint32_t *size)
{
    switch (get_filetype(filename))
    {
        case FILETYPE_BINARY:
            return binfile_getsize(filename, size);

        case FILETYPE_INTELHEX:
            return hexfile_getsize(filename, size);

        default:
            return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movq %rdi, %r15
callq 0x4895
cmpl $0x2, %eax
je 0x485b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x1, %eax
jne 0x4864
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2200
testl %eax, %eax
js 0x4874
movl %eax, %ebp
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x22a0
testl %eax, %eax
js 0x4882
movl 0x38(%rsp), %eax
movl %eax, (%r14)
xorl %ebx, %ebx
movl %ebp, %edi
callq 0x2140
jmp 0x4864
movl $0x10000, (%r14)        # imm = 0x10000
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40b8(%rip), %rdi      # 0x8933
callq 0x2230
jmp 0x4864
leaq 0x40c4(%rip), %rdi      # 0x894d
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4852
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/filedata.c
// Function: get_filetype
static int get_filetype(const char *filename)
{
    const char *ext = filename + (strlen(filename) -4);

    if (ext < filename)
    {
        return FILETYPE_UNKNOWN;
    }

    if (strncmp(ext, ".bin", 4) == 0)
    {
        return FILETYPE_BINARY;
    }

    if (strncmp(ext, ".hex", 4) == 0)
    {
        return FILETYPE_INTELHEX;
    }

    return FILETYPE_UNKNOWN;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
callq 0x20c0
leaq (%r14,%rax), %rbx
addq $-0x4, %rbx
xorl %eax, %eax
cmpq %r14, %rbx
jb 0x48ee
leaq 0x4072(%rip), %rsi      # 0x8929
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2070
testl %eax, %eax
je 0x48e9
leaq 0x405f(%rip), %rsi      # 0x892e
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2070
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
addl %eax, %eax
jmp 0x48ee
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/filedata.c
// Function: hexfile_putrecord
static int hexfile_putrecord(FILE *stream, struct ihex_record *record)
{
    uint8_t chksum = record->byte_count;
    chksum += (record->address >> 8) & 0xFF;
    chksum += (record->address & 0xFF);
    chksum += record->type;

    int i, len = 0;
    char buf[64];

    buf[0] = '\0';
    for (i = 0; i < record->byte_count; i++)
    {
        len += snprintf(buf + len, sizeof(buf) - len, "%02X", record->data[i]);
        chksum += record->data[i];
    }

    fprintf(stream, ":%02X%04X%02X%s%02X\n",
            record->byte_count,
            record->address,
            record->type,
            buf,
            (uint8_t)(0x100 - chksum));

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movzwl 0x2(%rsi), %ebp
movl %ebp, %eax
shrl $0x8, %eax
addb (%rsi), %bpl
addb 0x4(%rsi), %bpl
addb %al, %bpl
movb $0x0, 0x10(%rsp)
movb (%rsi), %al
testb %al, %al
je 0x504d
leaq 0x3a4d(%rip), %r15      # 0x8a57
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq %r13d, %r13
leaq (%rsp,%r13), %rdi
addq $0x10, %rdi
movl $0x40, %esi
subq %r13, %rsi
movq 0x8(%r14), %rax
movzbl (%rax,%r12), %ecx
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
movq 0x8(%r14), %rcx
addb (%rcx,%r12), %bpl
addl %eax, %r13d
incq %r12
movzbl (%r14), %eax
cmpq %rax, %r12
jb 0x5010
movzbl %al, %edx
movzwl 0x2(%r14), %ecx
movzbl 0x4(%r14), %r8d
negb %bpl
movzbl %bpl, %eax
movl %eax, (%rsp)
leaq 0x3a49(%rip), %rsi      # 0x8ab4
leaq 0x10(%rsp), %r9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2170
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_alloc
static struct multiboot * funk_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

    memset(mboot, 0x00, sizeof(struct multiboot));
    mboot->ops = &funk_ops;

    struct funk_privdata *funk = malloc(sizeof(struct funk_privdata));
    if (funk == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(funk, 0x00, sizeof(struct funk_privdata));
    funk->device = NULL;
    funk->address = 0;

    optarg_register(funk_optargs, ARRAY_SIZE(funk_optargs), funk_optarg_cb, (void *)funk);

    mboot->privdata = funk;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x5113
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
leaq 0x833d(%rip), %rax      # 0xd3f0
movq %rax, (%rbx)
movl $0x68, %edi
callq 0x21c0
testq %rax, %rax
je 0x510b
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x60(%rax)
leaq 0x834f(%rip), %rdi      # 0xd440
leaq 0x858(%rip), %rdx       # 0x5950
movl $0x2, %esi
movq %rax, %rcx
callq 0x72e0
movq %r14, 0x8(%rbx)
jmp 0x5115
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_free
static void funk_free(struct multiboot *mboot)
{
    struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;

    if (funk->device != NULL)
    {
        free(funk->device);
    }

    free(funk);
    free(mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x5138
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_close
static int funk_close(struct multiboot *mboot)
{
    struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;

    if (funk->connected)
    {
        funk_switch_application(funk, BOOTTYPE_APPLICATION);
    }

    funk_close_device(funk);
    return 0;
}

// Assembly:
pushq %rbx
movq 0x8(%rdi), %rbx
cmpl $0x0, 0xc(%rbx)
je 0x5543
movq %rbx, %rdi
movl $0x80, %esi
callq 0x5a13
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x22b0
movl 0x8(%rbx), %edi
leaq 0x28(%rbx), %rdx
xorl %esi, %esi
callq 0x21f0
movl 0x8(%rbx), %edi
callq 0x2140
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_read
static int funk_read(struct multiboot *mboot,
                     struct databuf *dbuf,
                     int memtype)
{
    struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "reading flash" : "reading eeprom";

    uint16_t pos = 0;
    uint16_t size = (memtype == MEMTYPE_FLASH) ? funk->flashsize : funk->eepromsize;

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

        uint16_t len = MIN(READ_BLOCK_SIZE, size - pos);
        if (funk_read_memory(funk, dbuf->data + pos, len, memtype, pos))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x2ed9(%rip), %rcx      # 0x8464
leaq 0x2ee0(%rip), %r12      # 0x8472
cmoveq %rcx, %r12
movq %rdi, 0x20(%rsp)
movzwl 0x1c(%rdi,%rax,8), %r13d
movq %rsi, 0x10(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movzbl %dl, %eax
movl %eax, 0xc(%rsp)
movzwl %r15w, %r14d
movl %r13d, %ebp
subl %r14d, %ebp
jbe 0x5621
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
cmpl $0x20, %ebp
movl $0x20, %eax
cmovgel %eax, %ebp
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %rsi
movzwl %bp, %edx
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %ecx
movl %r14d, %r8d
callq 0x5e25
movl %eax, %r14d
testl %eax, %eax
je 0x5612
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
jmp 0x5615
addl %ebp, %r15d
testl %r14d, %r14d
je 0x55b9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x5638
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_verify
static int funk_verify(struct multiboot *mboot,
                       struct databuf *dbuf,
                       int memtype)
{
    struct funk_privdata *funk = (struct funk_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 (funk_read_memory(funk, 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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0x2e2f(%rip), %rax      # 0x849a
leaq 0x2e37(%rip), %rbp      # 0x84a9
cmoveq %rax, %rbp
movq %rdi, 0x8(%rsp)
leaq 0x18(%rdi), %r12
leaq 0x8(%rsi), %rax
movq %rax, 0x10(%rsp)
movl $0x0, (%rsp)
movzbl %dl, %eax
movl %eax, 0x4(%rsp)
leaq 0x20(%rsp), %r13
movzwl (%rsp), %ebx
movl 0x4(%r14), %edx
cmpl %ebx, %edx
jbe 0x573e
movq %rbp, %rdi
movl %ebx, %esi
callq *(%r12)
movq %r12, %r15
movl 0x4(%r14), %r12d
subl %ebx, %r12d
cmpl $0x20, %r12d
movl $0x20, %eax
cmovael %eax, %r12d
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
callq 0x5e25
testl %eax, %eax
je 0x56fa
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *(%r15)
xorl %eax, %eax
jmp 0x5718
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rsi
movl %r12d, %edx
movq %r13, %rdi
callq 0x21d0
testl %eax, %eax
jne 0x572a
addl %r12d, (%rsp)
movb $0x1, %al
movq %r15, %r12
testb %al, %al
leaq 0x20(%rsp), %r13
jne 0x569b
jmp 0x5755
movq %r15, %r12
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x2943
xorl %eax, %eax
jmp 0x571b
movl %ebx, 0x4(%r14)
movq %rbp, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x575a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_optarg_cb
static int funk_optarg_cb(int val, const char *arg, void *privdata)
{
    struct funk_privdata *funk = (struct funk_privdata *)privdata;

    switch (val)
    {
        case 'a': /* address */
            {
                char *endptr;

                funk->address = strtol(arg, &endptr, 16);
                if (*endptr != '\0' || funk->address < 0x00 || funk->address > 0xFF) {
                    fprintf(stderr, "invalid address: '%s'\n", arg);
                    return -1;
                }
            }
            break;

        case 'd': /* device */
            if (funk->device != NULL) {
                fprintf(stderr, "invalid device: '%s'\n", optarg);
                return -1;
            }

            funk->device = strdup(optarg);
            if (funk->device == NULL) {
                perror("strdup()");
                return -1;
            }
            break;

        case 'h':
        case '?': /* error */
            fprintf(stderr, "Usage: funkboot [options]\n"
                "  -a <address>                 - selects rfm12 address (0x00 - 0xFF)\n"
                "  -d <device>                  - selects funkbridge device\n"
                "  -r <flash|eeprom>:<file>     - reads flash/eeprom to file   (.bin | .hex | -)\n"
                "  -w <flash|eeprom>:<file>     - write flash/eeprom from file (.bin | .hex)\n"
                "  -n                           - disable verify after write\n"
                "  -p <0|1|2>                   - progress bar mode\n"
                "\n"
                "Example: funkboot -d /dev/ttyUSB0 -a 0x22 -w flash:blmc.hex -w eeprom:blmc_eeprom.hex\n"
                "\n");
            return -1;

        default:
            return 1;
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movl $0x1, %eax
cmpl $0x63, %edi
jg 0x599a
cmpl $0x61, %edi
jne 0x59cf
movq %rsi, %rbx
leaq 0x8(%rsp), %r15
movq %rsi, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x2190
movl %eax, 0x10(%r14)
movq (%r15), %rcx
cmpb $0x0, (%rcx)
jne 0x59e9
cmpl $0x100, %eax            # imm = 0x100
jae 0x59e9
xorl %eax, %eax
jmp 0x5a09
cmpl $0x64, %edi
jne 0x59d6
cmpq $0x0, (%r14)
jne 0x59e2
movq 0x7624(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2280
movq %rax, %rcx
movq %rax, (%r14)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x5a09
leaq 0x26b2(%rip), %rdi      # 0x807a
callq 0x2230
jmp 0x5a04
cmpl $0x3f, %edi
jne 0x5a09
jmp 0x59db
cmpl $0x68, %edi
jne 0x5a09
callq 0x296e
jmp 0x5a04
callq 0x298c
jmp 0x5a04
movq 0x7608(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x2653(%rip), %rsi      # 0x804d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2170
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_switch_application
static int funk_switch_application(struct funk_privdata *funk,
                                   uint8_t application)
{
    struct rfm12_pkt packet;

    packet.dest_address         = funk->address;
    packet.source_address       = 0xCC;             // TODO: changed in bridge
    packet.data_length          = 0x04;
    packet.header_checksum      = 0xCC;             // TODO: calced in bridge
    packet.msg.command          = MSG_CMD_SWITCHAPP_REQUEST;
    packet.msg.seqnum           = ++funk->seqnum;   // TODO: retransmit in bridge?
    packet.msg.cause            = CAUSE_SUCCESS;
    packet.msg.p.switchapp.app  = application;

    int ret = funk_send_packet(funk, &packet, 4 + packet.data_length);
    if (ret < 0)
    {
        fprintf(stderr, "funk_switch_application(): funk_send_packet()\n");
        return ret;
    }

    int response_size = sizeof(packet);
    ret = funk_recv_packet(funk, &packet, &response_size);
    if (ret < 0)
    {
        fprintf(stderr, "funk_switch_application(): funk_recv_packet()\n");
        return ret;
    }

    if ((packet.msg.command != MSG_CMD_SWITCHAPP_RESPONSE) ||
        (packet.msg.cause != CAUSE_SUCCESS)
       )
    {
        return -1;
    }

    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movb 0x10(%rdi), %cl
leaq 0xd(%rsp), %rax
movb %cl, (%rax)
movl $0x20cc04cc, 0x1(%rax)  # imm = 0x20CC04CC
movl 0x18(%rdi), %ecx
incl %ecx
movl %ecx, 0x18(%rdi)
movb %cl, 0x5(%rax)
movb $0x0, 0x6(%rax)
movb %sil, 0x7(%rax)
movq %rax, %rsi
movl $0x8, %edx
callq 0x5d4a
testl %eax, %eax
js 0x5a89
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %r14, %rdi
callq 0x5db2
testl %eax, %eax
js 0x5a92
movb 0x11(%rsp), %al
xorb $-0x20, %al
xorl %ebx, %ebx
orb 0x13(%rsp), %al
setne %bl
negl %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
retq
movl %eax, %ebx
callq 0x29d0
jmp 0x5a7f
movl %eax, %ebx
callq 0x29ae
jmp 0x5a7f