// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %rdi, %r13
movq 0x10(%rdi), %rax
movq %rax, 0x80(%rsp)
movl 0x18(%rdi), %r8d
leaq 0xcdf0(%rip), %rax      # 0x132a8
movslq (%rax), %rax
testq %rax, %rax
jle 0x64e8
shlq $0x6, %rax
xorl %ecx, %ecx
leaq 0xd9c3(%rip), %rdx      # 0x13e90
movl 0x8(%rdx,%rcx), %esi
cmpl 0x8(%r13), %esi
jne 0x64df
movl $0x0, 0x38(%rdx,%rcx)
addq $0x40, %rcx
cmpq %rcx, %rax
jne 0x64cd
movl $0x1, %ebx
testl %r8d, %r8d
jle 0x6b6f
leaq 0x8(%r13), %r9
leaq 0xcd57(%rip), %r10      # 0x13258
leaq 0xd988(%rip), %r11      # 0x13e90
leaq 0x50(%rsp), %r12
xorl %ebx, %ebx
movq $0x0, 0x20(%rsp)
xorl %esi, %esi
xorl %edi, %edi
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x48(%rsp)
movl %r8d, 0x8(%rsp)
movq %r9, 0x10(%rsp)
movq %r13, 0x38(%rsp)
movl %r8d, %ecx
subl %ebx, %ecx
cmpl $0x3, %ecx
jle 0x6c14
movslq %ebx, %rbp
addq 0x80(%rsp), %rbp
movzwl 0x2(%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
leal 0x4(%r14), %r15d
cmpl %r15d, %ecx
jb 0x6c1d
movzwl (%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl $0x1f, %edx
jle 0x65cd
movq %rdi, 0x18(%rsp)
leal -0x20(%rdx), %ecx
cmpl $0x4, %ecx
ja 0x6859
leaq 0x7244(%rip), %rdi      # 0xd7e4
movslq (%rdi,%rcx,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movl (%r10), %ecx
cmpw $0x3, %ax
jbe 0x6bf3
cmpl $0x2, %ecx
jge 0x6a0e
movzwl 0x6(%rbp), %eax
movw %ax, 0x38(%r13)
jmp 0x6926
cmpl $0x8, %edx
je 0x6838
cmpl $0x9, %edx
movq %rdi, 0x18(%rsp)
jne 0x6850
cmpw $0x7, %ax
jbe 0x69d6
movl 0x4(%rbp), %r14d
movl 0x8(%rbp), %r13d
bswapl %r14d
movl %r13d, %ebp
bswapl %ebp
cmpl $0x2, (%r10)
jge 0x6a65
leaq 0xcc99(%rip), %rax      # 0x132a8
movslq (%rax), %rax
testq %rax, %rax
jle 0x6921
movl %esi, %edi
cmpl $0x1, %r13d
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %ebp, %ecx
shlq $0x6, %rax
xorl %edx, %edx
movq 0x38(%rsp), %r13
movl 0x8(%r11,%rdx), %esi
cmpl (%r9), %esi
jne 0x664b
cmpl %r14d, 0xc(%r11,%rdx)
jne 0x664b
movl %ecx, 0x38(%r11,%rdx)
addq $0x40, %rdx
cmpq %rdx, %rax
jne 0x6635
movl %edi, %esi
jmp 0x6926
movl %esi, 0xc(%rsp)
cmpw $0x13, %ax
jbe 0x69b8
movl 0x4(%rbp), %r14d
movups 0x8(%rbp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x2, (%r10)
movq %r10, %rbp
jge 0x6a36
bswapl %r14d
movq %r12, %rdi
callq 0x905d
cmpl $0x2, (%rbp)
jge 0x6a40
movq 0x58(%r13), %rdi
movq %r12, %rsi
movl $0x80, %edx
movq 0x10(%rsp), %rcx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0x938c
testq %rax, %rax
je 0x6817
movq %rax, 0x58(%r13)
jmp 0x6817
movl %esi, 0xc(%rsp)
cmpl $0x2, (%r10)
jge 0x69c2
addq $0x4, %rbp
movq %r13, %rdi
movq %rbp, %rsi
movl %r14d, %edx
callq 0x6c39
testq %rax, %rax
je 0x6817
movq %rax, %r14
movq 0x48(%rsp), %rbp
cmpl %ebp, 0x30(%rsp)
jge 0x6947
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %r9
leaq 0xcb42(%rip), %r10      # 0x13258
leaq 0xd773(%rip), %r11      # 0x13e90
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rdx
jmp 0x699b
cmpw $0x5, %ax
movl %esi, 0xc(%rsp)
jbe 0x69cc
movzbl 0x9(%rbp), %ecx
leal 0x7(%rcx), %eax
shrl $0x3, %eax
addl $0x6, %eax
cmpl %r14d, %eax
ja 0x6a5b
movl 0x4(%rbp), %eax
movl %eax, 0x44(%rsp)
movzbl 0x8(%rbp), %eax
movl %eax, 0x40(%rsp)
addq $0xa, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl %ecx, %r13d
shrl $0x3, %r13d
movq %r12, %rdi
movq %rbp, %rsi
movq %rcx, %r14
movq %r13, %rdx
callq 0x2210
movq %r14, %rsi
movl %esi, %eax
andl $0x7, %eax
je 0x67a2
movb $0x8, %cl
subb %al, %cl
movl $0xff, %eax
shll %cl, %eax
andb (%rbp,%r13), %al
movb %al, 0x50(%rsp,%r13)
movaps 0x50(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0xcaa5(%rip), %rbp      # 0x13258
cmpl $0x2, (%rbp)
movq 0x38(%rsp), %r13
leaq 0x60(%rsp), %rdi
jge 0x6afc
movq %rsi, 0x78(%rsp)
movl 0x44(%rsp), %ebp
bswapl %ebp
movl 0x40(%rsp), %r14d
andl $0xf, %r14d
callq 0x9097
leaq 0xca71(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x6b0e
movq 0x50(%r13), %rdi
leaq 0x60(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x938c
testq %rax, %rax
je 0x6817
movq %rax, 0x50(%r13)
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %r9
leaq 0xca2c(%rip), %r10      # 0x13258
leaq 0xd65d(%rip), %r11      # 0x13e90
jmp 0x6926
cmpw $0xb, %ax
jbe 0x69e2
cmpl %edi, %esi
jge 0x689a
movq 0x20(%rsp), %rdx
jmp 0x68ef
cmpl $0x7, %edx
je 0x6c30
cmpl $0x3, (%r10)
jl 0x6926
movl $0x2, %edi
movl %esi, %ebp
leaq 0x741d(%rip), %rsi      # 0xdc8e
movl %r14d, %ecx
xorl %eax, %eax
callq 0x30a8
leaq 0xd60e(%rip), %r11      # 0x13e90
leaq 0xc9cf(%rip), %r10      # 0x13258
movq 0x10(%rsp), %r9
movl 0x8(%rsp), %r8d
movl %ebp, %esi
jmp 0x6926
movl %esi, 0xc(%rsp)
leal (%rdi,%rdi), %eax
cltq
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
addq $0x18, %rsi
movq %rdi, %r14
movq 0x20(%rsp), %rdi
callq 0x2280
testq %rax, %rax
je 0x6b2b
leal 0x2(,%r14,2), %r14d
movq %rax, %rdx
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %r9
leaq 0xc973(%rip), %r10      # 0x13258
leaq 0xd5a4(%rip), %r11      # 0x13e90
movq %r14, %rdi
movslq %esi, %rax
leaq (%rax,%rax,2), %rax
movl 0x4(%rbp), %ecx
movl %ecx, (%rdx,%rax,4)
movl 0x8(%rbp), %ecx
bswapl %ecx
movl %ecx, 0x4(%rdx,%rax,4)
movl 0xc(%rbp), %ecx
bswapl %ecx
movq %rdx, 0x20(%rsp)
movl %ecx, 0x8(%rdx,%rax,4)
cmpl $0x2, (%r10)
jge 0x6aa2
incl %esi
jmp 0x692b
movq 0x38(%rsp), %r13
movq 0x18(%rsp), %rdi
addl %ebx, %r15d
movl %r15d, %ebx
negl %ebx
andl $0x3, %ebx
addl %r15d, %ebx
cmpl %r8d, %ebx
jl 0x6546
jmp 0x6b5e
leal (,%rbp,2), %eax
cltq
leaq 0x10(,%rax,8), %rsi
movq 0x28(%rsp), %rdi
callq 0x2280
testq %rax, %rax
je 0x6b54
leal 0x2(,%rbp,2), %ebp
movq %rbp, 0x48(%rsp)
movq %rax, %rdx
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %r9
leaq 0xc8c9(%rip), %r10      # 0x13258
leaq 0xd4fa(%rip), %r11      # 0x13e90
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rcx
movslq %ecx, %rax
incl %ecx
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %r14, (%rdx,%rax,8)
jmp 0x692b
callq 0x2a1c
jmp 0x6817
callq 0x2a99
jmp 0x66d4
callq 0x2a77
jmp 0x6817
movl %esi, %ebp
movq %rdi, %r14
callq 0x2b00
jmp 0x69ec
movl %esi, %ebp
movq %rdi, %r14
callq 0x2b44
movq %r14, %rdi
leaq 0xd49a(%rip), %r11      # 0x13e90
leaq 0xc85b(%rip), %r10      # 0x13258
movq 0x10(%rsp), %r9
movl 0x8(%rsp), %r8d
movl %ebp, %esi
jmp 0x692b
movl %esi, %r14d
callq 0x2ad2
leaq 0xd473(%rip), %r11      # 0x13e90
leaq 0xc834(%rip), %r10      # 0x13258
movq 0x10(%rsp), %r9
movl 0x8(%rsp), %r8d
movl %r14d, %esi
jmp 0x65bf
callq 0x2a05
jmp 0x6683
movl $0x2, %edi
leaq 0x724a(%rip), %rsi      # 0xdc96
movl %r14d, %edx
xorl %eax, %eax
callq 0x30a8
jmp 0x6698
callq 0x2a55
jmp 0x6817
movl $0x2, %edi
movl %esi, 0xc(%rsp)
leaq 0x709e(%rip), %rsi      # 0xdb13
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x30a8
leaq 0xd408(%rip), %r11      # 0x13e90
leaq 0xc7c9(%rip), %r10      # 0x13258
movq 0x10(%rsp), %r9
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %esi
jmp 0x6608
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %r14
movq %rdi, 0x18(%rsp)
movq %r14, %rdi
movl %esi, %ebp
callq 0xb657
movl 0x4(%r14), %ecx
movl 0x8(%r14), %r8d
movl $0x2, %edi
leaq 0x7002(%rip), %rsi      # 0xdad0
movq %rax, %rdx
xorl %eax, %eax
callq 0x30a8
movq 0x18(%rsp), %rdi
leaq 0xd3ac(%rip), %r11      # 0x13e90
leaq 0xc76d(%rip), %r10      # 0x13258
movq 0x10(%rsp), %r9
movl 0x8(%rsp), %r8d
movl %ebp, %esi
jmp 0x691d
callq 0x2a3e
movq %r14, %rsi
leaq 0x60(%rsp), %rdi
jmp 0x67c7
movl $0x2, %edi
leaq 0x708b(%rip), %rsi      # 0xdba5
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x30a8
jmp 0x67f0
callq 0x2b22
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %r9
leaq 0xc713(%rip), %r10      # 0x13258
leaq 0xd344(%rip), %r11      # 0x13e90
movq %r14, %rdi
jmp 0x692b
callq 0x2ab0
jmp 0x6817
movl $0x1, %ebx
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
jmp 0x6b80
movq $0x0, 0x30(%rsp)
xorl %r14d, %r14d
xorl %esi, %esi
xorl %r15d, %r15d
movq 0x40(%r13), %rdi
testq %rdi, %rdi
je 0x6b92
movl %esi, %ebp
callq 0x2040
movl %ebp, %esi
movq %r15, 0x40(%r13)
movl %esi, 0x48(%r13)
movq 0x60(%r13), %rdi
testq %rdi, %rdi
je 0x6bd2
cmpl $0x0, 0x68(%r13)
jle 0x6bcd
movl %ebx, %ebp
xorl %ebx, %ebx
movq 0x60(%r13), %rax
movq (%rax,%rbx,8), %rdi
callq 0x4b98
incq %rbx
movslq 0x68(%r13), %rax
cmpq %rax, %rbx
jl 0x6bae
movq 0x60(%r13), %rdi
movl %ebp, %ebx
callq 0x2040
movq %r14, 0x60(%r13)
movq 0x30(%rsp), %rax
movl %eax, 0x68(%r13)
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x2, %ecx
movq 0x28(%rsp), %r14
jl 0x6b68
movl %esi, %ebp
callq 0x2ae9
movl %ebp, %esi
jmp 0x6b68
movl %esi, %ebx
callq 0x2baa
jmp 0x6c24
movl %esi, %ebx
callq 0x2b88
movl %ebx, %esi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x6b63
movl %esi, %ebx
callq 0x2b66
jmp 0x6c24