// File: /workspace/github_c_makefile_star2_O2/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 0x4517
callq 0x2060
movl $0x16, (%rax)
pushq $-0x1
popq %r13
jmp 0x4688
movq %r8, %r14
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %ebp
cmpq $0x0, 0x10f57(%rip)     # 0x15480
pushq $-0x1
popq %r13
jne 0x4549
movl $0xfa0, %edi            # imm = 0xFA0
callq 0xa957
movq %rax, 0x10f40(%rip)     # 0x15480
testq %rax, %rax
je 0x4688
movl %ebp, 0x4(%rsp)
movl 0x10efd(%rip), %ebp     # 0x15450
testl %ebp, %ebp
je 0x457f
testq %r14, %r14
setne %cl
movq 0x10ef4(%rip), %rax     # 0x15458
cmpq %r14, %rax
setne %dl
testb %dl, %cl
jne 0x45b5
testq %r14, %r14
je 0x4589
leal (%rbx,%rbp), %eax
cmpl $0x579, %eax            # imm = 0x579
jge 0x45b5
jmp 0x45c0
cmpl $0xf9d, %ebx            # imm = 0xF9D
jge 0x45ca
jmp 0x45de
testq %rax, %rax
jne 0x45b5
leaq 0x10ecb(%rip), %rsi     # 0x15460
pushq $0x1c
popq %rdx
movq %r12, %rdi
callq 0x2270
testl %eax, %eax
setne %al
leal (%rbx,%rbp), %ecx
cmpl $0x579, %ecx            # imm = 0x579
setge %cl
orb %al, %cl
je 0x45c0
callq 0x4428
movl 0x10e90(%rip), %ebp     # 0x15450
leal (%rbx,%rbp), %eax
cmpl $0xf9c, %eax            # imm = 0xF9C
jle 0x45da
callq 0x2060
movl $0x5a, (%rax)
jmp 0x4688
testl %ebp, %ebp
jne 0x4611
leaq 0x8(%r14), %rax
leaq 0x18(%r12), %rcx
testq %r14, %r14
movq 0x10e8f(%rip), %rdx     # 0x15480
movl $0x8000300, (%rdx)      # imm = 0x8000300
leaq 0xcc82(%rip), %rsi      # 0x11280
movl (%rsi), %esi
movl %esi, 0x4(%rdx)
cmovneq %rax, %rcx
movl (%rcx), %eax
bswapl %eax
movl %eax, 0x8(%rdx)
pushq $0xc
popq %rbp
testq %r14, %r14
je 0x461f
movq %r14, 0x10e3b(%rip)     # 0x15458
jmp 0x4638
movups (%r12), %xmm0
movups 0xc(%r12), %xmm1
movups %xmm1, 0x10e3b(%rip)    # 0x1546c
movups %xmm0, 0x10e28(%rip)    # 0x15460
movl 0x4(%rsp), %eax
rolw $0x8, %ax
movq 0x10e39(%rip), %rcx     # 0x15480
movslq %ebp, %r12
leaq (%rcx,%r12), %rdi
addq $0x4, %rdi
movw %ax, -0x4(%rdi)
movl %ebx, %eax
rolw $0x8, %ax
movw %ax, -0x2(%rdi)
movslq %ebx, %rdx
movq %r15, %rsi
callq 0x2220
leal (%r12,%rbx), %eax
addl $0x4, %eax
movl %eax, 0x10dd8(%rip)     # 0x15450
leaq 0xcbd9(%rip), %rax      # 0x11258
pushq $0x1
popq %r13
cmpl $0x3, (%rax)
jge 0x469a
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
leaq 0x8019(%rip), %rax      # 0xc6bd
leaq 0x801c(%rip), %rdx      # 0xc6c7
cmovneq %rax, %rdx
leaq 0x7ff1(%rip), %rsi      # 0xc6a7
pushq $0x2
popq %rdi
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x23c0
jmp 0x4688