// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x21b0
testq %rax, %rax
je 0x6e9e
testl %ebp, %ebp
jle 0x6ea0
leaq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq %rax, (%rsp)
addq $0x10, %rax
movq %rax, 0x20(%rsp)
addq $0x8, 0x18(%rsp)
xorl %ebx, %ebx
movq %r13, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movl %ebp, %ecx
subl %ebx, %ecx
cmpl $0x4, %ecx
jl 0x6e95
movslq %ebx, %r15
addq %r13, %r15
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
leal 0x4(%r12), %r14d
cmpl %r14d, %ecx
jb 0x6e95
movzwl (%r15), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl $0x26, %edx
je 0x6ddb
cmpl $0x25, %edx
je 0x6db4
cmpl $0x22, %edx
jne 0x6e16
cmpw $0x8, %ax
jbe 0x6e4b
movzbl 0xc(%r15), %r13d
leal 0x7(%r13), %eax
shrl $0x3, %eax
addl $0x9, %eax
cmpl %r12d, %eax
ja 0x6e6a
addq $0xd, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movl %r13d, %r12d
shrl $0x3, %r12d
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2210
movl %r13d, %eax
andl $0x7, %eax
je 0x6d4d
movb $0x8, %cl
subb %al, %cl
movl $0xff, %eax
shll %cl, %eax
andb (%r15,%r12), %al
movb %al, 0x30(%rsp,%r12)
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0xc4fa(%rip), %r12      # 0x13258
cmpl $0x2, (%r12)
movq (%rsp), %r15
leaq 0x40(%rsp), %rbp
jge 0x6e76
movq %rbp, %rdi
movl %r13d, %esi
callq 0x9097
cmpl $0x2, (%r12)
jge 0x6e85
movq (%r15), %rdi
movq %rbp, %rsi
movl %r13d, %edx
movq 0x18(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x938c
testq %rax, %rax
movq 0x10(%rsp), %r13
movl 0xc(%rsp), %ebp
je 0x6e22
movq %rax, (%r15)
jmp 0x6e22
leaq 0xc49d(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x6e3a
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x6eaf
jmp 0x6e00
leaq 0xc476(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x6e44
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x7093
leaq 0xc469(%rip), %rax      # 0x13270
movups (%rax), %xmm0
leaq 0xc427(%rip), %rax      # 0x13238
movups %xmm0, (%rax)
jmp 0x6e22
leaq 0xc43b(%rip), %rax      # 0x13258
cmpl $0x3, (%rax)
jge 0x6e52
addl %ebx, %r14d
movl %r14d, %ebx
negl %ebx
andl $0x3, %ebx
addl %r14d, %ebx
cmpl %ebp, %ebx
jl 0x6c98
jmp 0x6e8f
callq 0x2be3
jmp 0x6dc0
callq 0x2bcc
jmp 0x6de7
callq 0x2c4a
jmp 0x6e22
movl $0x2, %edi
leaq 0x6e2e(%rip), %rsi      # 0xdc8c
movl %r12d, %ecx
xorl %eax, %eax
callq 0x30a8
jmp 0x6e22
callq 0x2c28
movq 0x10(%rsp), %r13
jmp 0x6e22
callq 0x2bfa
leaq 0x40(%rsp), %rbp
jmp 0x6d72
callq 0x2c11
jmp 0x6d88
movq (%rsp), %rax
jmp 0x6ea0
movq (%rsp), %rdi
callq 0x2c6c
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq