// File: davmac314[P]dinit/src/dinit-monitor.cc
// Function: read_var_and_issue(int, cpbuffer<1024u>&, unsigned long, std::unordered_set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<stringview, std::allocator<stringview>>&, bool&, char const*, char const*)
static size_t read_var_and_issue(int socknum, cpbuffer_t &rbuffer, size_t dsz, const std::unordered_set<std::string> &varset,
        std::string &enval, std::vector<stringview> &command_parts, bool &issued, const char* str_set, const char *str_unset)
{
    enval.clear();
    issued = false;
    while (dsz > 0) {
        auto colen = rbuffer.get_contiguous_length(rbuffer.get_ptr(0));
        auto chlen = std::min((size_t)colen, dsz);
        for (unsigned i = 0; i < chlen; ++i) {
            if (rbuffer[i] != '\0') {
                continue;
            }
            enval.append(rbuffer.get_ptr(0), rbuffer.get_ptr(0) + i);
            rbuffer.consume(i + 1);
            issued = issue_var(enval, varset, command_parts, str_set, str_unset);
            return dsz - i - 1;
        }
        // copy what we have so far and fill some more
        enval.append(rbuffer.get_ptr(0), rbuffer.get_ptr(0) + chlen);
        rbuffer.consume(chlen);
        dsz -= chlen;
        if (dsz == 0) {
            // didn't find null terminator, malformed
            throw dinit_protocol_error();
        }
        if (rbuffer.get_length() == 0) {
            fill_some(rbuffer, socknum);
        }
    }
    // unreachable
    throw dinit_protocol_error();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x33c0
movq 0x10(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x18(%rbp)
jbe 0x51ba
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xa220
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0xa190
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x87b0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpq -0x40(%rbp), %rax
jae 0x5123
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x64e0
movsbl %al, %eax
cmpl $0x0, %eax
je 0x5093
jmp 0x5115
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xa220
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xa220
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
movl -0x4c(%rbp), %eax
addq %rax, %rdx
callq 0xa260
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
addl $0x1, %esi
callq 0x66d0
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x20(%rbp), %r8
callq 0x5910
movb %al, %cl
movq 0x10(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl -0x4c(%rbp), %ecx
subq %rcx, %rax
subq $0x1, %rax
addq $0x80, %rsp
popq %rbp
retq
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x506d
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xa220
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xa220
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq %rax, %rdx
addq -0x40(%rbp), %rdx
callq 0xa260
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %esi
callq 0x66d0
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x519b
movl $0x1, %edi
callq 0x3130
movq %rax, %rdi
leaq 0x10b96(%rip), %rsi     # 0x15d28
xorl %eax, %eax
movl %eax, %edx
callq 0x34e0
movq -0x10(%rbp), %rdi
callq 0xa2d0
cmpl $0x0, %eax
jne 0x51b5
movq -0x10(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0xa2f0
jmp 0x501e
movl $0x1, %edi
callq 0x3130
movq %rax, %rdi
leaq 0x10b5a(%rip), %rsi     # 0x15d28
xorl %eax, %eax
movl %eax, %edx
callq 0x34e0
nopw (%rax,%rax)