LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_set_progmode
static int eprog_set_progmode(struct eprog_privdata *p_prog,
                              uint8_t progmode)
{
    uint8_t request[] = { MSGTYPE_PROGMODE_REQ, 1, progmode };

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

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

    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xd(%rsp), %rax
movw $0x104, (%rax)          # imm = 0x104
movb %sil, 0x2(%rax)
movl 0x44(%rdi), %edi
movl $0x3, %edx
movq %rax, %rsi
callq 0x2090
testl %eax, %eax
jle 0x43e5
movl 0x44(%rbx), %edi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x452c
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x43e5
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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
movl $0x5, %edx
callq 0x2090
testl %eax, %eax
jle 0x46b9
movl 0x44(%rbx), %edi
movl $0x85, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x452c
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x46b9
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_read_data
static int eprog_read_data(struct eprog_privdata *p_prog,
                           uint8_t * data,
                           uint8_t length)
{
    uint8_t request[] = { MSGTYPE_READ_REQ, 1, length };

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

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

    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xd(%rsp), %rsi
movw $0x107, (%rsi)          # imm = 0x107
movb %bpl, 0x2(%rsi)
movl 0x44(%rdi), %edi
movl $0x3, %edx
callq 0x2090
testl %eax, %eax
jle 0x470c
movl 0x44(%r14), %edi
movzbl %bpl, %ecx
movl $0x87, %esi
movq %rbx, %rdx
callq 0x452c
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ecx, %eax
jmp 0x470c
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O3/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 0x4757
movq %rbx, %rdi
addq $0x8, %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x2120
movl %ebp, (%rbx)
movl $0x0, 0x4(%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x41d2(%rip), %rdi      # 0x8930
callq 0x2240
jmp 0x474f
// File: /workspace/github_c_makefile_star2_O3/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 0x47ff
cmpl $0x2, %eax
je 0x47c5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x1, %eax
jne 0x47ce
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2210
testl %eax, %eax
js 0x47de
movl %eax, %ebp
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x22b0
testl %eax, %eax
js 0x47ec
movl 0x38(%rsp), %eax
movl %eax, (%r14)
xorl %ebx, %ebx
movl %ebp, %edi
callq 0x2140
jmp 0x47ce
movl $0x10000, (%r14)        # imm = 0x10000
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4160(%rip), %rdi      # 0x8945
callq 0x2240
jmp 0x47ce
leaq 0x416c(%rip), %rdi      # 0x895f
callq 0x2240
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x47bc
// File: /workspace/github_c_makefile_star2_O3/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 0x4858
leaq 0x411a(%rip), %rsi      # 0x893b
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2070
testl %eax, %eax
je 0x4853
leaq 0x4107(%rip), %rsi      # 0x8940
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2070
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
addl %eax, %eax
jmp 0x4858
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/filedata.c
// Function: file_read
int file_read(const char *filename, struct databuf *dbuf)
{
    switch (get_filetype(filename))
    {
        case FILETYPE_BINARY:
            return binfile_read(filename, dbuf);

        case FILETYPE_INTELHEX:
            return hexfile_read(filename, dbuf);

        default:
            return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x47ff
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x48c7
cmpl $0x1, %eax
jne 0x4964
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2210
testl %eax, %eax
js 0x4973
movl %eax, %r14d
leaq 0x8(%rbx), %rsi
movl (%rbx), %edx
movl %eax, %edi
callq 0x2150
testq %rax, %rax
jle 0x498a
movl %eax, 0x4(%rbx)
movl %r14d, %edi
callq 0x2140
jmp 0x4962
leaq 0x40da(%rip), %rsi      # 0x89a8
movq %r14, %rdi
callq 0x2220
testq %rax, %rax
je 0x497c
movq %rax, %r14
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %rax, %rdi
callq 0x4c91
cmpl $-0x1, %eax
je 0x495a
leaq 0x8(%rbx), %r12
movq %rsp, %r15
cmpb $0x0, 0x4(%rsp)
jne 0x493a
movzwl 0x2(%rsp), %eax
movl (%rbx), %ecx
cmpl %eax, %ecx
jb 0x49a0
movzbl (%rsp), %edx
leal (%rdx,%rax), %ebp
cmpl %ecx, %ebp
ja 0x49a0
movl %eax, %edi
addq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x21b0
movl %ebp, 0x4(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4c91
cmpl $-0x1, %eax
jne 0x4907
movq %r14, %rdi
callq 0x20a0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4000(%rip), %rdi      # 0x897a
jmp 0x4983
leaq 0x4027(%rip), %rdi      # 0x89aa
callq 0x2240
jmp 0x4964
leaq 0x4000(%rip), %rdi      # 0x8991
callq 0x2240
movl %r14d, %edi
callq 0x2140
jmp 0x4964
callq 0x26b6
jmp 0x495a
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/filedata.c
// Function: hexfile_putrecord
static int hexfile_putrecord(FILE *stream, struct ihex_record *record)
{
    uint8_t chksum = record->byte_count;
    chksum += (record->address >> 8) & 0xFF;
    chksum += (record->address & 0xFF);
    chksum += record->type;

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

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

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

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movzwl 0x2(%rsi), %eax
movl %eax, %ecx
shrl $0x8, %ecx
movb (%rsi), %dl
movb 0x4(%rsi), %sil
leal (%rdx,%rax), %ebp
addb %sil, %bpl
addb %cl, %bpl
movb $0x0, 0x10(%rsp)
testb %dl, %dl
je 0x5000
movq 0x8(%r14), %rcx
leaq 0x3ab3(%rip), %r15      # 0x8a69
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq %r13d, %r13
leaq (%rsp,%r13), %rdi
addq $0x10, %rdi
movl $0x40, %esi
subq %r13, %rsi
movzbl (%rcx,%r12), %ecx
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
movq 0x8(%r14), %rcx
addb (%rcx,%r12), %bpl
addl %eax, %r13d
incq %r12
movzbl (%r14), %edx
cmpq %rdx, %r12
jb 0x4fbc
movzwl 0x2(%r14), %eax
movb 0x4(%r14), %sil
jmp 0x5002
xorl %edx, %edx
movzwl %ax, %ecx
movzbl %sil, %r8d
negb %bpl
movzbl %bpl, %eax
movl %eax, (%rsp)
leaq 0x3aac(%rip), %rsi      # 0x8ac6
leaq 0x10(%rsp), %r9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2180
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_alloc
static struct multiboot * funk_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

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

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

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

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

    mboot->privdata = funk;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
testq %rax, %rax
je 0x509d
movq %rax, %rbx
leaq 0x83a6(%rip), %rax      # 0xd400
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x68, %esi
callq 0x2160
testq %rax, %rax
je 0x5095
movq %rax, %r14
leaq 0x83d5(%rip), %rdi      # 0xd450
leaq 0x8c9(%rip), %rdx       # 0x594b
movl $0x2, %esi
movq %rax, %rcx
callq 0x72f0
movq %r14, 0x8(%rbx)
jmp 0x509f
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_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_free
static void funk_free(struct multiboot *mboot)
{
    struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;

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

    free(funk);
    free(mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x50c2
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_O3/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 0x54df
movq %rbx, %rdi
movl $0x80, %esi
callq 0x5a0e
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_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_read
static int funk_read(struct multiboot *mboot,
                     struct databuf *dbuf,
                     int memtype)
{
    struct funk_privdata *funk = (struct funk_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "reading flash" : "reading eeprom";

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

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

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

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rsi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x2f36(%rip), %rcx      # 0x8464
leaq 0x2f3d(%rip), %r15      # 0x8472
cmoveq %rcx, %r15
movq %rsi, 0x20(%rsp)
movzwl 0x1c(%rsi,%rax,8), %ebx
movl $0x0, %r14d
testl %ebx, %ebx
je 0x55b4
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movzbl %dl, %ebp
xorl %r12d, %r12d
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %r13d
subl %r14d, %r13d
cmpl $0x20, %r13d
movl $0x20, %eax
cmovgel %eax, %r13d
movzwl %r12w, %r8d
movq 0x18(%rsp), %rax
leaq (%rax,%r8), %rsi
movzwl %r13w, %edx
movq 0x20(%rsp), %rdi
movl %ebp, %ecx
callq 0x5df9
testl %eax, %eax
jne 0x55d1
addl %r13d, %r12d
movzwl %r12w, %r14d
cmpl %r14d, %ebx
ja 0x5564
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x55eb
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movl %edx, %eax
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0x2e7c(%rip), %rcx      # 0x849a
leaq 0x2e84(%rip), %rdx      # 0x84a9
cmoveq %rcx, %rdx
movq %rdx, (%rsp)
movl 0x4(%rsi), %edx
movl $0x0, %ebp
testl %edx, %edx
je 0x56d2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rsi
movq %rsi, 0x28(%rsp)
addq $0x18, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x8(%r12), %rcx
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
movzbl %al, %eax
movl %eax, 0x14(%rsp)
xorl %r15d, %r15d
movq (%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rax
callq *(%rax)
movl 0x4(%r12), %ebx
subl %ebp, %ebx
cmpl $0x20, %ebx
movl $0x20, %eax
cmovael %eax, %ebx
movzwl %r15w, %r13d
movq 0x28(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
movl %ebx, %edx
movl 0x14(%rsp), %ecx
movl %r13d, %r8d
callq 0x5df9
testl %eax, %eax
jne 0x56eb
addq 0x20(%rsp), %r13
movl %ebx, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x21e0
testl %eax, %eax
jne 0x5716
addl %ebx, %r15d
movzwl %r15w, %ebp
movl 0x4(%r12), %edx
cmpl %ebp, %edx
ja 0x566a
movl %ebp, 0x4(%r12)
movq (%rsp), %rdi
movl %ebp, %esi
movl %ebp, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x5705
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq (%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rax
callq *(%rax)
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movl %ebp, %edx
callq 0x2904
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x5705
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_optarg_cb
static int funk_optarg_cb(int val, const char *arg, void *privdata)
{
    struct funk_privdata *funk = (struct funk_privdata *)privdata;

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

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

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

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

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

        default:
            return 1;
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movl $0x1, %eax
cmpl $0x63, %edi
jg 0x5995
cmpl $0x61, %edi
jne 0x59ca
movq %rsi, %rbx
leaq 0x8(%rsp), %r15
movq %rsi, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x21a0
movl %eax, 0x10(%r14)
movq (%r15), %rcx
cmpb $0x0, (%rcx)
jne 0x59e4
cmpl $0x100, %eax            # imm = 0x100
jae 0x59e4
xorl %eax, %eax
jmp 0x5a04
cmpl $0x64, %edi
jne 0x59d1
cmpq $0x0, (%r14)
jne 0x59dd
movq 0x7629(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2290
movq %rax, %rcx
movq %rax, (%r14)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x5a04
leaq 0x26b7(%rip), %rdi      # 0x807a
callq 0x2240
jmp 0x59ff
cmpl $0x3f, %edi
jne 0x5a04
jmp 0x59d6
cmpl $0x68, %edi
jne 0x5a04
callq 0x292f
jmp 0x59ff
callq 0x294d
jmp 0x59ff
movq 0x760d(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x2658(%rip), %rsi      # 0x804d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2180
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_switch_application
static int funk_switch_application(struct funk_privdata *funk,
                                   uint8_t application)
{
    struct rfm12_pkt packet;

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

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

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

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

    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movb 0x10(%rdi), %cl
leaq 0xd(%rsp), %rax
movb %cl, (%rax)
movl $0x20cc04cc, 0x1(%rax)  # imm = 0x20CC04CC
movl 0x18(%rdi), %ecx
incl %ecx
movl %ecx, 0x18(%rdi)
movb %cl, 0x5(%rax)
movb $0x0, 0x6(%rax)
movb %sil, 0x7(%rax)
movq %rax, %rsi
movl $0x8, %edx
callq 0x5d1b
testl %eax, %eax
js 0x5a83
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %rbx, %rdi
callq 0x5d86
testl %eax, %eax
js 0x5a8c
movb 0x11(%rsp), %al
xorb $-0x20, %al
xorl %ebp, %ebp
orb 0x13(%rsp), %al
setne %bpl
negl %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %rbp
retq
movl %eax, %ebp
callq 0x2991
jmp 0x5a7a
callq 0x296f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5a7a
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_bridge_send
static int funk_bridge_send(struct funk_privdata *funk,
                            uint8_t *header,
                            uint8_t headerlength,
                            uint8_t *data,
                            uint8_t datalength)
{
    if (headerlength > 0)
    {
        if (write(funk->fd, header, headerlength) != headerlength)
        {
            return -1;
        }
    }

    if (datalength > 0)
    {
        if (write(funk->fd, data, datalength) != datalength)
        {
            return -1;
        }
    }

#if (FUNK_BRIDGE_DEBUG == 1)
    char *dump = funk_print_data(data, datalength);
    printf("funk_bridge_send() cmd=0x%02x length=0x%02x\n%s\n", header[0], datalength, dump);
    free(dump);
#endif

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r15
movl 0x8(%rdi), %edi
movl $0x2, %edx
callq 0x2090
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x2, %rax
jne 0x5ade
testb %bpl, %bpl
je 0x5adc
movl 0x8(%r15), %edi
movzbl %bpl, %r15d
movq %r14, %rsi
movq %r15, %rdx
callq 0x2090
cmpq %r15, %rax
jne 0x5ade
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_serial_read
static int funk_serial_read(int fd, void *data, int size)
{
    int pos = 0;

    while (1)
    {
        fd_set fdset;
        struct timeval timeout = { .tv_sec = 1, .tv_usec = 0 };

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

        int ret = select(fd +1, &fdset, NULL, NULL, &timeout);
        if (ret == -1)
        {
            perror("select");
            return -1;

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

            }
            else
            {
                pos += len;
                if (pos == size)
                {
                    break;
                }
            }
        }
    }

    return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebx
movq %rsi, 0x8(%rsp)
movl %edi, %r15d
leal 0x3f(%r15), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %r13d
shlq %cl, %r13
sarl $0x6, %eax
movslq %eax, %r14
leal 0x1(%r15), %ebp
xorl %r12d, %r12d
movups 0x3473(%rip), %xmm0     # 0x90c8
movaps %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
orq %r13, 0x20(%rsp,%r14,8)
movl %ebp, %edi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x21c0
testl %eax, %eax
je 0x5cf8
cmpl $-0x1, %eax
je 0x5d0d
testq %r13, 0x20(%rsp,%r14,8)
je 0x5ce3
movl %r12d, %esi
addq 0x8(%rsp), %rsi
movl %ebx, %eax
subl %r12d, %eax
movslq %eax, %rdx
movl %r15d, %edi
callq 0x2150
addl %eax, %r12d
xorl %ecx, %ecx
cmpl %ebx, %r12d
sete %dl
testl %eax, %eax
js 0x5cf2
movb %dl, %cl
leal (%rcx,%rcx,2), %eax
jmp 0x5ce5
xorl %eax, %eax
testl %eax, %eax
je 0x5c4e
cmpl $0x3, %eax
je 0x5cf8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2743(%rip), %rdi      # 0x8457
callq 0x2240
jmp 0x5cf2
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_send_packet
static int funk_send_packet(struct funk_privdata *funk,
                            struct rfm12_pkt *pkt,
                            int length)
{
    uint8_t request[] = { BRIDGE_CMD_TRANSMIT, length };

    int ret = funk_bridge_send(funk, request, sizeof(request), (uint8_t *)pkt, length);
    if (ret < 0)
    {
        return ret;
    }

    uint8_t cause = BRIDGE_CAUSE_SUCCESS;
    ret = funk_bridge_recv(funk, request[0], &cause, NULL, 0);
    if (ret != 0)
    {
        return -1;
    }

#if (FUNK_PACKET_DEBUG == 1)
    char *dump = funk_print_data((uint8_t *)pkt, length);
    printf("funk_send_packet() cause=0x%02x length=0x%02x\n%s\n",
           cause, length, dump);

    free(dump);
#endif

    return (cause != BRIDGE_CAUSE_SUCCESS);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rax
movq %rdi, %r14
leaq 0xe(%rsp), %rsi
movb $0x54, (%rsi)
movb %dl, 0x1(%rsi)
movzbl %dl, %ecx
movq %rax, %rdx
callq 0x5a98
testl %eax, %eax
js 0x5d75
leaq 0xd(%rsp), %r15
movb $0x0, (%r15)
xorl %ebx, %ebx
movq %r14, %rdi
movl $0x54, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5aeb
xorl %ecx, %ecx
cmpb $0x0, (%r15)
setne %cl
negl %eax
sbbl %ebx, %ebx
orl %ecx, %ebx
jmp 0x5d7a
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_recv_packet
static int funk_recv_packet(struct funk_privdata *funk,
                            struct rfm12_pkt *pkt,
                            int *length)
{
    uint8_t request[] = { BRIDGE_CMD_RECEIVE, 0 };

    int ret = funk_bridge_send(funk, request, sizeof(request), NULL, 0);
    if (ret < 0)
    {
        return ret;
    }

    uint8_t cause = BRIDGE_CAUSE_SUCCESS;
    ret = funk_bridge_recv(funk, request[0], &cause, (uint8_t *)pkt, *length);
    if (ret < 0)
    {
        return -1;
    }

    *length = ret;

#if (FUNK_PACKET_DEBUG == 1)
    char *dump = funk_print_data((uint8_t *)pkt, *length);
    printf("funk_recv_packet() cause=0x%02x length=0x%02x\n%s\n", cause, *length, dump);
    free(dump);
#endif

    return (cause != BRIDGE_CAUSE_SUCCESS);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0xe(%rsp), %rsi
movw $0x52, (%rsi)
movl 0x8(%rdi), %edi
movl $0x2, %edx
callq 0x2090
movq %rax, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x2, %rcx
jne 0x5def
leaq 0xd(%rsp), %rdx
movb $0x0, (%rdx)
movl (%rbx), %r8d
movq %r15, %rdi
movl $0x52, %esi
movq %r14, %rcx
callq 0x5aeb
testl %eax, %eax
js 0x5dea
movl %eax, (%rbx)
xorl %eax, %eax
cmpb $0x0, 0xd(%rsp)
setne %al
jmp 0x5def
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: funk_read_memory
static int funk_read_memory(struct funk_privdata *funk,
                            uint8_t *buffer,
                            uint16_t size,
                            uint8_t memtype,
                            uint16_t address)
{
    struct rfm12_pkt packet;

    packet.dest_address         = funk->address;
    packet.source_address       = 0xCC;             // TODO: changed in bridge
    packet.data_length          = 0x07;
    packet.header_checksum      = 0xCC;             // TODO: calced in bridge
    packet.msg.command          = MSG_CMD_READ_REQUEST;
    packet.msg.seqnum           = ++funk->seqnum;   // TODO: retransmit in bridge?
    packet.msg.cause            = CAUSE_SUCCESS;
    packet.msg.p.read_req.address   = address;
    packet.msg.p.read_req.mem_type  = memtype;
    packet.msg.p.read_req.size      = size;

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

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

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

    memcpy(buffer, packet.msg.p.read_rsp.data, MIN(packet.data_length -3, size));

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movb 0x10(%rdi), %al
leaq 0xd(%rsp), %rsi
movb %al, (%rsi)
movl $0x23cc07cc, 0x1(%rsi)  # imm = 0x23CC07CC
movl 0x18(%rdi), %eax
incl %eax
movl %eax, 0x18(%rdi)
movb %al, 0x5(%rsi)
movb $0x0, 0x6(%rsi)
movw %r8w, 0x7(%rsi)
movb %cl, 0x9(%rsi)
movb %bpl, 0xa(%rsi)
movl $0xb, %edx
callq 0x5d1b
testl %eax, %eax
js 0x5ea5
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %r14, %rdi
callq 0x5d86
testl %eax, %eax
js 0x5eaf
cmpb $-0x1d, 0x11(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jne 0x5e97
cmpb $0x0, 0x13(%rsp)
jne 0x5e97
leaq 0x14(%rsp), %rsi
movzbl -0x5(%rsi), %eax
addl $-0x3, %eax
movzwl %bp, %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movslq %eax, %rdx
movq %rbx, %rdi
callq 0x21b0
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r15d
callq 0x29eb
jmp 0x5e97
callq 0x29c9
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x5e97
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/funkboot.c
// Function: _funk_write_memory
static int __funk_write_memory(struct funk_privdata *funk,
                               uint8_t *buffer,
                               uint16_t size,
                               uint8_t memtype,
                               uint16_t address)
{
    struct rfm12_pkt packet;

    packet.dest_address         = funk->address;
    packet.source_address       = 0xCC;             // TODO: changed in bridge
    packet.data_length          = 0x07 + size;
    packet.header_checksum      = 0xCC;             // TODO: calced in bridge
    packet.msg.command          = MSG_CMD_WRITE_REQUEST;
    packet.msg.seqnum           = ++funk->seqnum;   // TODO: retransmit in bridge?
    packet.msg.cause            = CAUSE_SUCCESS;
    packet.msg.p.write_req.address   = address;
    packet.msg.p.write_req.mem_type  = memtype;
    packet.msg.p.write_req.size      = size;

    memcpy(packet.msg.p.write_req.data, buffer, size);

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

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

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

    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movb 0x10(%rdi), %al
leaq 0x18(%rsp), %rdi
movb %al, -0xb(%rdi)
movb $-0x34, -0xa(%rdi)
leal 0x7(%rdx), %ebp
movb %bpl, -0x9(%rdi)
movw $0x24cc, -0x8(%rdi)     # imm = 0x24CC
movl 0x18(%rbx), %eax
incl %eax
movl %eax, 0x18(%rbx)
movb %al, -0x6(%rdi)
movb $0x0, -0x5(%rdi)
movw %r8w, -0x4(%rdi)
movb %cl, -0x2(%rdi)
movb %dl, -0x1(%rdi)
movl %edx, %edx
callq 0x21b0
movzbl %bpl, %edx
addl $0x4, %edx
leaq 0xd(%rsp), %rsi
movq %rbx, %rdi
callq 0x5d1b
testl %eax, %eax
js 0x5f51
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %rbx, %rdi
callq 0x5d86
testl %eax, %eax
js 0x5f5a
movb 0x11(%rsp), %al
xorb $-0x1c, %al
xorl %ebp, %ebp
orb 0x13(%rsp), %al
setne %bpl
negl %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %rbp
retq
movl %eax, %ebp
callq 0x2a29
jmp 0x5f48
callq 0x2a07
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5f48
nop
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_alloc
static struct multiboot * mpm_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

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

    struct mpm_privdata *mpm = malloc(sizeof(struct mpm_privdata));
    if (mpm == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(mpm, 0x00, sizeof(struct mpm_privdata));
    mpm->device  = NULL;
    mpm->address = 0;

    optarg_register(mpm_optargs, ARRAY_SIZE(mpm_optargs),
                    mpm_optarg_cb, (void *)mpm);

    mboot->privdata = mpm;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
testq %rax, %rax
je 0x5fcd
movq %rax, %rbx
leaq 0x7506(%rip), %rax      # 0xd490
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x58, %esi
callq 0x2160
testq %rax, %rax
je 0x5fc5
movq %rax, %r14
leaq 0x7535(%rip), %rdi      # 0xd4e0
leaq 0x7bb(%rip), %rdx       # 0x676d
movl $0x2, %esi
movq %rax, %rcx
callq 0x72f0
movq %r14, 0x8(%rbx)
jmp 0x5fcf
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_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_free
static void mpm_free(struct multiboot *mboot)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;

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

    free(mpm);
    free(mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x5ff2
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_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_close
static int mpm_close(struct multiboot *mboot)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;

    if (mpm->connected)
    {
        mpm_switch_application(mpm, BOOTTYPE_APPLICATION);
    }

    mpm_close_device(mpm);
    return 0;
}

// Assembly:
pushq %rbx
movq 0x8(%rdi), %rbx
cmpl $0x0, 0xc(%rbx)
je 0x62f3
movq %rbx, %rdi
movl $0x80, %esi
callq 0x6834
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x22c0
movl 0x8(%rbx), %edi
leaq 0x18(%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_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_read
static int mpm_read(struct multiboot *mboot,
                    struct databuf *dbuf, int memtype)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "reading flash" : "reading eeprom";

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

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

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

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rsi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x2122(%rip), %rcx      # 0x8464
leaq 0x2129(%rip), %r15      # 0x8472
cmoveq %rcx, %r15
movq %rsi, 0x20(%rsp)
movzwl 0x12(%rsi,%rax,4), %r12d
movl $0x0, %r14d
testl %r12d, %r12d
je 0x63ca
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movzbl %dl, %ebp
xorl %ebx, %ebx
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %r12d, %r13d
subl %r14d, %r13d
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r13d
cmovgel %eax, %r13d
movzwl %bx, %r8d
movq 0x18(%rsp), %rax
leaq (%rax,%r8), %rsi
movzwl %r13w, %edx
movq 0x20(%rsp), %rdi
movl %ebp, %ecx
callq 0x6be6
testl %eax, %eax
jne 0x63e8
addl %r13d, %ebx
movzwl %bx, %r14d
cmpw %r12w, %r14w
jb 0x6379
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x6402
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_verify
static int mpm_verify(struct multiboot *mboot,
                      struct databuf *dbuf, int memtype)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "verifing flash" : "verifing eeprom";

    uint16_t pos = 0;
    uint8_t comp[READ_BLOCK_SIZE];

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

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

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

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %edx, %eax
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0x2062(%rip), %rcx      # 0x849a
leaq 0x206a(%rip), %rdx      # 0x84a9
cmoveq %rcx, %rdx
movq %rdx, (%rsp)
movl 0x4(%rsi), %edx
movl $0x0, %ebp
testl %edx, %edx
je 0x64eb
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rsi
movq %rsi, 0x28(%rsp)
addq $0x18, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x8(%r12), %rcx
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
movzbl %al, %eax
movl %eax, 0x14(%rsp)
xorl %r15d, %r15d
movq (%rsp), %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rax
callq *(%rax)
movl 0x4(%r12), %ebx
subl %ebp, %ebx
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %ebx
cmovael %eax, %ebx
movzwl %r15w, %r13d
movq 0x28(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
movl %ebx, %edx
movl 0x14(%rsp), %ecx
movl %r13d, %r8d
callq 0x6be6
testl %eax, %eax
jne 0x6504
addq 0x20(%rsp), %r13
movl %ebx, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x21e0
testl %eax, %eax
jne 0x6532
addl %ebx, %r15d
movzwl %r15w, %ebp
movl 0x4(%r12), %edx
cmpl %ebp, %edx
ja 0x6484
movl %ebp, 0x4(%r12)
movq (%rsp), %rdi
movl %ebp, %esi
movl %ebp, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x651e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq (%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rax
callq *(%rax)
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movl %ebp, %edx
callq 0x2b13
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x651e
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_optarg_cb
static int mpm_optarg_cb(int val, const char *arg, void *privdata)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)privdata;

    switch (val)
    {
        case 'a': /* address */
            {
                char *endptr;
                mpm->address = strtol(arg, &endptr, 16);

                if (*endptr != '\0' || mpm->address < 0x01 || mpm->address > 0x7F)
                {
                    fprintf(stderr, "invalid address: '%s'\n", arg);
                    return -1;
                }
            }
            break;

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

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

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

            return -1;

        default:
            return 1;
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movl $0x1, %eax
cmpl $0x63, %edi
jg 0x67bb
cmpl $0x61, %edi
jne 0x67f0
movq %rsi, %rbx
leaq 0x8(%rsp), %r15
movq %rsi, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x21a0
movb %al, 0x10(%r14)
movq (%r15), %rcx
cmpb $0x0, (%rcx)
jne 0x6803
movzbl %al, %eax
addl $-0x80, %eax
cmpl $-0x80, %eax
jbe 0x6803
xorl %eax, %eax
jmp 0x682a
cmpl $0x64, %edi
jne 0x67f7
cmpq $0x0, (%r14)
jne 0x6820
movq 0x6803(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2290
movq %rax, %rcx
movq %rax, (%r14)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x682a
leaq 0x1891(%rip), %rdi      # 0x807a
callq 0x2240
jmp 0x6825
cmpl $0x3f, %edi
jne 0x682a
jmp 0x67fc
cmpl $0x68, %edi
jne 0x682a
callq 0x2b3f
jmp 0x6825
movq 0x67ee(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x1839(%rip), %rsi      # 0x804d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2180
jmp 0x6825
callq 0x2b5d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_switch_application
static int mpm_switch_application(struct mpm_privdata *mpm,
                                  uint8_t application)
{
    uint8_t data[] = { application };

    int ret = mpm_send(mpm, CMD_SWITCH_APPLICATION, data, sizeof(data));
    if (ret < 0)
    {
        return ret;
    }

    uint8_t cause = CAUSE_SUCCESS;
    ret = mpm_recv(mpm, CMD_SWITCH_APPLICATION, &cause, NULL, 0);
    if (ret < 0)
    {
        return ret;
    }

    return (cause != CAUSE_SUCCESS);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x7(%rsp), %rdx
movb %sil, (%rdx)
movl $0x1, %esi
movl $0x1, %ecx
callq 0x6893
testl %eax, %eax
js 0x6886
leaq 0x6(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x69b1
movl %eax, %ecx
xorl %eax, %eax
cmpb $0x0, (%r14)
setne %al
testl %ecx, %ecx
cmovsl %ecx, %eax
jmp 0x688b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_send
static int mpm_send(struct mpm_privdata *mpm, uint8_t command,
                    uint8_t *data, uint16_t length)
{
    struct termios tio;

    if (tcgetattr(mpm->fd, &tio) < 0)
    {
        perror("tcgetattr(tio)");
        return -1;
    }

    tio.c_cflag |= PARODD;

    if (tcsetattr(mpm->fd, TCSAFLUSH, &tio) < 0)
    {
        perror("tcsetattr(tio)");
        return -1;
    }

//     usleep(5000);

    uint8_t address = mpm->address;
    if (write(mpm->fd, &address, sizeof(address)) != sizeof(address))
    {
        perror("write(address)");
        return -1;
    }

    usleep(500);

    tio.c_cflag &= ~(PARODD);

    if (tcsetattr(mpm->fd, TCSAFLUSH, &tio) < 0)
    {
        perror("tcsetattr(tio)");
        return -1;
    }

    uint8_t header[3];
    header[0] = command;
    header[1] = (length >> 8) & 0xFF;
    header[2] = length & 0xFF;

    if (write(mpm->fd, header, sizeof(header)) != sizeof(header))
    {
        perror("write(header)");
        return -1;
    }

    if (data != NULL && length != 0)
    {
        if (write(mpm->fd, data, length) != length)
        {
            perror("write(data)");
            return -1;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movl 0x8(%rdi), %edi
leaq 0xc(%rsp), %rsi
callq 0x21f0
testl %eax, %eax
js 0x6981
leaq 0xc(%rsp), %rdx
orb $0x2, 0x9(%rdx)
movl 0x8(%r15), %edi
movl $0x2, %esi
callq 0x2200
testl %eax, %eax
js 0x6978
movb 0x10(%r15), %al
leaq 0x8(%rsp), %rsi
movb %al, (%rsi)
movl 0x8(%r15), %edi
movl $0x1, %edx
callq 0x2090
cmpq $0x1, %rax
jne 0x698a
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x22c0
leaq 0xc(%rsp), %rdx
andb $-0x3, 0x9(%rdx)
movl 0x8(%r15), %edi
movl $0x2, %esi
callq 0x2200
testl %eax, %eax
js 0x6978
leaq 0x9(%rsp), %rsi
movb %bpl, (%rsi)
movb %bh, 0xa(%rsp)
movb %bl, 0x2(%rsi)
movl 0x8(%r15), %edi
movl $0x3, %edx
callq 0x2090
cmpq $0x3, %rax
jne 0x6993
testq %r14, %r14
sete %al
testw %bx, %bx
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x69a4
movl 0x8(%r15), %edi
movzwl %bx, %ebx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2090
cmpq %rbx, %rax
je 0x69a4
leaq 0x29ea(%rip), %rdi      # 0x9360
jmp 0x699a
leaq 0x29b5(%rip), %rdi      # 0x9334
jmp 0x699a
leaq 0x299d(%rip), %rdi      # 0x9325
jmp 0x699a
leaq 0x29b2(%rip), %rdi      # 0x9343
jmp 0x699a
leaq 0x29b8(%rip), %rdi      # 0x9352
callq 0x2240
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq