// File: /workspace/github_c_makefile_star2_O3/jech[P]shncpd/send.c
// Function: buffer_tlv
int
buffer_tlv(int type, const unsigned char *data, int datalen,
           const struct sockaddr_in6 *sin6, struct interface *interface)
{
    if(interface && sin6) {
        errno = EINVAL;
        return -1;
    }

    if(sendbuf == NULL)
        sendbuf = allocate_buffer(SENDBUF_SIZE);
    if(sendbuf == NULL)
        return -1;

    if(buffered &&
       ((interface && interface != buffered_interface) ||
        (!interface && (buffered_interface ||
                        memcmp(sin6, &buffered_sin6, sizeof(*sin6)) != 0)) ||
        buffered + datalen > 1400))
        flushbuf();

    if(buffered + datalen + 4 > SENDBUF_SIZE) {
        errno = EMSGSIZE;
        return -1;
    }

    if(!buffered) {
        /* NODE-ENDPOINT */
        DO_HTONS(sendbuf + 0, 3);
        DO_HTONS(sendbuf + 2, 8);
        memcpy(sendbuf + 4, myid, 4);
        DO_HTONL(sendbuf + 8,
                 interface ? interface->ifindex : sin6->sin6_scope_id);
        buffered = 12;
    }

    if(interface)
        buffered_interface = interface;
    else
        memcpy(&buffered_sin6, sin6, sizeof(*sin6));

    DO_HTONS(sendbuf + buffered, type); buffered += 2;
    DO_HTONS(sendbuf + buffered, datalen); buffered += 2;
    memcpy(sendbuf + buffered, data, datalen); buffered += datalen;

    if(debug_level >= 3)
        debugf("Buffering %s %d (%d)\n",
               interface ? "multicast" : "unicast", type, datalen);

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %r12
testq %r8, %r8
sete %al
testq %rcx, %rcx
sete %cl
orb %al, %cl
jne 0x5131
callq 0x2060
movl $0x16, (%rax)
jmp 0x520a
movq %r8, %r14
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %ebp
cmpq $0x0, 0x1233d(%rip)     # 0x17480
jne 0x515f
movl $0xfa0, %edi            # imm = 0xFA0
callq 0xb756
movq %rax, 0x1232a(%rip)     # 0x17480
testq %rax, %rax
je 0x520a
movl 0x122eb(%rip), %eax     # 0x17450
testl %eax, %eax
je 0x5194
testq %r14, %r14
setne %dl
movq 0x122e2(%rip), %rcx     # 0x17458
cmpq %r14, %rcx
setne %sil
testb %sil, %dl
jne 0x51e9
testq %r14, %r14
je 0x519e
leal (%rax,%rbx), %ecx
cmpl $0x579, %ecx            # imm = 0x579
jge 0x51e9
jmp 0x51f4
cmpl $0xf9d, %ebx            # imm = 0xF9D
jge 0x51ff
jmp 0x5219
testq %rcx, %rcx
jne 0x51e9
movdqu 0x122b5(%rip), %xmm0    # 0x17460
movdqu (%r12), %xmm1
pcmpeqb %xmm0, %xmm1
movdqu 0xc(%r12), %xmm0
movdqu 0x122a8(%rip), %xmm2    # 0x1746c
pcmpeqb %xmm0, %xmm2
pand %xmm1, %xmm2
pmovmskb %xmm2, %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
setne %cl
leal (%rax,%rbx), %edx
cmpl $0x579, %edx            # imm = 0x579
setge %dl
orb %cl, %dl
je 0x51f4
callq 0x5058
movl 0x1225c(%rip), %eax     # 0x17450
leal (%rax,%rbx), %ecx
cmpl $0xf9c, %ecx            # imm = 0xF9C
jle 0x5215
callq 0x2060
movl $0x5a, (%rax)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x52c9
testl %eax, %eax
jne 0x524e
leaq 0x8(%r14), %rax
leaq 0x18(%r12), %rcx
testq %r14, %r14
movq 0x12254(%rip), %rdx     # 0x17480
movl $0x8000300, (%rdx)      # imm = 0x8000300
leaq 0xe047(%rip), %rsi      # 0x13280
movl (%rsi), %esi
movl %esi, 0x4(%rdx)
cmovneq %rax, %rcx
movl (%rcx), %eax
bswapl %eax
movl %eax, 0x8(%rdx)
movl $0xc, %eax
testq %r14, %r14
je 0x525c
movq %r14, 0x121fe(%rip)     # 0x17458
jmp 0x5279
movdqu (%r12), %xmm0
movdqu 0xc(%r12), %xmm1
movdqu %xmm1, 0x121fb(%rip)    # 0x1746c
movdqu %xmm0, 0x121e7(%rip)    # 0x17460
movl %ebp, %ecx
rolw $0x8, %cx
movq 0x121fa(%rip), %rdx     # 0x17480
movslq %eax, %r12
leaq (%rdx,%r12), %rdi
addq $0x4, %rdi
movw %cx, -0x4(%rdi)
movl %ebx, %eax
rolw $0x8, %ax
movw %ax, -0x2(%rdi)
movslq %ebx, %rdx
movq %r15, %rsi
callq 0x2210
leal (%r12,%rbx), %eax
addl $0x4, %eax
movl %eax, 0x12199(%rip)     # 0x17450
leaq 0xdf9a(%rip), %rax      # 0x13258
movl $0x1, %r15d
cmpl $0x3, (%rax)
jge 0x52d5
movl %r15d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
leaq 0x83de(%rip), %rax      # 0xd6bd
leaq 0x83e1(%rip), %rdx      # 0xd6c7
cmovneq %rax, %rdx
leaq 0x83b6(%rip), %rsi      # 0xd6a7
movl $0x2, %edi
movl %ebp, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x30a8
jmp 0x52c9