// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %r9
movl 0x18(%rdi), %eax
movl %eax, 0x4c(%rsp)
leaq 0xcb2a(%rip), %rax      # 0x132a8
movslq (%rax), %rax
testq %rax, %rax
jle 0x67ad
shlq $0x6, %rax
xorl %ecx, %ecx
leaq 0xd6fd(%rip), %rdx      # 0x13e90
movl 0x8(%rdx,%rcx), %esi
cmpl 0x8(%rbx), %esi
jne 0x67a4
movl $0x0, 0x38(%rdx,%rcx)
addq $0x40, %rcx
cmpq %rcx, %rax
jne 0x6793
leaq 0x8(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0xca9b(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
movq $0x0, 0x50(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x30(%rsp)
xorl %r8d, %r8d
xorl %r12d, %r12d
movq %r9, (%rsp)
movl 0x4c(%rsp), %ecx
subl %r12d, %ecx
jle 0x6e99
cmpl $0x3, %ecx
jle 0x6c1e
movslq %r12d, %r13
addq %r9, %r13
movzwl 0x2(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
leal 0x4(%r14), %r15d
cmpl %r15d, %ecx
jl 0x6c2b
movzwl (%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl $0x1f, %edx
jle 0x6890
leal -0x20(%rdx), %ecx
cmpl $0x4, %ecx
ja 0x6b3a
leaq 0x6f9a(%rip), %rsi      # 0xd7e4
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl (%rdi), %ecx
cmpw $0x3, %ax
ja 0x6b76
movl $0x7, %r14d
cmpl $0x2, %ecx
jl 0x6cff
movq %r8, %r15
movq %r9, %r13
callq 0x2b0b
movq %r13, %r9
leaq 0x10(%rsp), %r10
leaq 0xc9d0(%rip), %rdi      # 0x13258
movq %r15, %r8
jmp 0x6cff
cmpl $0x8, %edx
je 0x6b14
cmpl $0x9, %edx
jne 0x6b31
movq %r8, 0x8(%rsp)
cmpw $0x7, %ax
jbe 0x6d41
movq %rbp, 0x28(%rsp)
movl 0x4(%r13), %ebp
movl 0x8(%r13), %r13d
bswapl %ebp
movl %r13d, %r14d
bswapl %r14d
cmpl $0x2, (%rdi)
jge 0x6dae
leaq 0xc9d2(%rip), %rax      # 0x132a8
movslq (%rax), %rax
testq %rax, %rax
jle 0x6c6f
cmpl $0x1, %r13d
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %r14d, %ecx
shlq $0x6, %rax
xorl %edx, %edx
movq 0x8(%rsp), %r8
leaq 0xd58e(%rip), %r9       # 0x13e90
movl 0x8(%r9,%rdx), %esi
cmpl 0x8(%rbx), %esi
jne 0x6918
cmpl %ebp, 0xc(%r9,%rdx)
jne 0x6918
movl %ecx, 0x38(%r9,%rdx)
addq $0x40, %rdx
cmpq %rdx, %rax
jne 0x6902
movq (%rsp), %r9
jmp 0x6c78
movq %rbp, 0x28(%rsp)
movq %r8, 0x8(%rsp)
cmpl $0x2, (%rdi)
jge 0x6d1d
addq $0x4, %r13
movq %rbx, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x6f10
testq %rax, %rax
je 0x6c53
movq %rax, %r14
movq 0x50(%rsp), %rbp
cmpl %ebp, 0x34(%rsp)
jge 0x6c7f
movq 0x8(%rsp), %r8
leaq 0xc8e2(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
movq 0x28(%rsp), %rbp
movq (%rsp), %r9
jmp 0x6cd6
movq %r8, 0x8(%rsp)
cmpw $0x13, %ax
jbe 0x6d27
movq %rbp, 0x28(%rsp)
movl 0x4(%r13), %ebp
movups 0x8(%r13), %xmm0
movaps %xmm0, 0x10(%rsp)
cmpl $0x2, (%rdi)
movq %rdi, %r13
jge 0x6d7b
bswapl %ebp
movq %r10, %rdi
movq %r10, %r14
callq 0x9562
cmpl $0x2, (%r13)
jge 0x6d8a
movq 0x58(%rbx), %rdi
movq %r14, %rsi
movl $0x80, %edx
movq 0x58(%rsp), %rcx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x9871
testq %rax, %rax
movq (%rsp), %r9
movq 0x28(%rsp), %rbp
je 0x69fd
movq %rax, 0x58(%rbx)
movq 0x8(%rsp), %r8
leaq 0xc84f(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
jmp 0x6cec
cmpw $0x5, %ax
movq %r8, 0x8(%rsp)
jbe 0x6d37
movzbl 0x9(%r13), %ecx
leal 0x7(%rcx), %eax
shrl $0x3, %eax
addl $0x6, %eax
cmpl %r14d, %eax
ja 0x6da4
movq %rbp, 0x28(%rsp)
movl 0x4(%r13), %r14d
movzbl 0x8(%r13), %eax
movl %eax, 0x48(%rsp)
addq $0xa, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movl %ecx, %ebp
shrl $0x3, %ebp
movq %r10, %rdi
movq %r13, %rsi
movq %rcx, 0x40(%rsp)
movq %rbp, %rdx
callq 0x2210
movq 0x40(%rsp), %rsi
movl %esi, %eax
andl $0x7, %eax
je 0x6a8f
movb $0x8, %cl
subb %al, %cl
movl $0xff, %eax
shll %cl, %eax
andb (%r13,%rbp), %al
movb %al, 0x10(%rsp,%rbp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0xc7b8(%rip), %r13      # 0x13258
cmpl $0x2, (%r13)
leaq 0x60(%rsp), %rbp
jge 0x6dd7
bswapl %r14d
movl 0x48(%rsp), %r13d
andl $0xf, %r13d
movq %rbp, %rdi
callq 0x959c
leaq 0xc78d(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x6deb
movq 0x50(%rbx), %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %rdx
movq 0x58(%rsp), %rcx
movl %r14d, %r8d
movl %r13d, %r9d
callq 0x9871
testq %rax, %rax
movq 0x28(%rsp), %rbp
je 0x6afe
movq %rax, 0x50(%rbx)
movq 0x8(%rsp), %r8
leaq 0xc74e(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
jmp 0x6c69
cmpw $0xb, %ax
jbe 0x6d5f
movl 0x30(%rsp), %r14d
cmpl %ebp, %r14d
jge 0x6b8d
movq (%rsp), %r9
jmp 0x6be3
cmpl $0x7, %edx
je 0x6d0d
cmpl $0x3, (%rdi)
jl 0x6cec
movl $0x2, %edi
leaq 0x715f(%rip), %rsi      # 0xdcae
movl %r14d, %ecx
xorl %eax, %eax
movq %r8, %r14
movq %r9, %r13
callq 0x319e
movq %r13, %r9
leaq 0x10(%rsp), %r10
leaq 0xc6ea(%rip), %rdi      # 0x13258
movq %r14, %r8
jmp 0x6cec
cmpl $0x2, %ecx
jge 0x6e53
movzwl 0x6(%r13), %eax
movw %ax, 0x38(%rbx)
jmp 0x6cec
leal (,%rbp,2), %eax
cltq
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
addq $0x18, %rsi
movq %r8, %rdi
movq %r8, 0x8(%rsp)
callq 0x2280
movq %rax, %r14
testq %rax, %rax
je 0x6e73
leal 0x2(,%rbp,2), %ebp
movq %r14, %r8
leaq 0xc68c(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
movq (%rsp), %r9
testq %r14, %r14
movl 0x30(%rsp), %r14d
je 0x6cec
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
movl 0x4(%r13), %ecx
movl %ecx, (%r8,%rax,4)
movl 0x8(%r13), %ecx
bswapl %ecx
movl %ecx, 0x4(%r8,%rax,4)
movl 0xc(%r13), %ecx
bswapl %ecx
movl %ecx, 0x8(%r8,%rax,4)
cmpl $0x2, (%rdi)
jge 0x6e09
incl %r14d
movl %r14d, 0x30(%rsp)
jmp 0x6cec
movq %r8, %r14
movq %r9, %r15
callq 0x2bcc
jmp 0x6c36
movq %r8, %r14
movq %r9, %r15
callq 0x2baa
movq %r15, %r9
leaq 0x10(%rsp), %r10
leaq 0xc613(%rip), %rdi      # 0x13258
movq %r14, %r8
movl $0x7, %r14d
jmp 0x6cff
movq 0x8(%rsp), %r8
leaq 0xc5f9(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
movq 0x28(%rsp), %rbp
movq (%rsp), %r9
jmp 0x6cec
movq (%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x28(%rsp), %rbp
jmp 0x6cec
leal (,%rbp,2), %eax
cltq
leaq 0x10(,%rax,8), %rsi
movq 0x38(%rsp), %rdi
callq 0x2280
movq %rax, %r13
testq %rax, %rax
je 0x6e82
leal 0x2(,%rbp,2), %ebp
movq %rbp, 0x50(%rsp)
movq %r13, 0x38(%rsp)
movq 0x8(%rsp), %r8
leaq 0xc595(%rip), %rdi      # 0x13258
leaq 0x10(%rsp), %r10
movq 0x28(%rsp), %rbp
movq (%rsp), %r9
testq %r13, %r13
je 0x6cec
movl 0x34(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x34(%rsp)
movq 0x38(%rsp), %rcx
movq %r14, (%rcx,%rax,8)
addl %r12d, %r15d
movl %r15d, %r12d
negl %r12d
andl $0x3, %r12d
addl %r15d, %r12d
xorl %r14d, %r14d
testl %r14d, %r14d
je 0x67f0
jmp 0x6e8c
movq %r8, %r14
movq %r9, %r15
callq 0x2b88
jmp 0x6c36
callq 0x2abb
jmp 0x693d
movq %r9, %r14
callq 0x2a3e
movq %r14, %r9
jmp 0x69fd
callq 0x2a99
jmp 0x6afe
movq %r9, %r14
callq 0x2b22
movq %r14, %r9
leaq 0x10(%rsp), %r10
leaq 0xc500(%rip), %rdi      # 0x13258
movq 0x8(%rsp), %r8
jmp 0x6cec
movq %r8, %r14
callq 0x2b66
leaq 0x10(%rsp), %r10
leaq 0xc4e5(%rip), %rdi      # 0x13258
movq %r14, %r8
jmp 0x6c69
callq 0x2a27
leaq 0x10(%rsp), %r10
jmp 0x69b7
movl $0x2, %edi
leaq 0x6f20(%rip), %rsi      # 0xdcb6
movl %ebp, %edx
xorl %eax, %eax
callq 0x319e
jmp 0x69cf
callq 0x2a77
jmp 0x6afe
movl $0x2, %edi
leaq 0x6d79(%rip), %rsi      # 0xdb33
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x319e
leaq 0x10(%rsp), %r10
leaq 0xc486(%rip), %rdi      # 0x13258
jmp 0x68cf
callq 0x2a60
movq 0x40(%rsp), %rsi
leaq 0x60(%rsp), %rbp
jmp 0x6ab0
movl $0x2, %edi
leaq 0x6dce(%rip), %rsi      # 0xdbc5
movl %r14d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x319e
jmp 0x6ad4
leaq (%r8,%rax,4), %r14
movq %r14, %rdi
movq %r8, %r13
callq 0xbc25
movl 0x4(%r14), %ecx
movl 0x8(%r14), %r8d
movl 0x30(%rsp), %r14d
movl $0x2, %edi
leaq 0x6cbf(%rip), %rsi      # 0xdaf0
movq %rax, %rdx
xorl %eax, %eax
callq 0x319e
movq (%rsp), %r9
leaq 0x10(%rsp), %r10
leaq 0xc40d(%rip), %rdi      # 0x13258
movq %r13, %r8
jmp 0x6c11
movq %r8, %r14
callq 0x2af4
movq (%rsp), %r9
leaq 0x10(%rsp), %r10
leaq 0xc3ed(%rip), %rdi      # 0x13258
movq %r14, %r8
jmp 0x6b7f
callq 0x2b44
movq 0x8(%rsp), %r8
jmp 0x6bc5
callq 0x2ad2
jmp 0x6cb7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x7, %r14d
je 0x6e9e
jmp 0x6eff
movl $0x1, %ebp
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x6eb2
movq %r8, %r14
callq 0x2040
movq %r14, %r8
movq %r8, 0x40(%rbx)
movl 0x30(%rsp), %eax
movl %eax, 0x48(%rbx)
cmpq $0x0, 0x60(%rbx)
movq 0x38(%rsp), %r15
je 0x6ef4
cmpl $0x0, 0x68(%rbx)
jle 0x6eeb
xorl %r14d, %r14d
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x4d42
incq %r14
movslq 0x68(%rbx), %rax
cmpq %rax, %r14
jl 0x6ed2
movq 0x60(%rbx), %rdi
callq 0x2040
movq %r15, 0x60(%rbx)
movl 0x34(%rsp), %eax
movl %eax, 0x68(%rbx)
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq