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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorl %eax, %eax
subl -0xc(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x27f0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jb 0x2860
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, %eax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x283c
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_unique_64_xsl_rr_32_boundedrand_r
inline uint32_t pcg_unique_64_xsl_rr_32_boundedrand_r(struct pcg_state_64* rng,
                                                      uint32_t bound)
{
    uint32_t threshold = -bound % bound;
    for (;;) {
        uint32_t r = pcg_unique_64_xsl_rr_32_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorl %eax, %eax
subl -0xc(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2870
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jb 0x28e0
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, %eax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x28bc
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_setseq_64_xsl_rr_32_boundedrand_r
inline uint32_t
pcg_setseq_64_xsl_rr_32_boundedrand_r(struct pcg_state_setseq_64* rng,
                                      uint32_t bound)
{
    uint32_t threshold = -bound % bound;
    for (;;) {
        uint32_t r = pcg_setseq_64_xsl_rr_32_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorl %eax, %eax
subl -0xc(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x28f0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jb 0x2960
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, %eax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x293c
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorl %eax, %eax
subl -0xc(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2970
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jb 0x29e0
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, %eax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x29bc
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
subq -0x10(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x29f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x2a6e
movq -0x20(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, %rax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x2a42
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
subq -0x10(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2a70
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x2aee
movq -0x20(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, %rax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x2ac2
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
subq -0x10(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2af0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x2b6e
movq -0x20(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x10(%rbp)
movq %rdx, %rax
addq $0x20, %rsp
popq %rbp
retq
jmp 0x2b42
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x0, -0x8(%rbp)
jbe 0x2bd7
movl -0x8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2bb6
movl -0xc(%rbp), %eax
imull -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
imull -0xc(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
imull -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
imull -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %eax
shrl %eax
movl %eax, -0x8(%rbp)
jmp 0x2b8e
movl -0x14(%rbp), %eax
imull -0x4(%rbp), %eax
addl -0x18(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x1, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
jbe 0x2c72
movq -0x10(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2c47
movq -0x18(%rbp), %rax
imulq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
imulq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
imulq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
imulq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
shrq %rax
movq %rax, -0x10(%rbp)
jmp 0x2c14
movq -0x28(%rbp), %rax
imulq -0x8(%rbp), %rax
addq -0x30(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/pyk[P]simple-nn/deps/pcg/src/../include/pcg_variants.h
// Function: pcg_output_xsl_rr_rr_64_64
inline uint64_t pcg_output_xsl_rr_rr_64_64(uint64_t state)
{
    uint32_t rot1 = (uint32_t)(state >> 59u);
    uint32_t high = (uint32_t)(state >> 32u);
    uint32_t low  = (uint32_t)state;
    uint32_t xored = high ^ low;
    uint32_t newlow  = pcg_rotr_32(xored, rot1);
    uint32_t newhigh = pcg_rotr_32(high, newlow & 31u);
    return (((uint64_t)newhigh) << 32u) | newlow;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
shrq $0x3b, %rax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
shrq $0x20, %rax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
xorl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
movl -0xc(%rbp), %esi
callq 0x2d50
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %edi
movl -0x1c(%rbp), %esi
andl $0x1f, %esi
callq 0x2d50
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
shlq $0x20, %rax
movl -0x1c(%rbp), %ecx
orq %rcx, %rax
addq $0x20, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x20, %edi
callq 0x21b0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x23ba
movq $0x0, -0x8(%rbp)
jmp 0x2440
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq -0x10(%rbp), %rax
leaq 0xdd8b(%rip), %rcx      # 0x10160
movq %rcx, (%rax)
movl $0x58, %edi
callq 0x21b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2400
movq -0x10(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x2440
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x2100
movq -0x18(%rbp), %rcx
leaq 0xdd95(%rip), %rdi      # 0x101b0
movl $0x4, %esi
leaq 0x919(%rip), %rdx       # 0x2d40
callq 0x9670
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x247e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0x10(%rbp), %rdi
callq 0x2030
movq -0x8(%rbp), %rdi
callq 0x2030
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_get_memtype
static int butterfly_get_memtype(struct multiboot * p_mboot,
                                 const char * p_memname)
{
    /* unused parameter */
    (void)p_mboot;

    if (strcmp(p_memname, "flash") == 0)
    {
        return 'F';
    }
    else if (strcmp(p_memname, "eeprom") == 0)
    {
        return 'E';
    }

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x907a(%rip), %rsi      # 0xb535
callq 0x2150
cmpl $0x0, %eax
jne 0x24ce
movl $0x46, -0x4(%rbp)
jmp 0x24f5
movq -0x18(%rbp), %rdi
leaq 0x906a(%rip), %rsi      # 0xb543
callq 0x2150
cmpl $0x0, %eax
jne 0x24ec
movl $0x45, -0x4(%rbp)
jmp 0x24f5
jmp 0x24ee
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_get_memsize
static uint32_t butterfly_get_memsize(struct multiboot * p_mboot,
                                      int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

    if (!p_priv->progmode_active)
    {
        return 0;
    }

    switch (memtype)
    {
        case 'F':
            return p_priv->flashsize;

        case 'E':
            return p_priv->eepromsize;

        default:
            return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x52(%rax)
jne 0x252a
movl $0x0, -0x4(%rbp)
jmp 0x2562
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
subl $0x45, %eax
je 0x254e
jmp 0x2537
movl -0x24(%rbp), %eax
subl $0x46, %eax
jne 0x255b
jmp 0x2541
movq -0x20(%rbp), %rax
movzwl 0x4e(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x2562
movq -0x20(%rbp), %rax
movzwl 0x50(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x2562
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x52(%rax)
je 0x281b
movq -0x10(%rbp), %rdi
callq 0x3450
movq -0x10(%rbp), %rdi
callq 0x3040
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_open_device
static int butterfly_open_device(bfly_privdata_t * p_priv)
{
    p_priv->fd = open(p_priv->p_device, O_RDWR | O_NOCTTY | O_CLOEXEC);
    if (p_priv->fd < 0)
    {
        perror("open()");
        return -1;
    }

    if (tcgetattr(p_priv->fd, &p_priv->oldtio) < 0)
    {
        perror("tcgetattr(oldtio)");
        close(p_priv->fd);
        return -1;
    }

    struct termios newtio;
    memset(&newtio, 0, sizeof(newtio));

    newtio.c_iflag = IGNBRK;
    newtio.c_cflag = (CS8 | CREAD | CLOCAL);
    cfsetispeed(&newtio, SERIAL_BAUDRATE);
    cfsetospeed(&newtio, SERIAL_BAUDRATE);
    newtio.c_cc[VMIN] = 1;
    newtio.c_cc[VTIME] = 0;

    int err = tcsetattr(p_priv->fd, TCSANOW, &newtio);
    if (err < 0)
    {
        perror("tcsetattr(newtio)");
        close(p_priv->fd);
        return -1;
    }

    /* needed for some slow USB2Serial adapters */
    usleep(200000);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x80102, %esi          # imm = 0x80102
movb $0x0, %al
callq 0x21e0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jge 0x2efa
leaq 0x8b46(%rip), %rdi      # 0xba2f
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2fc6
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x21c0
cmpl $0x0, %eax
jge 0x2f37
leaq 0x85e0(%rip), %rdi      # 0xb4fa
callq 0x2210
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2fc6
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
movl $0x3c, %edx
callq 0x2100
movl $0x1, -0x4c(%rbp)
movl $0x8b0, -0x44(%rbp)     # imm = 0x8B0
leaq -0x4c(%rbp), %rdi
movl $0x1002, %esi           # imm = 0x1002
callq 0x2200
leaq -0x4c(%rbp), %rdi
movl $0x1002, %esi           # imm = 0x1002
callq 0x2090
movb $0x1, -0x35(%rbp)
movb $0x0, -0x36(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
xorl %esi, %esi
leaq -0x4c(%rbp), %rdx
callq 0x21d0
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x2fb5
leaq 0x8571(%rip), %rdi      # 0xb50c
callq 0x2210
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2fc6
movl $0x30d40, %edi          # imm = 0x30D40
callq 0x2280
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_enter_progmode
static int butterfly_enter_progmode(bfly_privdata_t * p_priv)
{
    if (p_priv->twi_address == 0x00)
    {
        (void)write(p_priv->fd, "P", 1);
    }
    else
    {
        uint8_t cmd[2] = { 'I' , p_priv->twi_address };
        (void)write(p_priv->fd, cmd, 2);
    }

    return butterfly_expect_cr(p_priv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x48(%rax), %eax
cmpl $0x0, %eax
jne 0x3003
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x8527(%rip), %rsi      # 0xb51e
movl $0x1, %edx
callq 0x2070
jmp 0x3026
movb $0x49, -0xa(%rbp)
movq -0x8(%rbp), %rax
movb 0x48(%rax), %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0xa(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movq -0x8(%rbp), %rdi
callq 0x31f0
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_get_signature
static int butterfly_get_signature(bfly_privdata_t * p_priv,
                                   uint8_t * p_signature)
{
    int result;
    uint8_t buffer[3];

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

    result = butterfly_serial_read(p_priv->fd, buffer, sizeof(buffer),
                                   SERIAL_TIMEOUT);

    if (result == 3)
    {
        p_signature[0] = buffer[2];
        p_signature[1] = buffer[1];
        p_signature[2] = buffer[0];
        return 0;
    }

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x804f(%rip), %rsi      # 0xb0ed
movl $0x1, %edx
callq 0x2070
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x1f(%rbp), %rsi
movl $0x3, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x3250
movl %eax, -0x1c(%rbp)
cmpl $0x3, -0x1c(%rbp)
jne 0x30f1
movb -0x1d(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movb -0x1e(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movb -0x1f(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x30f8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_get_buffersize
static int butterfly_get_buffersize(bfly_privdata_t * p_priv,
                                    uint16_t * p_buffersize)
{
    int result;
    uint8_t buffer[3];

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

    result = butterfly_serial_read(p_priv->fd, buffer, sizeof(buffer),
                                   SERIAL_TIMEOUT);
    if (result == sizeof(buffer))
    {
        if (buffer[0] == 'Y')
        {
            *p_buffersize = (buffer[1] << 8) | buffer[2];
        }
        else
        {
            *p_buffersize = 0;
        }
    }

    return (result != sizeof(buffer));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x83f9(%rip), %rsi      # 0xb527
movl $0x1, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x3, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x3250
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x3, %rax
jne 0x318c
movzbl -0x17(%rbp), %eax
cmpl $0x59, %eax
jne 0x3181
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, (%rax)
jmp 0x318a
movq -0x10(%rbp), %rax
movw $0x0, (%rax)
jmp 0x318c
movslq -0x14(%rbp), %rax
cmpq $0x3, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x11(%rbp), %rsi
movl $0x1, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x3250
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rax
cmpq $0x1, %rax
jne 0x3235
movzbl -0x11(%rbp), %eax
cmpl $0xd, %eax
jne 0x3235
movl $0x0, -0x4(%rbp)
jmp 0x323c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_leave_progmode
static int butterfly_leave_progmode(bfly_privdata_t * p_priv)
{
    if (p_priv->stay_in_bootloader)
    {
        /* Leave programming mode */
        (void)write(p_priv->fd, "L", 1);
    }
    else
    {
        /* Exit Bootloader */
        (void)write(p_priv->fd, "E", 1);
    }

    return butterfly_expect_cr(p_priv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x4a(%rax)
je 0x3480
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x80b5(%rip), %rsi      # 0xb529
movl $0x1, %edx
callq 0x2070
jmp 0x3498
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x809d(%rip), %rsi      # 0xb52b
movl $0x1, %edx
callq 0x2070
movq -0x8(%rbp), %rdi
callq 0x31f0
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq 0x8090(%rip), %rsi      # 0xb561
movl $0x1, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0xb(%rbp), %rsi
movl $0x1, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x3250
movl %eax, -0x10(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x354c
movzbl -0xb(%rbp), %eax
cmpl $0x59, %eax
jne 0x354c
movzwl -0xa(%rbp), %eax
sarl %eax
movw %ax, -0xa(%rbp)
movb $0x41, -0x13(%rbp)
movzwl -0xa(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x12(%rbp)
movzwl -0xa(%rbp), %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x13(%rbp), %rsi
movl $0x3, %edx
callq 0x2070
movq -0x8(%rbp), %rdi
callq 0x31f0
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movw %dx, %cx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movb %al, -0x13(%rbp)
movb $0x67, -0x1c(%rbp)
movzwl -0x12(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x1b(%rbp)
movzwl -0x12(%rbp), %eax
andl $0xff, %eax
movb %al, -0x1a(%rbp)
movb -0x13(%rbp), %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x1c(%rbp), %rsi
movl $0x4, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x10(%rbp), %rsi
movzwl -0x12(%rbp), %edx
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x3250
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_write_data
static int butterfly_write_data(bfly_privdata_t * p_priv,
                                const uint8_t * p_data, uint16_t size,
                                uint8_t memtype)
{
    uint8_t cmd[4] = { 'B', size >> 8, size & 0xFF, memtype };
    (void)write(p_priv->fd, cmd, 4);

    (void)write(p_priv->fd, p_data, size);

    return butterfly_expect_cr(p_priv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movw %dx, %cx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movb %al, -0x13(%rbp)
movb $0x42, -0x17(%rbp)
movzwl -0x12(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x16(%rbp)
movzwl -0x12(%rbp), %eax
andl $0xff, %eax
movb %al, -0x15(%rbp)
movb -0x13(%rbp), %al
movb %al, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x4, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x10(%rbp), %rsi
movzwl -0x12(%rbp), %eax
movl %eax, %edx
callq 0x2070
movq -0x8(%rbp), %rdi
callq 0x31f0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpq $0x7, %rax
jae 0x36f0
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0xcb9c(%rip), %rax      # 0x10230
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x36e3
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jne 0x36e3
movq -0x20(%rbp), %rax
movzbl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jne 0x36e3
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x36f8
jmp 0x36e5
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x367f
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x20, %edi
callq 0x21b0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x377a
movq $0x0, -0x8(%rbp)
jmp 0x380b
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq -0x10(%rbp), %rax
leaq 0xcb4b(%rip), %rcx      # 0x102e0
movq %rcx, (%rax)
movl $0x78, %edi
callq 0x21b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x37c0
movq -0x10(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x380b
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x78, %edx
callq 0x2100
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rcx
leaq 0xcb4a(%rip), %rdi      # 0x10330
movl $0x3, %esi
leaq 0x85e(%rip), %rdx       # 0x4050
callq 0x9670
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_get_memtype
static int eprog_get_memtype(struct multiboot *mboot,
                                const char *memname)
{
    /* unused parameter */
    (void)mboot;

    if (strcmp(memname, "eprom") == 0)
    {
        return MEMTYPE_EPROM;
    }

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x7cb9(%rip), %rsi      # 0xb544
callq 0x2150
cmpl $0x0, %eax
jne 0x389e
movl $0x1, -0x4(%rbp)
jmp 0x38a5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_get_memsize
static uint32_t eprog_get_memsize(struct multiboot *mboot,
                                  int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

    if (memtype != MEMTYPE_EPROM)
    {
        return 0;
    }

    return p_prog->eprom_type * 1024;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpl $0x1, -0x14(%rbp)
je 0x38d6
movl $0x0, -0x4(%rbp)
jmp 0x38e4
movq -0x20(%rbp), %rax
movzbl 0x69(%rax), %eax
shll $0xa, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x70(%rax), %eax
cmpl $0x1, %eax
jne 0x3bf0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x4690
movq -0x10(%rbp), %rdi
callq 0x4470
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0x7d72(%rip), %rax      # 0xb9a8
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x69(%rax), %eax
shll $0xa, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x4b40
cmpl $0x0, %eax
jge 0x3c84
movq 0xc391(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x78d9(%rip), %rsi      # 0xb54a
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d46
jmp 0x3c86
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x3d21
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
callq *%rax
movq -0x28(%rbp), %rax
movzbl 0x68(%rax), %eax
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jae 0x3cc5
movq -0x28(%rbp), %rax
movzbl 0x68(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x3cce
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movb %al, -0x39(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movl -0x34(%rbp), %eax
addq %rax, %rsi
movzbl -0x39(%rbp), %edx
callq 0x4be0
cmpl $0x0, %eax
je 0x3d12
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d46
movzbl -0x39(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3c86
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0x7a8f(%rip), %rax      # 0xb9c5
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x4b40
cmpl $0x0, %eax
jge 0x3f76
movq 0xc09f(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x75e7(%rip), %rsi      # 0xb54a
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4042
jmp 0x3f78
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x4023
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
callq *%rax
movq -0x28(%rbp), %rax
movzbl 0x6a(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jae 0x3fc3
movq -0x28(%rbp), %rax
movzbl 0x6a(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0x3fd0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movb %al, -0x35(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movl -0x34(%rbp), %eax
addq %rax, %rsi
movzbl -0x35(%rbp), %edx
callq 0x4c70
cmpl $0x0, %eax
je 0x4014
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4042
movzbl -0x35(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3f78
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_open_device
static int eprog_open_device(struct eprog_privdata *p_prog)
{
    p_prog->fd = open(p_prog->device, O_RDWR | O_NOCTTY | O_CLOEXEC);
    if (p_prog->fd < 0)
    {
        perror("open()");
        return -1;
    }

    if (tcgetattr(p_prog->fd, &p_prog->oldtio) < 0)
    {
        perror("tcgetattr(oldtio)");
        close(p_prog->fd);
        return -1;
    }

    struct termios newtio;
    memset(&newtio, 0, sizeof(newtio));

    newtio.c_iflag |= IGNBRK;
    newtio.c_cflag |= SERIAL_BAUDRATE | CS8 | CLOCAL | CREAD;

    newtio.c_cc[VMIN] = 1;
    newtio.c_cc[VTIME] = 0;

    int err = tcsetattr(p_prog->fd, TCSANOW, &newtio);
    if (err < 0)
    {
        perror("tcsetattr(newtio)");
        close(p_prog->fd);
        return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x80102, %esi          # imm = 0x80102
movb $0x0, %al
callq 0x21e0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jge 0x42fa
leaq 0x7746(%rip), %rdi      # 0xba2f
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43a3
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x21c0
cmpl $0x0, %eax
jge 0x4334
leaq 0x71e0(%rip), %rdi      # 0xb4fa
callq 0x2210
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43a3
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
movl $0x3c, %edx
callq 0x2100
movl -0x4c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
orl $0x18b2, %eax           # imm = 0x18B2
movl %eax, -0x44(%rbp)
movb $0x1, -0x35(%rbp)
movb $0x0, -0x36(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
xorl %esi, %esi
leaq -0x4c(%rbp), %rdx
callq 0x21d0
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x439c
leaq 0x718a(%rip), %rdi      # 0xb50c
callq 0x2210
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43a3
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_sync
static int eprog_sync(struct eprog_privdata *p_prog)
{
    int sync_count = 255;

    while (sync_count > 0)
    {
        /* send only MSGTYPE, no request length! */
        uint8_t request[] = { MSGTYPE_SYNC };
        uint8_t response[3];

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

        ret = eprog_serial_read(p_prog->fd, response, sizeof(response), SERIAL_TIMEOUT_SYNC);
        if ((ret == sizeof(response)) &&
            (response[0] == MSGTYPE_ERROR_RSP) &&
            (response[1] == 1) &&
            (response[2] == ERROR_UNKNOWN_COMMAND)
           )
        {
           return 0;
        }

        sync_count--;
    }

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0xff, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x445e
leaq -0x15(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x2100
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x15(%rbp), %rsi
movl $0x1, %edx
callq 0x2070
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x4403
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4465
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x3, %edx
movl $0x5, %ecx
callq 0x4710
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
cmpq $0x3, %rax
jne 0x4450
movzbl -0x18(%rbp), %eax
cmpl $0x80, %eax
jne 0x4450
movzbl -0x17(%rbp), %eax
cmpl $0x1, %eax
jne 0x4450
movzbl -0x16(%rbp), %eax
cmpl $0x1, %eax
jne 0x4450
movl $0x0, -0x4(%rbp)
jmp 0x4465
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x43c3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_close_device
static void eprog_close_device(struct eprog_privdata *p_prog)
{
    /* delay close() / tcsetattr() */
    usleep(100000);

    tcsetattr(p_prog->fd, TCSANOW, &p_prog->oldtio);
    close(p_prog->fd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x2280
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x8(%rbp), %rdx
addq $0x8, %rdx
xorl %esi, %esi
callq 0x21d0
movq -0x8(%rbp), %rax
movl 0x44(%rax), %edi
callq 0x2120
addq $0x10, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_get_version
static int eprog_get_version(struct eprog_privdata *p_prog,
                             uint8_t *version, uint8_t length)
{
    uint8_t request[] = { MSGTYPE_VERSION_REQ, 0 };

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

    ret = eprog_recv(p_prog->fd, MSGTYPE_VERSION_RSP, version, length);
    if (ret <= 0)
    {
        return -1;
    }

    if (ret < length)
    {
        version[ret] = '\0';
    }
    else
    {
        version[length -1] = '\0';
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movw 0x7414(%rip), %ax       # 0xb8e0
movw %ax, -0x1b(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x1b(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x44f6
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4553
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
movq -0x18(%rbp), %rdx
movl $0x81, %esi
movzbl -0x19(%rbp), %ecx
callq 0x4910
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x4521
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4553
movl -0x20(%rbp), %eax
movzbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x453a
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x454c
movq -0x18(%rbp), %rax
movzbl -0x19(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_get_pagesize
static int eprog_get_pagesize(struct eprog_privdata *p_prog,
                              uint8_t *pagesize)
{
    uint8_t request[] = { MSGTYPE_PAGESIZE_REQ, 0 };
    uint8_t response[1];

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

    ret = eprog_recv(p_prog->fd, MSGTYPE_PAGESIZE_RSP, response, sizeof(response));
    if (ret != sizeof(response))
    {
        return -1;
    }

    *pagesize = response[0];

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw 0x742f(%rip), %ax       # 0xb9a6
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x1a(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x45a1
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x45e1
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x1b(%rbp), %rdx
movl $0x82, %esi
movl $0x1, %ecx
callq 0x4910
movl %eax, -0x20(%rbp)
movslq -0x20(%rbp), %rax
cmpq $0x1, %rax
je 0x45d1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45e1
movb -0x1b(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_set_config
static int eprog_set_config(struct eprog_privdata *p_prog,
                            uint8_t eprom_type,
                            uint8_t pagesize,
                            uint8_t reset_polarity)
{
    uint8_t request[] = { MSGTYPE_CONFIG_REQ, 3, eprom_type, pagesize, reset_polarity };

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

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

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movb %dl, %cl
movb %sil, %dl
movq %rdi, -0x10(%rbp)
movb %dl, -0x11(%rbp)
movb %cl, -0x12(%rbp)
movb %al, -0x13(%rbp)
movb $0x3, -0x18(%rbp)
movb $0x3, -0x17(%rbp)
movb -0x11(%rbp), %al
movb %al, -0x16(%rbp)
movb -0x12(%rbp), %al
movb %al, -0x15(%rbp)
movb -0x13(%rbp), %al
movb %al, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x5, %edx
callq 0x2070
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x464c
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x467b
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edi
movl $0x83, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x4910
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x4674
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x467b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)