// File: /workspace/github_c_makefile_star2_O2/jech[P]shncpd/receive.c
// Function: parse_node_state
int
parse_node_state(struct node *node)
{
    const unsigned char *buf = node->data;
    int buflen = node->datalen;
    int i = 0, j, rc;
    struct node_neighbour *nn = NULL;
    int numnn = 0, maxnn = 0;
    struct external **exts = NULL;
    int numexts = 0, maxexts = 0;

    for(j = 0; j < numneighs; j++) {
        if(id_eq(neighs[j].id, node->id))
            neighs[j].keepalive_interval = 0;
    }

    while(i < buflen) {
        unsigned const char *tlv = buf + i;
        int type, bodylen;

        if(buflen - i < 4) {
            fprintf(stderr, "Received truncated TLV.\n");
            goto fail;
        }

        DO_NTOHS(type, tlv);
        DO_NTOHS(bodylen, tlv + 2);
        if(buflen - i < 4 + bodylen) {
            fprintf(stderr, "Received truncated TLV.\n");
            goto fail;
        }

        switch(type) {
        case 7:
            fprintf(stderr, "Received fragmented nonsense.\n");
            goto fail;
        case 8: {
            if(bodylen < 12) {
                fprintf(stderr, "Truncated neighbour TLV.\n");
                break;
            }

            if(numnn >= maxnn) {
                struct node_neighbour *nnn =
                    realloc(nn,
                            (2 * maxnn + 2) *
                            sizeof(struct node_neighbour));
                if(nnn == NULL) {
                    fprintf(stderr, "Eek.\n");
                    /* Oh, well. */
                    break;
                }
                nn = nnn;
                maxnn = 2 * maxnn + 2;
            }

            memcpy(nn[numnn].neigh, tlv + 4, 4);
            DO_NTOHL(nn[numnn].nei, tlv + 8);
            DO_NTOHL(nn[numnn].lei, tlv + 12);
            debugf("     NEIGHBOR %s (nei=%u, lei=%u)\n",
                   format_32(nn[numnn].neigh),
                   nn[numnn].nei, nn[numnn].lei);
            numnn++;
            break;
        }
        case 9: {
            unsigned eid, interval;
            if(bodylen < 8) {
                fprintf(stderr, "Truncated KEEP-ALIVE-INTERVAL.\n");
                break;
            }
            DO_NTOHL(eid, tlv + 4);
            DO_NTOHL(interval, tlv + 8);
            debugf("    KEEP-ALIVE-INTERVAL %u (eid=%u)\n", interval, eid);
            for(j = 0; j < numneighs; j++) {
                if(id_eq(neighs[j].id, node->id) && neighs[j].eid == eid)
                    neighs[j].keepalive_interval =
                        interval ? interval : 0xFFFFFFFF;
            }
            break;
        }
        case 32: {
            if(bodylen < 4) {
                debugf("Truncated VERSION\n");
                goto fail;
            }
            debugf("     VERSION\n");
            memcpy(node->capabilities, tlv + 6, 2);
            break;
        }
        case 33: {
            struct external *ext;
            debugf("     EXTERNAL-CONNECTION\n");
            ext = parse_external(node, tlv + 4, bodylen);
            if(ext) {
                if(numexts >= maxexts) {
                    struct external **e =
                        realloc(exts,
                                (2 * maxexts + 2) * sizeof(struct external *));
                    if(e == NULL) {
                        fprintf(stderr, "Eek.\n");
                        break;
                    }
                    maxexts = 2 * maxexts + 2;
                    exts = e;
                }
                exts[numexts++] = ext;
            }
            break;
        }
        case 35: {
            unsigned char plen;
            struct in6_addr addr;
            int prio;
            unsigned int eid;
            struct prefix_list *pl;

            if(bodylen < 6) {
                fprintf(stderr, "Truncated ASSIGNED-PREFIX.\n");
                break;
            }
            DO_NTOHL(eid, tlv + 4);
            plen = *(tlv + 9);
            if(bodylen < 6 + (plen + 7) / 8) {
                fprintf(stderr, "Truncated ASSIGNED-PREFIX.\n");
                break;
            }
            prio = tlv[8] & 0x0F;
            parse_pref(&addr, tlv + 10, plen);
            debugf("     ASSIGNED-PREFIX ");
            debug_prefix_raw(&addr, plen);
            debugf(" (%d, prio=%d)\n", eid, prio);
            pl = prefix_list_cons(node->assigned,
                                  &addr, plen, node->id, eid, prio);
            if(pl)
                node->assigned = pl;
            break;
        }
        case 36: {
            unsigned int eid;
            struct prefix_list *pl;
            struct in6_addr addr;
            if(bodylen < 20) {
                fprintf(stderr, "Truncated NODE-ADDRESS.\n");
                break;
            }
            DO_NTOHL(eid, tlv + 4);
            memcpy(&addr, tlv + 8, 16);
            debugf("     NODE-ADDRESS ");
            debug_address(&addr);
            debugf(" %d\n",eid);
            pl = prefix_list_cons(node->addresses,
                                  &addr, 128, node->id, eid, 0);
            if(pl)
                node->addresses = pl;
            break;
        }
        default:
            if(debug_level >= 3)
                debugf("     %d: %d\n", type, bodylen);
            break;
        }
        i += 4 + bodylen;
        i += -i & 3;
    }

    rc = 1;
    goto done;

 fail:
    rc = -1;

 done:
    if(node->neighs)
        free(node->neighs);
    node->neighs = nn;
    node->numneighs = numnn;
    if(node->exts) {
        for(i = 0; i < node->numexts; i++)
            destroy_external(node->exts[i]);
        free(node->exts);
    }
    node->exts = exts;
    node->numexts = numexts;

    return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r12
movq 0x10(%rdi), %r13
movl 0x18(%rdi), %eax
movl %eax, 0x54(%rsp)
leaq 0xba54(%rip), %rax      # 0x112a8
movl (%rax), %ebx
leaq 0x8(%rdi), %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
testl %ebx, %ebx
cmovlel %r14d, %ebx
shlq $0x6, %rbx
leaq 0xc61d(%rip), %rcx      # 0x11e90
cmpq %r14, %rbx
je 0x58a1
leaq (%rcx,%r14), %rdi
addq $0x8, %rdi
movq 0x48(%rsp), %rsi
callq 0x5827
leaq 0xc5ff(%rip), %rcx      # 0x11e90
testl %eax, %eax
je 0x589b
andl $0x0, 0x38(%rcx,%r14)
addq $0x40, %r14
jmp 0x5873
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
movq $0x0, 0x58(%rsp)
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x38(%rsp)
xorl %ebx, %ebx
movq %r12, 0x40(%rsp)
movq %r13, 0x30(%rsp)
movl 0x54(%rsp), %ecx
subl %ebx, %ecx
jle 0x5eae
cmpl $0x3, %ecx
jle 0x5e8b
movslq %ebx, %rbp
addq %r13, %rbp
movzwl 0x2(%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
leal 0x4(%r14), %r15d
cmpl %r15d, %ecx
jb 0x5e8b
movzwl (%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
leal -0x20(%rdx), %ecx
cmpl $0x4, %ecx
ja 0x596f
leaq 0x6ea9(%rip), %rsi      # 0xc7e4
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
leaq 0xb90d(%rip), %rcx      # 0x11258
movl (%rcx), %ecx
cmpw $0x3, %ax
jbe 0x5e67
cmpl $0x2, %ecx
jge 0x5cf8
movzwl 0x6(%rbp), %eax
movw %ax, 0x38(%r12)
jmp 0x5c49
cmpl $0x8, %edx
je 0x5bab
cmpl $0x9, %edx
je 0x5b16
cmpl $0x7, %edx
je 0x5f22
leaq 0xb8c7(%rip), %rax      # 0x11258
cmpl $0x3, (%rax)
jl 0x5c49
pushq $0x2
popq %rdi
leaq 0x72c2(%rip), %rsi      # 0xcc66
movl %r14d, %ecx
xorl %eax, %eax
callq 0x23c0
jmp 0x5c44
leaq 0xb89e(%rip), %rax      # 0x11258
cmpl $0x2, (%rax)
jge 0x5cb2
addq $0x4, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl %r14d, %edx
callq 0x5f3a
testq %rax, %rax
je 0x5c44
movq %rax, %r14
movq 0x58(%rsp), %rcx
cmpl %ecx, 0x1c(%rsp)
jge 0x5c5c
movq 0x10(%rsp), %rdx
leaq 0x20(%rsp), %rdi
jmp 0x5c9a
cmpw $0x5, %ax
jbe 0x5cc8
movzbl 0x9(%rbp), %r13d
leal 0x7(%r13), %eax
shrl $0x3, %eax
addl $0x6, %eax
cmpl %r14d, %eax
ja 0x5d13
movl 0x4(%rbp), %r14d
movzbl 0x8(%rbp), %r12d
addq $0xa, %rbp
movq %rbp, %rsi
movl %r13d, %edx
callq 0x61e3
leaq 0xb818(%rip), %rbp      # 0x11258
cmpl $0x2, (%rbp)
jge 0x5d68
bswapl %r14d
andl $0xf, %r12d
leaq 0x20(%rsp), %rdi
movl %r13d, %esi
callq 0x8412
cmpl $0x2, (%rbp)
jge 0x5d7e
movq 0x40(%rsp), %rax
movq 0x50(%rax), %rdi
leaq 0x20(%rsp), %rsi
movl %r13d, %edx
movq 0x48(%rsp), %rcx
movl %r14d, %r8d
movl %r12d, %r9d
movq %rax, %r12
callq 0x86c7
testq %rax, %rax
movq 0x30(%rsp), %r13
je 0x5c44
movq %rax, 0x50(%r12)
jmp 0x5c44
cmpw $0x13, %ax
jbe 0x5ce0
movl 0x4(%rbp), %r14d
movups 0x8(%rbp), %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0xb796(%rip), %rbp      # 0x11258
cmpl $0x2, (%rbp)
jge 0x5d34
bswapl %r14d
movq %rdi, %r13
callq 0x83dc
cmpl $0x2, (%rbp)
jge 0x5d4f
movq 0x58(%r12), %rdi
movq %r13, %rsi
movl $0x80, %edx
movq 0x48(%rsp), %rcx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0x86c7
testq %rax, %rax
movq 0x30(%rsp), %r13
je 0x5c44
movq %rax, 0x58(%r12)
jmp 0x5c44
cmpw $0x7, %ax
jbe 0x5d9a
movl 0x4(%rbp), %r14d
movl 0x8(%rbp), %r13d
bswapl %r14d
movl %r13d, %ebp
bswapl %ebp
leaq 0xb721(%rip), %rax      # 0x11258
cmpl $0x2, (%rax)
jge 0x5dd0
leaq 0xb761(%rip), %rax      # 0x112a8
movl (%rax), %r12d
cmpl $0x1, %r13d
movl $0x0, %r13d
sbbl %r13d, %r13d
orl %ebp, %r13d
testl %r12d, %r12d
movl $0x0, %eax
cmovlel %eax, %r12d
shlq $0x6, %r12
xorl %ebp, %ebp
leaq 0xc31d(%rip), %rcx      # 0x11e90
cmpq %rbp, %r12
je 0x5c3a
leaq (%rcx,%rbp), %rdi
addq $0x8, %rdi
movq 0x48(%rsp), %rsi
callq 0x5827
leaq 0xc2fb(%rip), %rcx      # 0x11e90
testl %eax, %eax
je 0x5ba5
cmpl %r14d, 0xc(%rcx,%rbp)
jne 0x5ba5
movl %r13d, 0x38(%rcx,%rbp)
addq $0x40, %rbp
jmp 0x5b73
cmpw $0xb, %ax
movl 0xc(%rsp), %ecx
jbe 0x5daf
movq 0x60(%rsp), %rax
cmpl %eax, %ecx
jge 0x5bcc
movl %eax, %r13d
movq 0x38(%rsp), %r14
jmp 0x5bf5
leal 0x2(,%rax,2), %r13d
movslq %r13d, %rax
imulq $0xc, %rax, %rsi
movq 0x38(%rsp), %rdi
callq 0x2290
movl 0xc(%rsp), %ecx
movq %rax, %r14
testq %rax, %rax
je 0x5e1d
movslq %ecx, %rax
imulq $0xc, %rax, %r12
movl 0x4(%rbp), %eax
movl %eax, (%r14,%r12)
movl 0x8(%rbp), %eax
bswapl %eax
movl %eax, 0x4(%r14,%r12)
movl 0xc(%rbp), %eax
bswapl %eax
movl %eax, 0x8(%r14,%r12)
leaq 0xb63a(%rip), %rax      # 0x11258
cmpl $0x2, (%rax)
jge 0x5deb
incl %ecx
movl %ecx, 0xc(%rsp)
movl %r13d, %eax
movq %rax, 0x60(%rsp)
movq %r14, 0x38(%rsp)
movq 0x40(%rsp), %r12
movq 0x30(%rsp), %r13
leaq 0x20(%rsp), %rdi
addl %ebx, %r15d
movl %r15d, %ebx
negl %ebx
andl $0x3, %ebx
addl %r15d, %ebx
jmp 0x58ed
movq %r13, %rbp
leal (%rcx,%rcx), %eax
cltq
leaq 0x10(,%rax,8), %rsi
movq 0x10(%rsp), %rdi
movq %rcx, %r13
callq 0x2290
testq %rax, %rax
je 0x5e3e
leal 0x2(,%r13,2), %r13d
movq %r13, 0x58(%rsp)
movq %rax, %rdx
leaq 0x20(%rsp), %rdi
movq %rbp, %r13
movl 0x1c(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x1c(%rsp)
movq %rdx, 0x10(%rsp)
movq %r14, (%rdx,%rax,8)
jmp 0x5c49
pushq $0x2
popq %rdi
leaq 0x6e75(%rip), %rsi      # 0xcb31
xorl %eax, %eax
callq 0x23c0
jmp 0x59c3
movq 0xb329(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6e72(%rip), %rdi      # 0xcb4b
pushq $0x1b
jmp 0x5dc2
movq 0xb311(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6e9c(%rip), %rdi      # 0xcb8d
pushq $0x18
jmp 0x5dc2
pushq $0x2
popq %rdi
leaq 0x6e21(%rip), %rsi      # 0xcb23
xorl %eax, %eax
callq 0x23c0
leaq 0x20(%rsp), %rdi
jmp 0x5960
movq 0xb2de(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6e27(%rip), %rdi      # 0xcb4b
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
jmp 0x5c3f
pushq $0x2
popq %rdi
leaq 0x6e68(%rip), %rsi      # 0xcba6
xorl %eax, %eax
callq 0x23c0
leaq 0x20(%rsp), %rdi
jmp 0x5acc
pushq $0x2
popq %rdi
leaq 0x6f15(%rip), %rsi      # 0xcc6e
movl %r14d, %edx
xorl %eax, %eax
callq 0x23c0
jmp 0x5ae1
pushq $0x2
popq %rdi
leaq 0x6df5(%rip), %rsi      # 0xcb67
xorl %eax, %eax
callq 0x23c0
jmp 0x5a4a
pushq $0x2
popq %rdi
leaq 0x6df5(%rip), %rsi      # 0xcb7d
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x23c0
jmp 0x5a68
movq 0xb257(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6d20(%rip), %rdi      # 0xcacb
pushq $0x1f
jmp 0x5dc2
movq 0xb242(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6cc8(%rip), %rdi      # 0xca88
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
jmp 0x5c44
pushq $0x2
popq %rdi
leaq 0x6d11(%rip), %rsi      # 0xcaeb
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x23c0
jmp 0x5b40
addq %r14, %r12
movq %r12, %rdi
callq 0xa86d
movl 0x4(%r12), %ecx
movl 0x8(%r12), %r8d
pushq $0x2
popq %rdi
leaq 0x6c9e(%rip), %rsi      # 0xcaa8
movq %rax, %rdx
xorl %eax, %eax
callq 0x23c0
movl 0xc(%rsp), %ecx
jmp 0x5c27
movq 0xb1d4(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6c74(%rip), %rdi      # 0xcaa2
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
jmp 0x5c3a
movq 0xb1b3(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6c53(%rip), %rdi      # 0xcaa2
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
leaq 0x20(%rsp), %rdi
movq %rbp, %r13
jmp 0x5c49
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
cmpl $0x2, %ecx
movq 0x10(%rsp), %rbx
jl 0x5eb3
leaq 0x6c91(%rip), %rsi      # 0xcb10
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x23c0
jmp 0x5eb3
movq 0xb166(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6970(%rip), %rdi      # 0xc80c
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rbx
movq 0x40(%r12), %rdi
callq 0x2040
movq 0x38(%rsp), %rax
movq %rax, 0x40(%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x48(%r12)
cmpq $0x0, 0x60(%r12)
je 0x5f01
xorl %ebx, %ebx
movslq 0x68(%r12), %rax
movq 0x60(%r12), %rdi
cmpq %rax, %rbx
jge 0x5ef7
movq (%rdi,%rbx,8), %rdi
callq 0x3f13
incq %rbx
jmp 0x5eda
callq 0x2040
movq 0x10(%rsp), %rbx
movq %rbx, 0x60(%r12)
movl 0x1c(%rsp), %eax
movl %eax, 0x68(%r12)
movl 0x8(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb0cf(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6b36(%rip), %rdi      # 0xca69
pushq $0x1e
jmp 0x5e9e