// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x57cf
cmpq $0x0, -0x20(%rbp)
je 0x57cf
callq 0x2050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5a54
cmpq $0x0, 0x14cb9(%rip)     # 0x1a490
jne 0x57ea
movl $0xfa0, %edi            # imm = 0xFA0
callq 0xfe60
movq %rax, 0x14ca6(%rip)     # 0x1a490
cmpq $0x0, 0x14c9e(%rip)     # 0x1a490
jne 0x5800
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5a54
cmpl $0x0, 0x14c59(%rip)     # 0x1a460
je 0x585d
cmpq $0x0, -0x28(%rbp)
je 0x581d
movq -0x28(%rbp), %rax
cmpq 0x14c4d(%rip), %rax     # 0x1a468
jne 0x5858
cmpq $0x0, -0x28(%rbp)
jne 0x5848
cmpq $0x0, 0x14c3c(%rip)     # 0x1a468
jne 0x5858
movq -0x20(%rbp), %rdi
leaq 0x14c37(%rip), %rsi     # 0x1a470
movl $0x1c, %edx
callq 0x21c0
cmpl $0x0, %eax
jne 0x5858
movl 0x14c12(%rip), %eax     # 0x1a460
addl -0x14(%rbp), %eax
cmpl $0x578, %eax            # imm = 0x578
jle 0x585d
callq 0x5680
movl 0x14bfd(%rip), %eax     # 0x1a460
addl -0x14(%rbp), %eax
addl $0x4, %eax
cmpl $0xfa0, %eax            # imm = 0xFA0
jle 0x5887
callq 0x2050
movl $0x5a, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5a54
cmpl $0x0, 0x14bd2(%rip)     # 0x1a460
jne 0x5923
jmp 0x5896
movl $0x3, %edi
callq 0x2100
movw %ax, -0x2a(%rbp)
movq 0x14be5(%rip), %rax     # 0x1a490
movw -0x2a(%rbp), %cx
movw %cx, (%rax)
jmp 0x58b4
movl $0x8, %edi
callq 0x2100
movw %ax, -0x2c(%rbp)
movq 0x14bc7(%rip), %rax     # 0x1a490
movw -0x2c(%rbp), %cx
movw %cx, 0x2(%rax)
movq 0x14bb8(%rip), %rax     # 0x1a490
leaq 0x109b1(%rip), %rcx     # 0x16290
movl (%rcx), %ecx
movl %ecx, 0x4(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x58f7
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x5901
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edi
callq 0x2160
movl %eax, -0x30(%rbp)
movq 0x14b7d(%rip), %rax     # 0x1a490
movl -0x30(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl $0xc, 0x14b3d(%rip)     # 0x1a460
cmpq $0x0, -0x28(%rbp)
je 0x5937
movq -0x28(%rbp), %rax
movq %rax, 0x14b33(%rip)     # 0x1a468
jmp 0x5964
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, 0x14b2b(%rip)     # 0x1a470
movq 0x8(%rax), %rcx
movq %rcx, 0x14b28(%rip)     # 0x1a478
movq 0x10(%rax), %rcx
movq %rcx, 0x14b25(%rip)     # 0x1a480
movl 0x18(%rax), %eax
movl %eax, 0x14b24(%rip)     # 0x1a488
jmp 0x5966
movl -0x8(%rbp), %eax
movzwl %ax, %edi
callq 0x2100
movw %ax, -0x32(%rbp)
movq 0x14b14(%rip), %rax     # 0x1a490
movslq 0x14add(%rip), %rcx     # 0x1a460
movw -0x32(%rbp), %dx
movw %dx, (%rax,%rcx)
movl 0x14acf(%rip), %eax     # 0x1a460
addl $0x2, %eax
movl %eax, 0x14ac6(%rip)     # 0x1a460
movl -0x14(%rbp), %eax
movzwl %ax, %edi
callq 0x2100
movw %ax, -0x34(%rbp)
movq 0x14ae0(%rip), %rax     # 0x1a490
movslq 0x14aa9(%rip), %rcx     # 0x1a460
movw -0x34(%rbp), %dx
movw %dx, (%rax,%rcx)
movl 0x14a9b(%rip), %eax     # 0x1a460
addl $0x2, %eax
movl %eax, 0x14a92(%rip)     # 0x1a460
movq 0x14abb(%rip), %rdi     # 0x1a490
movslq 0x14a84(%rip), %rax     # 0x1a460
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x2230
movl -0x14(%rbp), %eax
addl 0x14a6b(%rip), %eax     # 0x1a460
movl %eax, 0x14a65(%rip)     # 0x1a460
leaq 0x10866(%rip), %rax     # 0x16268
cmpl $0x3, (%rax)
jl 0x5a4d
jmp 0x5a09
leaq 0x10858(%rip), %rax     # 0x16268
cmpl $0x2, (%rax)
jl 0x5a49
movq -0x28(%rbp), %rcx
leaq 0xcd34(%rip), %rdx      # 0x12754
leaq 0xcd23(%rip), %rax      # 0x1274a
cmpq $0x0, %rcx
cmovneq %rax, %rdx
movl -0x8(%rbp), %ecx
movl -0x14(%rbp), %r8d
movl $0x2, %edi
leaq 0xccf2(%rip), %rsi      # 0x12734
movb $0x0, %al
callq 0xfda0
jmp 0x5a4b
jmp 0x5a4d
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)