LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/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 0x5ae1
testb %bpl, %bpl
je 0x5adf
movl 0x8(%r15), %edi
movzbl %bpl, %r15d
movq %r14, %rsi
movq %r15, %rdx
callq 0x2090
cmpq %r15, %rax
jne 0x5ae1
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 %edi, %ebx
leal 0x3f(%rbx), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edi
andl $-0x40, %edi
movl %ebx, %ecx
subl %edi, %ecx
movl $0x1, %r13d
shlq %cl, %r13
movl %edx, %ebp
movq %rsi, 0x8(%rsp)
sarl $0x6, %eax
movslq %eax, %r15
leal 0x1(%rbx), %r12d
xorl %r14d, %r14d
movups 0x3448(%rip), %xmm0     # 0x90b8
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,%r15,8)
movl %r12d, %edi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x21b0
movl $0x3, %ecx
testl %eax, %eax
je 0x5d0d
cmpl $-0x1, %eax
je 0x5d17
testq %r13, 0x20(%rsp,%r15,8)
je 0x5d0b
movl %r14d, %esi
addq 0x8(%rsp), %rsi
movl %ebp, %eax
subl %r14d, %eax
movslq %eax, %rdx
movl %ebx, %edi
callq 0x2150
leal (%r14,%rax), %ecx
xorl %edx, %edx
cmpl %ebp, %ecx
sete %dl
testl %eax, %eax
cmovnsl %ecx, %r14d
leal (%rdx,%rdx,2), %ecx
movl $0x1, %eax
cmovsl %eax, %ecx
jmp 0x5d0d
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x5c69
jmp 0x5d2a
leaq 0x2739(%rip), %rdi      # 0x8457
callq 0x2230
movl $0x1, %ecx
jmp 0x5d0d
cmpl $0x3, %ecx
je 0x5d35
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 0x5a9b
testl %eax, %eax
js 0x5da4
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 0x5aee
xorl %ecx, %ecx
cmpb $0x0, (%r15)
setne %cl
negl %eax
sbbl %ebx, %ebx
orl %ecx, %ebx
jmp 0x5da6
movl %eax, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_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 0x5e1b
leaq 0xd(%rsp), %rdx
movb $0x0, (%rdx)
movzbl 0xe(%rsp), %esi
movl (%rbx), %r8d
movq %r15, %rdi
movq %r14, %rcx
callq 0x5aee
testl %eax, %eax
js 0x5e16
movl %eax, (%rbx)
xorl %eax, %eax
cmpb $0x0, 0xd(%rsp)
setne %al
jmp 0x5e1b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/funkboot.c
// Function: funk_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 0x5d4a
testl %eax, %eax
js 0x5ed1
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %r14, %rdi
callq 0x5db2
testl %eax, %eax
js 0x5edb
cmpb $-0x1d, 0x11(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jne 0x5ec3
cmpb $0x0, 0x13(%rsp)
jne 0x5ec3
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 0x21a0
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r15d
callq 0x2a2a
jmp 0x5ec3
callq 0x2a08
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x5ec3
// File: /workspace/github_c_makefile_star2_O1/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 0x21a0
movzbl %bpl, %edx
addl $0x4, %edx
leaq 0xd(%rsp), %rsi
movq %rbx, %rdi
callq 0x5d4a
testl %eax, %eax
js 0x5f7d
leaq 0x8(%rsp), %rdx
movl $0x2b, (%rdx)
leaq 0xd(%rsp), %rsi
movq %rbx, %rdi
callq 0x5db2
testl %eax, %eax
js 0x5f86
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 0x2a68
jmp 0x5f74
callq 0x2a46
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5f74
nop
// File: /workspace/github_c_makefile_star2_O1/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 $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x6017
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
leaq 0x74c5(%rip), %rax      # 0xd480
movq %rax, (%rbx)
movl $0x58, %edi
callq 0x21c0
testq %rax, %rax
je 0x600f
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x50(%rax)
leaq 0x74db(%rip), %rdi      # 0xd4d0
leaq 0x767(%rip), %rdx       # 0x6763
movl $0x2, %esi
movq %rax, %rcx
callq 0x72e0
movq %r14, 0x8(%rbx)
jmp 0x6019
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 0x603c
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 0x6345
movq %rbx, %rdi
movl $0x80, %esi
callq 0x682a
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x22b0
movl 0x8(%rbx), %edi
leaq 0x18(%rbx), %rdx
xorl %esi, %esi
callq 0x21f0
movl 0x8(%rbx), %edi
callq 0x2140
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 %rdi, %rbx
movq 0x8(%rdi), %rdi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x20d7(%rip), %rcx      # 0x8464
leaq 0x20de(%rip), %r12      # 0x8472
cmoveq %rcx, %r12
movq %rdi, 0x20(%rsp)
movzwl 0x12(%rdi,%rax,4), %r13d
movq %rsi, 0x10(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movzbl %dl, %eax
movl %eax, 0xc(%rsp)
movzwl %r15w, %r14d
cmpw %r13w, %r14w
jae 0x6426
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
movl %r13d, %ebp
subl %r14d, %ebp
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %ebp
cmovgel %eax, %ebp
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %rsi
movzwl %bp, %edx
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %ecx
movl %r14d, %r8d
callq 0x6c05
movl %eax, %r14d
testl %eax, %eax
je 0x6417
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
jmp 0x641a
addl %ebp, %r15d
testl %r14d, %r14d
je 0x63bb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x643d
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0x2027(%rip), %rax      # 0x849a
leaq 0x202f(%rip), %rbp      # 0x84a9
cmoveq %rax, %rbp
movq %rdi, 0x8(%rsp)
leaq 0x18(%rdi), %r12
leaq 0x8(%rsi), %rax
movq %rax, 0x10(%rsp)
movl $0x0, (%rsp)
movzbl %dl, %eax
movl %eax, 0x4(%rsp)
leaq 0x20(%rsp), %r13
movzwl (%rsp), %ebx
movl 0x4(%r14), %edx
cmpl %ebx, %edx
jbe 0x6545
movq %rbp, %rdi
movl %ebx, %esi
callq *(%r12)
movq %r12, %r15
movl 0x4(%r14), %r12d
subl %ebx, %r12d
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
cmovael %eax, %r12d
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
callq 0x6c05
testl %eax, %eax
je 0x6501
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *(%r15)
xorl %eax, %eax
jmp 0x651f
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rsi
movl %r12d, %edx
movq %r13, %rdi
callq 0x21d0
testl %eax, %eax
jne 0x6531
addl %r12d, (%rsp)
movb $0x1, %al
movq %r15, %r12
testb %al, %al
leaq 0x20(%rsp), %r13
jne 0x64a3
jmp 0x655c
movq %r15, %r12
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x2b6b
xorl %eax, %eax
jmp 0x6522
movl %ebx, 0x4(%r14)
movq %rbp, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x6561
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 0x67b1
cmpl $0x61, %edi
jne 0x67e6
movq %rsi, %rbx
leaq 0x8(%rsp), %r15
movq %rsi, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x2190
movb %al, 0x10(%r14)
movq (%r15), %rcx
cmpb $0x0, (%rcx)
jne 0x67f9
movzbl %al, %eax
addl $-0x80, %eax
cmpl $-0x80, %eax
jbe 0x67f9
xorl %eax, %eax
jmp 0x6820
cmpl $0x64, %edi
jne 0x67ed
cmpq $0x0, (%r14)
jne 0x6816
movq 0x680d(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2280
movq %rax, %rcx
movq %rax, (%r14)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x6820
leaq 0x189b(%rip), %rdi      # 0x807a
callq 0x2230
jmp 0x681b
cmpl $0x3f, %edi
jne 0x6820
jmp 0x67f2
cmpl $0x68, %edi
jne 0x6820
callq 0x2b97
jmp 0x681b
movq 0x67f8(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x1843(%rip), %rsi      # 0x804d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2170
jmp 0x681b
callq 0x2bb5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/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 0x6882
testl %eax, %eax
js 0x687a
leaq 0x6(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x69a0
movl %eax, %ecx
xorl %eax, %eax
cmpb $0x0, (%r14)
setne %al
testl %ecx, %ecx
cmovsl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x21e0
testl %eax, %eax
js 0x6970
leaq 0xc(%rsp), %rdx
orb $0x2, 0x9(%rdx)
movl 0x8(%r15), %edi
movl $0x2, %esi
callq 0x21f0
testl %eax, %eax
js 0x6967
movb 0x10(%r15), %al
leaq 0x8(%rsp), %rsi
movb %al, (%rsi)
movl 0x8(%r15), %edi
movl $0x1, %edx
callq 0x2090
cmpq $0x1, %rax
jne 0x6979
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x22b0
leaq 0xc(%rsp), %rdx
andb $-0x3, 0x9(%rdx)
movl 0x8(%r15), %edi
movl $0x2, %esi
callq 0x21f0
testl %eax, %eax
js 0x6967
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 0x6982
testq %r14, %r14
sete %al
testw %bx, %bx
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x6993
movl 0x8(%r15), %edi
movzwl %bx, %ebx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2090
cmpq %rbx, %rax
je 0x6993
leaq 0x29c3(%rip), %rdi      # 0x9328
jmp 0x6989
leaq 0x298e(%rip), %rdi      # 0x92fc
jmp 0x6989
leaq 0x2976(%rip), %rdi      # 0x92ed
jmp 0x6989
leaq 0x298b(%rip), %rdi      # 0x930b
jmp 0x6989
leaq 0x2991(%rip), %rdi      # 0x931a
callq 0x2230
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_read_memory
static int mpm_read_memory(struct mpm_privdata *mpm,
                           uint8_t *buffer, uint16_t size,
                           uint8_t memtype, uint16_t address)
{
    uint8_t param[5] = {
        memtype,
        (address >> 8) & 0xFF,
        (address & 0xFF),
        (size >> 8) & 0xFF,
        (size & 0xFF)
    };

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

    uint8_t cause = CAUSE_SUCCESS;
    ret = mpm_recv(mpm, CMD_READ_MEMORY, &cause, buffer, size);
    if (ret < 0)
    {
        return ret;
    }

    return (cause != CAUSE_SUCCESS);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movl %r8d, %eax
movl %edx, %ebx
movq %rdi, %r14
leaq 0x3(%rsp), %rdx
movb %cl, (%rdx)
movb %ah, 0x4(%rsp)
movb %al, 0x2(%rdx)
movb %bh, 0x6(%rsp)
movb %bl, 0x4(%rdx)
movl $0x11, %esi
movl $0x5, %ecx
callq 0x6882
testl %eax, %eax
js 0x6c74
leaq 0x2(%rsp), %r12
movb $0x0, (%r12)
movzwl %bx, %r8d
movq %r14, %rdi
movl $0x11, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x69a0
movl %eax, %ecx
xorl %eax, %eax
cmpb $0x0, (%r12)
setne %al
testl %ecx, %ecx
cmovsl %ecx, %eax
jmp 0x6c79
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/multiboot.c
// Function: progress_mode1_cb
static void progress_mode1_cb(const char *msg, int pos, int size)
{
    if (pos != -1 && size > 0)
    {
        char stars[51];
        int i;
        int count = (pos * 50 / size);

        for (i = 0; i < 50; i++)
        {
            stars[i] = (i < count) ? '*' : ' ';
        }

        stars[50] = '\0';
        printf("%-15s: [%s] (%d)\r", msg, stars, pos);
    }

    if (pos == size)
    {
        printf("\n");
    }
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movl %esi, %ebp
cmpl $-0x1, %esi
sete %al
testl %edx, %edx
setle %cl
orb %al, %cl
jne 0x7030
movq %rdi, %rsi
imull $0x32, %ebp, %eax
cltd
idivl %ebx
cltq
xorl %ecx, %ecx
movl $0x2a, %edx
cmpq %rax, %rcx
movl $0x20, %edi
cmovll %edx, %edi
movb %dil, (%rsp,%rcx)
incq %rcx
cmpq $0x32, %rcx
jne 0x7001
movq %rsp, %rdx
movb $0x0, 0x32(%rdx)
leaq 0x2470(%rip), %rdi      # 0x9497
movl %ebp, %ecx
xorl %eax, %eax
callq 0x20f0
cmpl %ebx, %ebp
jne 0x703e
movl $0xa, %edi
callq 0x2040
addq $0x38, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/multiboot.c
// Function: main_optarg_cb
static int main_optarg_cb(int val, const char *arg, void *privdata)
{
    struct multiboot *mboot = (struct multiboot *)privdata;

    switch (val)
    {
        case 'r': /* read */
            if ((mboot->ops->read == NULL) ||
                (add_action(mboot, ACTION_READ, arg) < 0)
               )
            {
                return -1;
            }
            break;

        case 'w': /* write */
            if ((mboot->ops->write == NULL) ||
                (add_action(mboot, ACTION_WRITE, arg) < 0)
               )
            {
                return -1;
            }
            break;

        case 'n': /* no verify after write */
            mboot->verify = 0;
            break;

        case 'p':
            switch (*arg)
            {
                case '0':
                    mboot->progress_cb = progress_mode0_cb;
                    break;

                case '1':
                    mboot->progress_cb = progress_mode1_cb;
                    break;

                case '2':
                    mboot->progress_cb = progress_mode2_cb;
                    break;

                default:
                    fprintf(stderr, "invalid progress bar mode: '%s'\n", arg);
                    return -1;
            }
            break;
    }

    return 0;
}

// Assembly:
pushq %rbx
addl $-0x6e, %edi
cmpl $0x9, %edi
ja 0x70db
movq %rsi, %rax
leaq 0x2348(%rip), %rcx      # 0x93a4
movslq (%rcx,%rdi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
movl $0x0, 0x10(%rdx)
jmp 0x70db
movq (%rdx), %rcx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x0, 0x38(%rcx)
je 0x70dd
movq %rdx, %rdi
movl $0x1, %esi
jmp 0x70b9
movzbl (%rax), %ecx
cmpl $0x32, %ecx
je 0x70c7
cmpl $0x31, %ecx
je 0x70d0
cmpl $0x30, %ecx
jne 0x70e1
leaq 0x1a1(%rip), %rax       # 0x7241
jmp 0x70d7
movq (%rdx), %rcx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x0, 0x48(%rcx)
je 0x70dd
movq %rdx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x7103
testl %eax, %eax
jns 0x70db
jmp 0x70dd
leaq 0x174(%rip), %rax       # 0x7242
jmp 0x70d7
leaq -0x101(%rip), %rax      # 0x6fd6
movq %rax, 0x18(%rdx)
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
retq
movq 0x5f10(%rip), %rcx      # 0xcff8
movq (%rcx), %rdi
leaq 0x23da(%rip), %rsi      # 0x94cc
movq %rax, %rdx
xorl %eax, %eax
callq 0x2170
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x70dd
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/multiboot.c
// Function: add_action
static int add_action(struct multiboot *mboot, int mode, const char *arg)
{
    struct mboot_action *action = malloc(sizeof(struct mboot_action));
    if (action == NULL)
    {
        perror("malloc()");
        return -1;
    }

    char *argcopy = strdup(arg);
    if (argcopy == NULL)
    {
        perror("strdup()");
        free(action);
        return -1;
    }

    char *tok = strtok(argcopy, ":");
    if (tok == NULL)
    {
        fprintf(stderr, "invalid argument: '%s'\n", arg);
        free(argcopy);
        free(action);
        return -1;
    }

    action->memtype = mboot->ops->get_memtype(mboot, tok);
    if (action->memtype == -1)
    {
        fprintf(stderr, "invalid memtype: '%s'\n", tok);
        free(argcopy);
        free(action);
        return -1;
    }

    tok = strtok(NULL, ":");
    if (tok == NULL)
    {
        fprintf(stderr, "invalid argument: '%s'\n", arg);
        free(argcopy);
        free(action);
        return -1;
    }

    action->filename = strdup(tok);
    if (action->filename == NULL)
    {
        perror("strdup()");
        free(argcopy);
        free(action);
        return -1;
    }

    action->mode = mode;

    list_add_tail(&action->list, &action_list);
    free(argcopy);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r12
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x71d8
movq %rax, %rbx
movq %r15, %rdi
callq 0x2280
testq %rax, %rax
je 0x71e6
movq %rax, %r14
leaq 0x23a6(%rip), %rsi      # 0x94ed
movq %rax, %rdi
callq 0x2240
testq %rax, %rax
je 0x71c2
movq %rax, %r13
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x18(%rax)
movl %eax, 0x18(%rbx)
cmpl $-0x1, %eax
je 0x71f4
leaq 0x2376(%rip), %rsi      # 0x94ed
xorl %edi, %edi
callq 0x2240
testq %rax, %rax
je 0x71c2
movq %rax, %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x7211
movl %ebp, 0x1c(%rbx)
movq 0x643a(%rip), %rax      # 0xd5d8
leaq 0x642b(%rip), %rcx      # 0xd5d0
movq %rbx, 0x642c(%rip)      # 0xd5d8
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
movq %rbx, (%rax)
movq %r14, %rdi
callq 0x2030
xorl %eax, %eax
jmp 0x7232
movq 0x5e2f(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x231c(%rip), %rsi      # 0x94ef
movq %r15, %rdx
jmp 0x7208
leaq 0x1854(%rip), %rdi      # 0x8a33
callq 0x2230
jmp 0x722d
leaq 0xe8d(%rip), %rdi       # 0x807a
callq 0x2230
jmp 0x7225
movq 0x5dfd(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x2302(%rip), %rsi      # 0x9507
movq %r13, %rdx
xorl %eax, %eax
callq 0x2170
jmp 0x721d
leaq 0xe62(%rip), %rdi       # 0x807a
callq 0x2230
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/multiboot.c
// Function: progress_mode2_cb
static void progress_mode2_cb(const char *msg, int pos, int size)
{
    static int old_count;

    if (pos != -1 && size > 0)
    {
        if (pos == 0)
        {
            old_count = 0;
            printf("%-15s: [", msg);

        }
        else if (pos <=size)
        {
            int i;
            int count = (pos * 50 / size);

            for (i = old_count; i < count; i++)
            {
                printf("*");
            }

            old_count = count;

            if (pos == size)
            {
                printf("] (%d)\n", pos);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
cmpl $-0x1, %esi
sete %al
testl %edx, %edx
setle %cl
orb %al, %cl
jne 0x72ad
testl %ebx, %ebx
je 0x72b8
movl %edx, %ebp
cmpl %edx, %ebx
jg 0x72ad
imull $0x32, %ebx, %eax
cltd
idivl %ebp
movl %eax, %r14d
movl %eax, %r15d
subl 0x642d(%rip), %r15d     # 0xd6a4
jle 0x7288
movl $0x2a, %edi
callq 0x2040
decl %r15d
jne 0x7279
movl %r14d, 0x6415(%rip)     # 0xd6a4
cmpl %ebp, %ebx
jne 0x72ad
leaq 0x228d(%rip), %rdi      # 0x9527
movl %ebx, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rsi
movl $0x0, 0x63df(%rip)      # 0xd6a4
leaq 0x2252(%rip), %rdi      # 0x951e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/optarg.c
// Function: optarg_register
int optarg_register(const struct option *opts, int count,
                    int (* parser_cb)(int val, const char *arg, void *privdata),
                    void *privdata)
{
    struct optarg_entry *entry;

    entry = malloc(sizeof(struct optarg_entry));
    if (entry == NULL)
    {
        return -1;
    }

    entry->opts         = opts;     /* TODO: copy? */
    entry->count        = count;
    entry->parser_cb    = parser_cb;
    entry->privdata     = privdata;

    list_add_tail(&entry->list, &option_list);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movl $0x30, %edi
callq 0x21c0
testq %rax, %rax
je 0x7333
movq %r15, 0x10(%rax)
movl %ebp, 0x18(%rax)
movq %r14, 0x20(%rax)
movq %rbx, 0x28(%rax)
movq 0x62d1(%rip), %rcx      # 0xd5e8
leaq 0x62c2(%rip), %rdx      # 0xd5e0
movq %rax, 0x62c3(%rip)      # 0xd5e8
movq %rdx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x7338
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/optarg.c
// Function: optarg_free
void optarg_free(void)
{
    struct optarg_entry *entry, *entry_tmp;

    list_for_each_entry_safe(entry, entry_tmp, &option_list, list)
    {
        list_del(&entry->list);
        free(entry);
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq 0x6292(%rip), %rdi      # 0xd5e0
leaq 0x628b(%rip), %rbx      # 0xd5e0
cmpq %rbx, %rdi
je 0x737b
movq (%rdi), %r14
movq 0x8(%rdi), %rax
movq %rax, 0x8(%r14)
movq %r14, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
callq 0x2030
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x735a
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/twiboot.c
// Function: twi_alloc
static struct multiboot * twi_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

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

    struct twi_privdata *twi = malloc(sizeof(struct twi_privdata));
    if (twi == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(twi, 0x00, sizeof(struct twi_privdata));
    twi->device  = NULL;
    twi->address = 0;

    optarg_register(twi_optargs, ARRAY_SIZE(twi_optargs), twi_optarg_cb, (void *)twi);

    mboot->privdata = twi;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x762f
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
leaq 0x6009(%rip), %rax      # 0xd5f0
movq %rax, (%rbx)
movl $0x20, %edi
callq 0x21c0
testq %rax, %rax
je 0x7627
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0x6033(%rip), %rdi      # 0xd640
leaq 0x715(%rip), %rdx       # 0x7d29
movl $0x3, %esi
movq %rax, %rcx
callq 0x72e0
movq %r14, 0x8(%rbx)
jmp 0x7631
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/twiboot.c
// Function: twi_free
static void twi_free(struct multiboot *mboot)
{
    struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata;

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

    free(twi);
    free(mboot);
}

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

    if (twi->connected && !twi->stay_in_bootloader)
    {
        twi_switch_application(twi, BOOTTYPE_APPLICATION);
    }

    twi_close_device(twi);
    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq 0x8(%rdi), %rbx
cmpl $0x0, 0x10(%rbx)
je 0x7947
cmpl $0x0, 0x14(%rbx)
jne 0x7947
leaq 0xe(%rsp), %rsi
movw $0x8001, (%rsi)         # imm = 0x8001
movl 0xc(%rbx), %edi
movl $0x2, %edx
callq 0x7e64
cmpl $0x0, 0x10(%rbx)
je 0x7955
movl 0xc(%rbx), %edi
callq 0x2140
movl $0x0, 0x10(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/twiboot.c
// Function: twi_read
static int twi_read(struct multiboot *mboot,
                    struct databuf *dbuf,
                    int memtype)
{
    struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "reading flash" : "reading eeprom";

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

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

        uint8_t len = MIN(READ_BLOCK_SIZE, size - pos);

        if (twi_read_memory(twi, dbuf->data + pos, len, memtype, pos))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0xadc(%rip), %rcx       # 0x8464
leaq 0xae3(%rip), %r12       # 0x8472
cmoveq %rcx, %r12
movq %rdi, 0x20(%rsp)
movzwl 0x1a(%rdi,%rax,2), %r13d
movq %rsi, 0x10(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movzbl %dl, %eax
movl %eax, 0xc(%rsp)
movzwl %r15w, %r14d
cmpw %r13w, %r14w
jae 0x7a26
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
movl %r13d, %ebp
subl %r14d, %ebp
movl $0x80, %eax
cmpl %eax, %ebp
cmovgel %eax, %ebp
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %rsi
movzbl %bpl, %edx
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %ecx
movl %r14d, %r8d
callq 0x7dff
movl %eax, %r14d
testl %eax, %eax
je 0x7a13
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
jmp 0x7a1a
movzbl %bpl, %eax
addl %eax, %r15d
testl %r14d, %r14d
je 0x79b6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x7a3d
movq 0x10(%rsp), %rax
movl %r14d, 0x4(%rax)
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq *0x18(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/twiboot.c
// Function: twi_verify
static int twi_verify(struct multiboot *mboot, struct databuf *dbuf, int memtype)
{
    struct twi_privdata *twi = (struct twi_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);

        int len = MIN(READ_BLOCK_SIZE, dbuf->length - pos);
        if (twi_read_memory(twi, 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 $0xa8, %rsp
movq %rsi, %r14
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
cmpl $0x1, %edx
leaq 0xa27(%rip), %rax       # 0x849a
leaq 0xa2f(%rip), %rbp       # 0x84a9
cmoveq %rax, %rbp
movq %rdi, 0x8(%rsp)
leaq 0x18(%rdi), %r12
leaq 0x8(%rsi), %rax
movq %rax, 0x10(%rsp)
movl $0x0, (%rsp)
movzbl %dl, %eax
movl %eax, 0x4(%rsp)
leaq 0x20(%rsp), %r13
movzwl (%rsp), %ebx
movl 0x4(%r14), %edx
cmpl %ebx, %edx
jbe 0x7b45
movq %rbp, %rdi
movl %ebx, %esi
callq *(%r12)
movq %r12, %r15
movl 0x4(%r14), %r12d
subl %ebx, %r12d
movl $0x80, %eax
cmpl %eax, %r12d
cmovael %eax, %r12d
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
callq 0x7dff
testl %eax, %eax
je 0x7b01
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *(%r15)
xorl %eax, %eax
jmp 0x7b1f
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rsi
movl %r12d, %edx
movq %r13, %rdi
callq 0x21d0
testl %eax, %eax
jne 0x7b31
addl %r12d, (%rsp)
movb $0x1, %al
movq %r15, %r12
testb %al, %al
leaq 0x20(%rsp), %r13
jne 0x7aa3
jmp 0x7b5c
movq %r15, %r12
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x2e34
xorl %eax, %eax
jmp 0x7b22
movl %ebx, 0x4(%r14)
movq %rbp, %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x7b61
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/twiboot.c
// Function: twi_write
static int twi_write(struct multiboot *mboot,
                     struct databuf *dbuf,
                     int memtype)
{
    struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata;
    char *progress_msg = (memtype == MEMTYPE_FLASH) ? "writing flash" : "writing eeprom";

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

        uint8_t len = (memtype == MEMTYPE_FLASH) ? twi->pagesize : WRITE_BLOCK_SIZE;

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

        if (twi_write_memory(twi, dbuf->data + pos, len, memtype, pos))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movq 0x8(%rdi), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, %edx
leaq 0x939(%rip), %rax       # 0x84d8
leaq 0x940(%rip), %rcx       # 0x84e6
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movzwl %ax, %ebx
movl 0x4(%r12), %edx
cmpl %ebx, %edx
jbe 0x7d02
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rdi
movl %ebx, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
movl $0x10, %eax
cmpl $0x1, %r15d
jne 0x7bf1
movq 0x8(%rsp), %rax
movzbl 0x18(%rax), %eax
movq %r12, %r14
movl 0x4(%r12), %r13d
subl %ebx, %r13d
cmpl %r13d, %eax
cmovbl %eax, %r13d
movl %r13d, %r12d
cmpb $0x1, %r15b
jne 0x7c23
movq 0x8(%rsp), %rax
movzbl 0x18(%rax), %r12d
leal -0x1(%r12), %eax
testl %ebx, %eax
jne 0x7ce1
addl $0x4, %r12d
movq %r12, %rdi
callq 0x21c0
testq %rax, %rax
je 0x7ca8
movq %rax, %rbp
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rsi
movb $0x2, (%rbp)
movb %r15b, 0x1(%rbp)
movb %bh, 0x2(%rbp)
movb %bl, 0x3(%rbp)
movq %rbp, %rbx
addq $0x4, %rbx
movq %rbx, %rdi
movq %r13, %rdx
callq 0x21a0
cmpb $0x1, %r15b
jne 0x7c82
addq %r13, %rbx
movq 0x8(%rsp), %rax
movzbl 0x18(%rax), %edx
subq %r13, %rdx
movq %rbx, %rdi
movl $0xff, %esi
callq 0x2120
movq 0x8(%rsp), %rax
movl 0xc(%rax), %edi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x7e64
movl %eax, %ebx
movq %rbp, %rdi
callq 0x2030
cmpl %r12d, %ebx
sete %bpl
jmp 0x7caa
xorl %ebp, %ebp
testb %bpl, %bpl
movq %r14, %r12
je 0x7cbb
movl 0x4(%rsp), %eax
addl %r13d, %eax
jmp 0x7cd6
movq 0x10(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rax
callq *0x18(%rax)
movl 0x4(%rsp), %eax
testb %bpl, %bpl
jne 0x7bba
jmp 0x7d15
movq 0x5310(%rip), %rax      # 0xcff8
movq (%rax), %rdi
xorl %ebp, %ebp
leaq 0x1ba2(%rip), %rsi      # 0x9896
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2170
jmp 0x7caa
movq 0x10(%rsp), %rdi
movl %ebx, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %eax, %eax
jmp 0x7d1a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq