// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
testq %r8, %r8
sete %al
testq %rcx, %rcx
sete %cl
orb %al, %cl
jne 0x5334
callq 0x2060
movl $0x16, (%rax)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x54df
movq %r8, %r14
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %ebp
cmpq $0x0, 0x1213a(%rip)     # 0x17480
jne 0x5359
movl $0xfa0, %edi            # imm = 0xFA0
callq 0xbd24
movq %rax, 0x12127(%rip)     # 0x17480
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq $0x0, 0x12119(%rip)     # 0x17480
je 0x54df
movl 0x120dd(%rip), %eax     # 0x17450
testl %eax, %eax
je 0x53ee
testq %r14, %r14
setne %dl
movq 0x120d4(%rip), %rcx     # 0x17458
cmpq %r14, %rcx
setne %sil
testb %sil, %dl
jne 0x53e9
testq %r14, %r14
je 0x53a0
addl %ebx, %eax
cmpl $0x579, %eax            # imm = 0x579
jge 0x53e9
jmp 0x53ee
testq %rcx, %rcx
jne 0x53e9
movdqu 0x120b3(%rip), %xmm0    # 0x17460
movdqu (%r12), %xmm1
pcmpeqb %xmm0, %xmm1
movdqu 0xc(%r12), %xmm0
movdqu 0x120a6(%rip), %xmm2    # 0x1746c
pcmpeqb %xmm0, %xmm2
pand %xmm1, %xmm2
pmovmskb %xmm2, %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
setne %cl
addl %ebx, %eax
cmpl $0x579, %eax            # imm = 0x579
setge %al
orb %cl, %al
je 0x53ee
callq 0x5250
movl 0x1205c(%rip), %eax     # 0x17450
leal (%rax,%rbx), %ecx
cmpl $0xf9d, %ecx            # imm = 0xF9D
jl 0x540f
callq 0x2060
movl $0x5a, (%rax)
jmp 0x54df
testl %eax, %eax
jne 0x544d
leaq 0x8(%r14), %rax
leaq 0x18(%r12), %rcx
testq %r14, %r14
movq 0x1205a(%rip), %rdx     # 0x17480
movl $0x8000300, (%rdx)      # imm = 0x8000300
leaq 0xde4d(%rip), %rsi      # 0x13280
movl (%rsi), %esi
movl %esi, 0x4(%rdx)
cmovneq %rax, %rcx
movl (%rcx), %eax
bswapl %eax
movl %eax, 0x8(%rdx)
movl $0xc, 0x12003(%rip)     # 0x17450
testq %r14, %r14
je 0x545b
movq %r14, 0x11fff(%rip)     # 0x17458
jmp 0x5478
movdqu (%r12), %xmm0
movdqu 0xc(%r12), %xmm1
movdqu %xmm1, 0x11ffc(%rip)    # 0x1746c
movdqu %xmm0, 0x11fe8(%rip)    # 0x17460
movl %ebp, %eax
rolw $0x8, %ax
movq 0x11ffb(%rip), %rcx     # 0x17480
movslq 0x11fc4(%rip), %r12     # 0x17450
leaq (%rcx,%r12), %rdi
addq $0x4, %rdi
movw %ax, -0x4(%rdi)
leaq 0x2(%r12), %rax
movl %eax, 0x11fad(%rip)     # 0x17450
movl %ebx, %eax
rolw $0x8, %ax
movw %ax, -0x2(%rdi)
addq $0x4, %r12
movl %r12d, 0x11f98(%rip)    # 0x17450
movslq %ebx, %rdx
movq %r15, %rsi
callq 0x2210
addl %ebx, %r12d
movl %r12d, 0x11f83(%rip)    # 0x17450
leaq 0xdd84(%rip), %rax      # 0x13258
movl $0x1, %r13d
cmpl $0x3, (%rax)
jge 0x54f1
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
leaq 0x81c2(%rip), %rax      # 0xd6bd
leaq 0x81c5(%rip), %rdx      # 0xd6c7
cmovneq %rax, %rdx
leaq 0x819a(%rip), %rsi      # 0xd6a7
movl $0x2, %edi
movl %ebp, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x319e
jmp 0x54df