// File: /workspace/github_c_makefile_star2_O1/jech[P]shncpd/receive.c
// Function: parse_external
struct external *
parse_external(struct node *node, const unsigned char *buf, int buflen)
{
    int i = 0;
    struct external *ext = calloc(1, sizeof(struct external));
    if(ext == NULL)
        return NULL;

    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 34: {
            unsigned char plen;
            struct in6_addr addr;
            struct prefix_list *pl;
            if(bodylen < 9) {
                fprintf(stderr, "Truncated DELEGATED-PREFIX.\n");
                break;
            }
            plen = *(tlv + 12);
            if(bodylen < 9 + (plen + 7) / 8) {
                fprintf(stderr, "Truncated DELEGATED-PREFIX.\n");
                break;
            }
            parse_pref(&addr, tlv + 13, plen);
            debugf("       DELEGATED-PREFIX ");
            debug_prefix_raw(&addr, plen);
            debugf("\n");
            /* XXX parse embedded TLVs. */
            pl = prefix_list_cons(ext->delegated, &addr, plen, node->id, 0, 0);
            if(pl != NULL)
                ext->delegated = pl;
            break;
        }
        case 37: {
            debugf("       DHCPV4-DATA\n");
            parse_dhcpv4(tlv + 4, bodylen, &ext->dns, &ext->ntp);
            data_change_time = now;
            break;
        }
        case 38: {
            debugf("       DHCPV6-DATA\n");
            parse_dhcpv6(tlv + 4, bodylen, &ext->dns, &ext->ntp);
            data_change_time = now;
            break;
        }
        default:
            if(debug_level >= 3)
                debugf("       %d: %d\n", type, bodylen);
            break;
        }
        i += 4 + bodylen;
        i += -i & 3;
    }

    return ext;

 fail:
    destroy_external(ext);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %rbx
movl $0x1, %edi
movl $0x18, %esi
callq 0x21b0
testq %rax, %rax
je 0x7184
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, (%rsp)
addq $0x10, %rax
movq %rax, 0x10(%rsp)
addq $0x8, %rbx
movq %rbx, 0x38(%rsp)
leaq 0xc2f4(%rip), %rsi      # 0x13258
xorl %ebx, %ebx
movq %r13, 0x8(%rsp)
movl %ebp, %ecx
subl %ebx, %ecx
jle 0x7175
cmpl $0x3, %ecx
jle 0x7109
movslq %ebx, %r15
addq %r13, %r15
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
leal 0x4(%r12), %r14d
cmpl %r14d, %ecx
jl 0x7110
movzwl (%r15), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl $0x26, %edx
je 0x70af
cmpl $0x25, %edx
je 0x708b
cmpl $0x22, %edx
jne 0x70ea
cmpw $0x8, %ax
jbe 0x7131
movzbl 0xc(%r15), %r13d
leal 0x7(%r13), %eax
shrl $0x3, %eax
addl $0x9, %eax
cmpl %r12d, %eax
ja 0x7150
addq $0xd, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movl %r13d, %r12d
shrl $0x3, %r12d
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2210
movl %r13d, %eax
andl $0x7, %eax
je 0x7026
movb $0x8, %cl
subb %al, %cl
movl $0xff, %eax
shll %cl, %eax
andb (%r15,%r12), %al
movb %al, 0x20(%rsp,%r12)
movaps 0x20(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0xc221(%rip), %r15      # 0x13258
cmpl $0x2, (%r15)
leaq 0x40(%rsp), %rdi
jge 0x715c
movq %rdi, %r12
movl %r13d, %esi
callq 0x959c
cmpl $0x2, (%r15)
jge 0x716b
movq (%rsp), %rax
movq (%rax), %rdi
movq %r12, %rsi
movl %r13d, %edx
movq 0x38(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x9871
testq %rax, %rax
movq 0x8(%rsp), %r13
je 0x70e1
movq (%rsp), %rcx
movq %rax, (%rcx)
jmp 0x70e1
cmpl $0x2, (%rsi)
jge 0x7120
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x7195
jmp 0x70cd
cmpl $0x2, (%rsi)
jge 0x712a
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x73eb
leaq 0xc19c(%rip), %rax      # 0x13270
movups (%rax), %xmm0
leaq 0xc15a(%rip), %rax      # 0x13238
movups %xmm0, (%rax)
leaq 0xc170(%rip), %rsi      # 0x13258
jmp 0x70ef
cmpl $0x3, (%rsi)
jge 0x7138
addl %ebx, %r14d
movl %r14d, %ebx
negl %ebx
andl $0x3, %ebx
addl %r14d, %ebx
movb $0x1, %al
testb %al, %al
jne 0x6f6b
jmp 0x717b
callq 0x2cb0
jmp 0x7115
callq 0x2c8e
leaq 0xc13c(%rip), %rsi      # 0x13258
xorl %eax, %eax
jmp 0x70ff
callq 0x2c05
jmp 0x7094
callq 0x2bee
jmp 0x70b4
callq 0x2c6c
jmp 0x70e1
movl $0x2, %edi
leaq 0x6b68(%rip), %rsi      # 0xdcac
movl %r12d, %ecx
xorl %eax, %eax
callq 0x319e
jmp 0x70e1
callq 0x2c4a
movq 0x8(%rsp), %r13
jmp 0x70e1
callq 0x2c1c
leaq 0x40(%rsp), %rdi
jmp 0x7046
callq 0x2c33
jmp 0x705b
movq (%rsp), %rax
jmp 0x7186
movq (%rsp), %rdi
callq 0x4d42
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq