LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_mcg_64_xsl_rr_32_boundedrand_r
inline uint32_t pcg_mcg_64_xsl_rr_32_boundedrand_r(struct pcg_state_64* rng,
                                                   uint32_t bound)
{
    uint32_t threshold = -bound % bound;
    for (;;) {
        uint32_t r = pcg_mcg_64_xsl_rr_32_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
movl %esi, %eax
negl %eax
xorl %edx, %edx
divl %esi
movq (%rdi), %r8
movabsq $0x5851f42d4c957f2d, %r9 # imm = 0x5851F42D4C957F2D
movq %r8, %rcx
imulq %r9, %r8
movq %rcx, %rax
shrq $0x20, %rax
xorl %ecx, %eax
shrq $0x3b, %rcx
rorl %cl, %eax
cmpl %edx, %eax
jb 0x203f
movq %r8, (%rdi)
xorl %edx, %edx
divl %esi
movl %edx, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_oneseq_64_xsl_rr_rr_64_boundedrand_r
inline uint64_t
pcg_oneseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64* rng,
                                         uint64_t bound)
{
    uint64_t threshold = -bound % bound;
    for (;;) {
        uint64_t r = pcg_oneseq_64_xsl_rr_rr_64_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rax
negq %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movq %r14, %rdi
callq 0x2063
cmpq %r15, %rax
jb 0x20bb
xorl %edx, %edx
divq %rbx
movq %rdx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_unique_64_xsl_rr_rr_64_boundedrand_r
inline uint64_t
pcg_unique_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_64* rng,
                                         uint64_t bound)
{
    uint64_t threshold = -bound % bound;
    for (;;) {
        uint64_t r = pcg_unique_64_xsl_rr_rr_64_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rax
negq %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movq %r14, %rdi
callq 0x20d6
cmpq %r15, %rax
jb 0x212b
xorl %edx, %edx
divq %rbx
movq %rdx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_setseq_64_xsl_rr_rr_64_boundedrand_r
inline uint64_t
pcg_setseq_64_xsl_rr_rr_64_boundedrand_r(struct pcg_state_setseq_64* rng,
                                         uint64_t bound)
{
    uint64_t threshold = -bound % bound;
    for (;;) {
        uint64_t r = pcg_setseq_64_xsl_rr_rr_64_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rax
negq %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movq %r14, %rdi
callq 0x2146
cmpq %r15, %rax
jb 0x2195
xorl %edx, %edx
divq %rbx
movq %rdx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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:
xorl %r8d, %r8d
pushq $0x1
popq %r9
movl %r9d, %eax
testl %esi, %esi
je 0x21ea
movl %r8d, %r10d
imull %edx, %r10d
addl %ecx, %r10d
testb $0x1, %sil
movl %edx, %r11d
cmovel %r9d, %r11d
cmovnel %r10d, %r8d
imull %r11d, %eax
leal 0x1(%rdx), %r10d
imull %r10d, %ecx
imull %edx, %edx
shrl %esi
jmp 0x21ba
imull %edi, %eax
addl %r8d, %eax
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/src/pcg-advance-64.c
// Function: pcg_advance_lcg_64
uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta, uint64_t cur_mult,
                            uint64_t cur_plus)
{
    uint64_t acc_mult = 1u;
    uint64_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:
pushq $0x1
popq %rax
xorl %r8d, %r8d
testq %rsi, %rsi
je 0x2221
testb $0x1, %sil
je 0x2210
imulq %rdx, %rax
imulq %rdx, %r8
addq %rcx, %r8
leaq 0x1(%rdx), %r9
imulq %r9, %rcx
imulq %rdx, %rdx
shrq %rsi
jmp 0x21fa
imulq %rdi, %rax
addq %r8, %rax
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x2427
movq %rax, %rbx
leaq 0xad96(%rip), %rax      # 0xd180
movq %rax, (%rbx)
pushq $0x1
popq %rdi
pushq $0x58
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x241f
movq %rax, %r14
leaq 0xadc9(%rip), %rdi      # 0xd1d0
leaq 0x789(%rip), %rdx       # 0x2b97
pushq $0x4
popq %rsi
movq %rax, %rcx
callq 0x6544
movq %r14, 0x8(%rbx)
jmp 0x2429
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_O2/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
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_O2/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
movq 0x8(%rdi), %rbx
cmpb $0x0, 0x52(%rbx)
je 0x2805
cmpb $0x0, 0x4a(%rbx)
movl 0x44(%rbx), %edi
leaq 0x5c78(%rip), %rax      # 0x8462
leaq 0x5c6f(%rip), %rsi      # 0x8460
cmoveq %rax, %rsi
pushq $0x1
popq %rdx
callq 0x2090
movq %rbx, %rdi
callq 0x2cae
movq %rbx, %rdi
callq 0x2c93
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movl %edx, %r14d
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r12
xorl %eax, %eax
cmpl $0x46, %edx
setne %al
leaq 0x5c27(%rip), %rcx      # 0x8464
leaq 0x5c2e(%rip), %rdx      # 0x8472
cmoveq %rcx, %rdx
movq %rdx, (%rsp)
movzwl 0x4e(%r12,%rax,2), %r15d
movq %r12, %rdi
callq 0x2dc5
testl %eax, %eax
js 0x28fc
movq %rbx, 0x10(%rsp)
addq $0x8, %rbx
xorl %ebp, %ebp
movzbl %r14b, %r13d
movzwl %bp, %r14d
cmpw %r15w, %r14w
jae 0x28ce
movq (%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movzwl 0x4c(%r12), %eax
movl %r15d, %ebp
subl %r14d, %ebp
cmpl %eax, %ebp
cmovgl %eax, %ebp
movl %r14d, %esi
addq %rbx, %rsi
movzwl %bp, %edx
movq %r12, %rdi
movl %r13d, %ecx
callq 0x2e27
addl %r14d, %ebp
testl %eax, %eax
je 0x2871
pushq $-0x1
popq %rbp
movq (%rsp), %rdi
movl %ebp, %esi
movl %ebp, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
jmp 0x28eb
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq (%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa6f5(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x5b74(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %rbp
jmp 0x28eb
// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %r12
cmpl $0x46, %edx
leaq 0x5b54(%rip), %rax      # 0x849a
leaq 0x5b5c(%rip), %rcx      # 0x84a9
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %r12, %rdi
callq 0x2dc5
testl %eax, %eax
js 0x2a53
leaq 0x8(%r15), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movzbl %bl, %ebp
leaq 0x20(%rsp), %rbx
movzwl %cx, %r13d
movl 0x4(%r15), %edx
cmpl %r13d, %edx
jbe 0x2a10
movq 0x8(%rsp), %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rax
callq *0x18(%rax)
movzwl 0x4c(%r12), %eax
movl 0x4(%r15), %ecx
subl %r13d, %ecx
cmpl %eax, %ecx
cmoval %eax, %ecx
movzwl %cx, %r14d
movq %r12, %rdi
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x2e27
testl %eax, %eax
jne 0x2a2b
movl %r13d, %esi
addq 0x18(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x21e0
leal (%r14,%r13), %ecx
testl %eax, %eax
je 0x2979
pushq $-0x1
popq %rbx
movq 0x8(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x10(%rsp), %rax
callq *0x18(%rax)
movq 0xa5fe(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x5ab5(%rip), %rsi      # 0x84b9
movl %r13d, %edx
xorl %eax, %eax
callq 0x2180
jmp 0x2a3f
movl %r13d, 0x4(%r15)
movq 0x8(%rsp), %rdi
movl %r13d, %esi
movl %r13d, %edx
movq 0x10(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x2a3f
pushq $-0x1
popq %rbx
movq 0x8(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x10(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa59e(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x5a1d(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %rbx
jmp 0x2a3f
// File: /workspace/github_c_makefile_star2_O2/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), %r12
cmpl $0x46, %edx
leaq 0x5a3e(%rip), %rax      # 0x84d8
leaq 0x5a45(%rip), %rcx      # 0x84e6
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %r12, %rdi
callq 0x2dc5
testl %eax, %eax
js 0x2b76
leaq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movzwl %bx, %r13d
movl 0x4(%r14), %ebx
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
cmpl %r13d, %ebx
jbe 0x2b63
pushq $0x10
popq %rax
cmpl $0x46, %ebp
jne 0x2af2
movzwl 0x4c(%r12), %eax
movl 0x4(%r14), %ebx
subl %r13d, %ebx
cmpl %ebx, %eax
cmovbl %eax, %ebx
movl %r13d, %r15d
addq 0x20(%rsp), %r15
movb $0x42, 0xc(%rsp)
movb %bh, 0xd(%rsp)
movb %bl, 0xe(%rsp)
movb %bpl, 0xf(%rsp)
movl 0x44(%r12), %edi
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2090
movl 0x44(%r12), %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2090
movq %r12, %rdi
callq 0x2cae
addl %r13d, %ebx
testl %eax, %eax
je 0x2ac5
pushq $-0x1
popq %rbx
movq 0x10(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
jmp 0x2b65
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa47b(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x58fa(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %rbx
jmp 0x2b65
// File: /workspace/github_c_makefile_star2_O2/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_expect_cr
static int butterfly_expect_cr(bfly_privdata_t * p_priv)
{
    uint8_t buffer[1];
    int result;

    result = butterfly_serial_read(p_priv->fd, buffer, sizeof(buffer),
                                   SERIAL_TIMEOUT);
    if ((result == sizeof(buffer)) &&
        (buffer[0] == '\r')
       )
    {
        return 0;
    }

    return -1;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl 0x44(%rdi), %edi
leaq 0xf(%rsp), %rbx
pushq $0x1
popq %rdx
movq %rbx, %rsi
callq 0x2cdf
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_O2/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 $0x98, %rsp
movl %edx, %ebx
movq %rsi, (%rsp)
movl %edi, %r12d
pushq $0x40
popq %rcx
movl %edi, %eax
cltd
idivl %ecx
movslq %eax, %r13
shll $0x6, %eax
movl %edi, %ecx
subl %eax, %ecx
pushq $0x1
popq %r14
shlq %cl, %r14
leal 0x1(%r12), %ebp
xorl %r15d, %r15d
xorl %eax, %eax
cmpq $0x10, %rax
je 0x2d2d
andq $0x0, 0x18(%rsp,%rax,8)
incq %rax
jmp 0x2d1c
orq %r14, 0x18(%rsp,%r13,8)
movq $0x1, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movl %ebp, %edi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x8(%rsp), %r8
callq 0x21c0
testl %eax, %eax
je 0x2da2
cmpl $-0x1, %eax
je 0x2db7
testq %r14, 0x18(%rsp,%r13,8)
je 0x2d93
movl %r15d, %esi
addq (%rsp), %rsi
movl %ebx, %eax
subl %r15d, %eax
movslq %eax, %rdx
movl %r12d, %edi
callq 0x2150
addl %eax, %r15d
xorl %ecx, %ecx
cmpl %ebx, %r15d
sete %dl
testl %eax, %eax
js 0x2d9e
movb %dl, %cl
leal (%rcx,%rcx,2), %eax
jmp 0x2d95
xorl %eax, %eax
testl %eax, %eax
je 0x2d1a
cmpl $0x3, %eax
je 0x2da2
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5699(%rip), %rdi      # 0x8457
callq 0x2240
jmp 0x2d9e
// File: /workspace/github_c_makefile_star2_O2/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 0x56c1(%rip), %rsi      # 0x8498
pushq $0x1
popq %rdx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xc(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2cdf
cmpl $0x1, %eax
jne 0x2e21
cmpb $0x59, 0xc(%rsp)
jne 0x2e21
leaq 0xd(%rsp), %rsi
movw $0x41, (%rsi)
movb $0x0, 0x2(%rsi)
movl 0x44(%rbx), %edi
pushq $0x3
popq %rdx
callq 0x2090
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
jmp 0x2cae
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x4
popq %rdx
callq 0x2090
movl 0x44(%r15), %edi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2cdf
xorl %ecx, %ecx
cmpl %ebx, %eax
setne %cl
movl %ecx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_c_makefile_star2_O2/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:
xorl %eax, %eax
leaq 0xa3cf(%rip), %rcx      # 0xd250
xorl %edx, %edx
cmpq $0xa8, %rdx
je 0x2eb7
movb (%rdx,%rcx), %sil
cmpb (%rdi), %sil
jne 0x2eab
movb 0x1(%rdx,%rcx), %sil
cmpb 0x1(%rdi), %sil
jne 0x2eab
movb 0x2(%rdx,%rcx), %sil
cmpb 0x2(%rdi), %sil
je 0x2eb1
addq $0x18, %rdx
jmp 0x2e83
addq %rdx, %rcx
movq %rcx, %rax
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x2f2f
movq %rax, %rbx
leaq 0xa40e(%rip), %rax      # 0xd300
movq %rax, (%rbx)
pushq $0x1
popq %rdi
pushq $0x78
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x2f27
movq %rax, %r14
leaq 0xa441(%rip), %rdi      # 0xd350
leaq 0x70d(%rip), %rdx       # 0x3623
pushq $0x3
popq %rsi
movq %rax, %rcx
callq 0x6544
movq %r14, 0x8(%rbx)
jmp 0x2f31
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_O2/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 0x3303
movq %rbx, %rdi
xorl %esi, %esi
callq 0x37ae
movq %rbx, %rdi
callq 0x3789
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movzbl 0x69(%r15), %ebp
movq %r15, %rdi
callq 0x3a78
testl %eax, %eax
js 0x33c3
shll $0xa, %ebp
movq %r14, (%rsp)
leaq 0x8(%r14), %r13
xorl %r12d, %r12d
movl %ebp, %r14d
subl %r12d, %r14d
jbe 0x3399
leaq 0x559d(%rip), %rdi      # 0x88f3
movl %r12d, %esi
movl %ebp, %edx
callq *0x18(%rbx)
movzbl 0x68(%r15), %eax
cmpl %eax, %r14d
cmoval %eax, %r14d
movl %r12d, %esi
addq %r13, %rsi
movzbl %r14b, %r14d
movq %r15, %rdi
movl %r14d, %edx
callq 0x3abe
addl %r14d, %r12d
testl %eax, %eax
je 0x3347
leaq 0x5566(%rip), %rdi      # 0x88f3
pushq $-0x1
popq %rbp
movl %ebp, %esi
movl %ebp, %edx
callq *0x18(%rbx)
jmp 0x33b2
movq (%rsp), %rax
movl %r12d, 0x4(%rax)
leaq 0x554b(%rip), %rdi      # 0x88f3
movl %r12d, %esi
movl %ebp, %edx
callq *0x18(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9c2e(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x50ad(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %rbp
jmp 0x33b2
// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x3a78
testl %eax, %eax
js 0x34fa
leaq 0x8(%r14), %rbx
xorl %r12d, %r12d
leaq 0x10(%rsp), %r13
movl %r12d, %ebp
movl 0x4(%r14), %edx
cmpl %edx, %r12d
jae 0x34b0
leaq 0x54cd(%rip), %rdi      # 0x8901
movl %ebp, %esi
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movzbl 0x6a(%r15), %eax
movl 0x4(%r14), %ecx
subl %ebp, %ecx
cmpl %eax, %ecx
cmoval %eax, %ecx
movzbl %cl, %r12d
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x3abe
testl %eax, %eax
jne 0x34cc
movl %ebp, %esi
addq %rbx, %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0x21e0
addl %ebp, %r12d
testl %eax, %eax
je 0x341d
leaq 0x547f(%rip), %rdi      # 0x8901
pushq $-0x1
popq %r14
movl %r14d, %esi
movl %r14d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movq 0x9b5d(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x5014(%rip), %rsi      # 0x84b9
movl %ebp, %edx
xorl %eax, %eax
callq 0x2180
jmp 0x34e5
movl %ebp, 0x4(%r14)
leaq 0x5446(%rip), %rdi      # 0x8901
movl %ebp, %esi
movl %ebp, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %r14d, %r14d
jmp 0x34e5
leaq 0x542e(%rip), %rdi      # 0x8901
pushq $-0x1
popq %r14
movl %r14d, %esi
movl %r14d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %r14d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9af7(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4f76(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %r14
jmp 0x34e5
// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq %r12, %rdi
callq 0x3a78
testl %eax, %eax
js 0x3601
leaq 0x8(%r15), %r13
xorl %ebp, %ebp
movl 0x4(%r15), %r14d
leaq 0x53be(%rip), %rdi      # 0x8910
movl %ebp, %esi
movl %r14d, %edx
callq *0x18(%rbx)
cmpl %r14d, %ebp
jae 0x35ec
movzbl 0x6a(%r12), %eax
movl 0x4(%r15), %r14d
subl %ebp, %r14d
cmpl %eax, %r14d
cmoval %eax, %r14d
movb $0x6, 0x6(%rsp)
movb %r14b, 0x7(%rsp)
movl 0x44(%r12), %edi
leaq 0x6(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x2090
movzbl %r14b, %r14d
testl %eax, %eax
jle 0x35cb
movl %ebp, %esi
addq %r13, %rsi
movl 0x44(%r12), %edi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
jle 0x35cb
movl 0x44(%r12), %edi
movl $0x86, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3906
movl %eax, %ecx
sarl $0x1f, %eax
andl %ecx, %eax
addl %r14d, %ebp
testl %eax, %eax
je 0x3547
leaq 0x5333(%rip), %rdi      # 0x8910
pushq $-0x1
popq %r14
movl %r14d, %esi
movl %r14d, %edx
callq *0x18(%rbx)
jmp 0x35ef
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x99f0(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e6f(%rip), %rdi      # 0x8481
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %r14
jmp 0x35ef
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x3
popq %rdx
movq %rax, %rsi
callq 0x2090
testl %eax, %eax
jle 0x37f0
movl 0x44(%rbx), %edi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3906
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x37f0
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x8(%rsp), %rsi
movl $0x305, (%rsi)          # imm = 0x305
movb $0x0, 0x4(%rsi)
movl 0x44(%rdi), %edi
pushq $0x5
popq %rdx
callq 0x2090
testl %eax, %eax
jle 0x3ab8
movl 0x44(%rbx), %edi
movl $0x85, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3906
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x3ab8
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x3
popq %rdx
callq 0x2090
testl %eax, %eax
jle 0x3b09
movl 0x44(%r14), %edi
movzbl %bpl, %ecx
movl $0x87, %esi
movq %rbx, %rdx
callq 0x3906
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x3b09
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/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 0x21d0
movq %rax, %rbx
testq %rax, %rax
je 0x3b50
movq %rbx, %rdi
addq $0x8, %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x2120
movl %ebp, (%rbx)
andl $0x0, 0x4(%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x4dc7(%rip), %rdi      # 0x891e
callq 0x2240
jmp 0x3b48
// File: /workspace/github_c_makefile_star2_O2/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 0x3bf4
cmpl $0x2, %eax
je 0x3bbc
pushq $-0x1
popq %rbx
cmpl $0x1, %eax
jne 0x3bc5
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2210
testl %eax, %eax
js 0x3bd5
movl %eax, %ebp
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x22b0
testl %eax, %eax
js 0x3be3
movl 0x38(%rsp), %eax
movl %eax, (%r14)
xorl %ebx, %ebx
movl %ebp, %edi
callq 0x2140
jmp 0x3bc5
movl $0x10000, (%r14)        # imm = 0x10000
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4d57(%rip), %rdi      # 0x8933
callq 0x2240
jmp 0x3bc5
leaq 0x4d63(%rip), %rdi      # 0x894d
callq 0x2240
pushq $-0x1
popq %rbx
jmp 0x3bb3
// File: /workspace/github_c_makefile_star2_O2/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 0x3c47
leaq 0x4d13(%rip), %rsi      # 0x8929
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x2070
testl %eax, %eax
je 0x3c44
leaq 0x4d02(%rip), %rsi      # 0x892e
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x2070
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
addl %eax, %eax
jmp 0x3c47
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/orempel[P]multiboot_tool/filedata.c
// Function: hex2byte
static uint8_t hex2byte(const char *ptr)
{
    int i;
    uint8_t result = 0;

    for (i = 0; i < 2; i++)
    {
        result <<= 4;
        result |= (ptr[i] >= '0' && ptr[i] <= '9') ? (ptr[i] - '0')
                                                   : (((ptr[i] & 0xDF) >= 'A' && (ptr[i] & 0xDF) <= 'F') ? (ptr[i] - 'A' + 0x0A)
                                                                                                         : 0x00);
    }

    return result;
}

// Assembly:
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
cmpq $0x2, %rdx
je 0x4254
movb (%rdi,%rdx), %sil
leal -0x30(%rsi), %r8d
cmpb $0xa, %r8b
jb 0x4249
movl %esi, %r8d
andb $-0x21, %r8b
addb $-0x41, %r8b
addb $-0x37, %sil
cmpb $0x6, %r8b
movzbl %sil, %r8d
cmovael %ecx, %r8d
shlb $0x4, %al
orb %r8b, %al
incq %rdx
jmp 0x421a
retq
// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movb (%rsi), %al
movzwl 0x2(%rsi), %ebp
movl %ebp, %ecx
shrl $0x8, %ecx
addb %al, %bpl
addb 0x4(%rsi), %bpl
addb %cl, %bpl
movb $0x0, 0x10(%rsp)
pushq $0x40
popq %r12
leaq 0x47c7(%rip), %r15      # 0x8a57
xorl %r13d, %r13d
xorl %ebx, %ebx
movzbl %al, %edx
cmpq %rdx, %r13
jae 0x42d3
movslq %ebx, %rbx
leaq (%rsp,%rbx), %rdi
addq $0x10, %rdi
movq %r12, %rsi
subq %rbx, %rsi
movq 0x8(%r14), %rax
movzbl (%rax,%r13), %ecx
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
addl %eax, %ebx
movq 0x8(%r14), %rax
addb (%rax,%r13), %bpl
incq %r13
movb (%r14), %al
jmp 0x4295
movzwl 0x2(%r14), %ecx
movzbl 0x4(%r14), %r8d
negb %bpl
movzbl %bpl, %eax
movl %eax, (%rsp)
leaq 0x47c6(%rip), %rsi      # 0x8ab4
leaq 0x10(%rsp), %r9
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x2180
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x436b
movq %rax, %rbx
leaq 0x90d2(%rip), %rax      # 0xd400
movq %rax, (%rbx)
pushq $0x1
popq %rdi
pushq $0x68
popq %rsi
callq 0x2160
testq %rax, %rax
je 0x4363
movq %rax, %r14
leaq 0x9105(%rip), %rdi      # 0xd450
leaq 0x8b9(%rip), %rdx       # 0x4c0b
pushq $0x2
popq %rsi
movq %rax, %rcx
callq 0x6544
movq %r14, 0x8(%rbx)
jmp 0x436d
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_O2/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 0x483b
movq %rbx, %rdi
movl $0x80, %esi
callq 0x4cfb
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x22c0
movl 0x8(%rbx), %edi
leaq 0x28(%rbx), %rdx
xorl %esi, %esi
callq 0x2200
movl 0x8(%rbx), %edi
callq 0x2140
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdi, (%rsp)
movq 0x8(%rdi), %rdi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x3be0(%rip), %rcx      # 0x8464
leaq 0x3be7(%rip), %r15      # 0x8472
cmoveq %rcx, %r15
movq %rdi, 0x10(%rsp)
movzwl 0x1c(%rdi,%rax,8), %r12d
movq %rsi, 0x8(%rsp)
leaq 0x8(%rsi), %rbx
xorl %ebp, %ebp
movzbl %dl, %r13d
movzwl %bp, %r14d
movl %r12d, %ebp
subl %r14d, %ebp
jbe 0x4901
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
movq (%rsp), %rax
callq *0x18(%rax)
cmpl $0x20, %ebp
pushq $0x20
popq %rax
cmovgel %eax, %ebp
movl %r14d, %esi
addq %rbx, %rsi
movzwl %bp, %edx
movq 0x10(%rsp), %rdi
movl %r13d, %ecx
movl %r14d, %r8d
callq 0x50d3
addl %r14d, %ebp
testl %eax, %eax
je 0x48a9
pushq $-0x1
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
movl %ebp, %edx
movq (%rsp), %rax
callq *0x18(%rax)
jmp 0x491c
movq 0x8(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
movq (%rsp), %rax
callq *0x18(%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0x3b44(%rip), %rax      # 0x849a
leaq 0x3b4c(%rip), %r14      # 0x84a9
cmoveq %rax, %r14
leaq 0x8(%rsi), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movzbl %dl, %ebp
leaq 0x20(%rsp), %rbx
movzwl %cx, %r15d
movl 0x4(%r12), %edx
cmpl %r15d, %edx
jbe 0x4a0a
movq %r14, %rdi
movl %r15d, %esi
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl 0x4(%r12), %r13d
subl %r15d, %r13d
cmpl $0x20, %r13d
pushq $0x20
popq %rax
cmovael %eax, %r13d
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movl %r13d, %edx
movl %ebp, %ecx
movl %r15d, %r8d
callq 0x50d3
testl %eax, %eax
jne 0x4a24
movl %r15d, %esi
addq 0x10(%rsp), %rsi
movl %r13d, %edx
movq %rbx, %rdi
callq 0x21e0
leal (%r15,%r13), %ecx
testl %eax, %eax
je 0x4974
pushq $-0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movq 0x8604(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4602(%rip), %rsi      # 0x9000
movl %r15d, %edx
xorl %eax, %eax
callq 0x2180
jmp 0x4a36
movl %r15d, 0x4(%r12)
movq %r14, %rdi
movl %r15d, %esi
movl %r15d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x4a36
pushq $-0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq