// File: davmac314[P]dinit/src/dinitctl.cc
// Function: get_service_description_dir[abi:cxx11](int, cpbuffer<1024u>&, unsigned int)
static std::string get_service_description_dir(int socknum, cpbuffer_t &rbuffer, handle_t service_handle)
{
    auto m = membuf()
            .append((char)cp_cmd::QUERYSERVICEDSCDIR)
            .append<char>(0)
            .append(service_handle);

    write_all_x(socknum, m);
    wait_for_reply(rbuffer, socknum);

    if (rbuffer[0] != (char)cp_rply::SVCDSCDIR) {
        throw dinit_protocol_error();
    }
    rbuffer.consume(1);

    fill_buffer_to(rbuffer, socknum, 4);

    uint32_t sdir_len;
    rbuffer.extract(&sdir_len, 0, sizeof(uint32_t));
    rbuffer.consume(4);

    std::string result_str;
    static_assert(sizeof(unsigned) >= sizeof(uint32_t), "");
    unsigned needed = sdir_len;

    while (needed > 0) {
        unsigned available = rbuffer.get_length();

        if (available == 0) {
            fill_some(rbuffer, socknum);
            available = rbuffer.get_length();
        }

        unsigned to_use = std::min(available, needed);
        size_t orig_len = result_str.length();
        result_str.resize(orig_len + to_use);
        rbuffer.extract(&result_str[orig_len], 0, to_use);
        rbuffer.consume(to_use);
        needed -= to_use;
    }

    return result_str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x60(%rbp)
movq %rdi, %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movb $0x16, -0x27(%rbp)
leaq -0x26(%rbp), %rdi
leaq -0x27(%rbp), %rsi
callq 0x11b60
movb %al, -0x25(%rbp)
movb $0x0, -0x28(%rbp)
leaq -0x25(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x11b90
movw %ax, -0x24(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x11bc0
movl %eax, %ecx
movl %ecx, -0x22(%rbp)
shrq $0x20, %rax
movw %ax, -0x1e(%rbp)
movl -0xc(%rbp), %edi
leaq -0x22(%rbp), %rsi
callq 0x11c10
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x11350
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x4d, %eax
je 0xd53c
movl $0x1, %edi
callq 0x51c0
movq %rax, %rdi
leaq 0x245ad(%rip), %rsi     # 0x31ae0
xorl %eax, %eax
movl %eax, %edx
callq 0x56b0
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x4, %edx
callq 0x11440
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
xorl %edx, %edx
movl $0x4, %ecx
callq 0x11540
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x115f0
movq -0x60(%rbp), %rdi
movb $0x0, -0x2d(%rbp)
callq 0x55c0
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jbe 0xd65f
movq -0x18(%rbp), %rdi
callq 0x12f00
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0xd5e2
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x12f20
jmp 0xd5ba
movq -0x18(%rbp), %rdi
callq 0x12f00
movl %eax, -0x38(%rbp)
jmp 0xd5e2
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x5280
jmp 0xd67c
leaq -0x38(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x11840
movq -0x60(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x48(%rbp)
callq 0x5620
movq -0x60(%rbp), %rdi
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
movl -0x48(%rbp), %eax
addq %rax, %rsi
callq 0x55a0
jmp 0xd616
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rsi
callq 0x57a0
movq %rax, -0x68(%rbp)
jmp 0xd631
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
movl -0x48(%rbp), %ecx
xorl %edx, %edx
callq 0x11540
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x115f0
movl -0x48(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
jmp 0xd590
movb $0x1, -0x2d(%rbp)
testb $0x1, -0x2d(%rbp)
jne 0xd672
movq -0x60(%rbp), %rdi
callq 0x5280
movq -0x58(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x56f0
nopw %cs:(%rax,%rax)