// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x21c0
testq %rax, %rax
je 0x61d2
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x8(%rsp)
addq $0x10, %rax
movq %rax, 0x10(%rsp)
addq $0x8, %r14
movq %r14, 0x20(%rsp)
leaq 0xb2cd(%rip), %rsi      # 0x11258
xorl %r13d, %r13d
movl %ebp, 0x4(%rsp)
movl %ebp, %ecx
subl %r13d, %ecx
jle 0x61a5
cmpl $0x4, %ecx
jl 0x61ac
movslq %r13d, %r15
addq %rbx, %r15
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
leal 0x4(%r12), %r14d
cmpl %r14d, %ecx
jb 0x61ac
movzwl (%r15), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl $0x26, %edx
je 0x609f
cmpl $0x25, %edx
je 0x607f
cmpl $0x22, %edx
jne 0x60da
cmpw $0x8, %ax
leaq 0x28(%rsp), %rdi
jbe 0x611d
movq %rbx, %rbp
movzbl 0xc(%r15), %ebx
leal 0x7(%rbx), %eax
shrl $0x3, %eax
addl $0x9, %eax
cmpl %r12d, %eax
ja 0x6151
addq $0xd, %r15
movq %r15, %rsi
movl %ebx, %edx
movq %rdi, %r12
callq 0x61e3
leaq 0xb22a(%rip), %r15      # 0x11258
cmpl $0x2, (%r15)
jge 0x6179
movq %r12, %rdi
movl %ebx, %esi
callq 0x8412
cmpl $0x2, (%r15)
jge 0x618f
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r12, %rsi
movl %ebx, %edx
movq 0x20(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x86c7
testq %rax, %rax
movq %rbp, %rbx
movl 0x4(%rsp), %ebp
je 0x60d1
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x60d1
cmpl $0x2, (%rsi)
jge 0x60f4
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x6238
jmp 0x60bd
cmpl $0x2, (%rsi)
jge 0x610a
addq $0x4, %r15
movq %r15, %rdi
movl %r12d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x6424
leaq 0xb1ac(%rip), %rax      # 0x11270
movups (%rax), %xmm0
leaq 0xb16a(%rip), %rax      # 0x11238
movups %xmm0, (%rax)
leaq 0xb180(%rip), %rsi      # 0x11258
jmp 0x60df
cmpl $0x3, (%rsi)
jge 0x613b
addl %r13d, %r14d
movl %r14d, %r13d
negl %r13d
andl $0x3, %r13d
addl %r14d, %r13d
jmp 0x5f92
pushq $0x2
popq %rdi
leaq 0x6af1(%rip), %rsi      # 0xcbef
xorl %eax, %eax
callq 0x23c0
jmp 0x6084
pushq $0x2
popq %rdi
leaq 0x6aef(%rip), %rsi      # 0xcc03
xorl %eax, %eax
callq 0x23c0
jmp 0x60a4
movq 0xaed4(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6a8b(%rip), %rdi      # 0xcbb9
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
jmp 0x60d1
pushq $0x2
popq %rdi
leaq 0x6b1f(%rip), %rsi      # 0xcc64
movl %r12d, %ecx
xorl %eax, %eax
callq 0x23c0
jmp 0x60d1
movq 0xaea0(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6a57(%rip), %rdi      # 0xcbb9
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
movq %rbp, %rbx
movl 0x4(%rsp), %ebp
jmp 0x60d1
pushq $0x2
popq %rdi
leaq 0x6a53(%rip), %rsi      # 0xcbd6
xorl %eax, %eax
callq 0x23c0
jmp 0x6038
pushq $0x2
popq %rdi
leaq 0x6750(%rip), %rsi      # 0xc8e9
xorl %eax, %eax
callq 0x23c0
jmp 0x604c
movq 0x8(%rsp), %rax
jmp 0x61d4
movq 0xae45(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x664f(%rip), %rdi      # 0xc80c
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
movq 0x8(%rsp), %rdi
callq 0x3f13
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq