// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r13
movl %ecx, %eax
shrl $0x10, %eax
shlq $0x10, %rcx
orq $0x16, %rcx
leaq 0x20(%rsp), %r15
movw %ax, 0x4(%r15)
movl %ecx, (%r15)
movl $0x6, %r12d
xorl %ebx, %ebx
movl %r12d, %edx
movl %ebp, %edi
movq %r15, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0xdf6a
addl %eax, %ebx
movslq %eax, %rcx
addq %rcx, %r15
subl %eax, %r12d
jmp 0xdf78
callq 0x4040
cmpl $0x4, (%rax)
jne 0xe00d
testl %r12d, %r12d
jg 0xdf4b
cmpl $-0x1, %ebx
je 0xe015
movq %r14, %rdi
movl %ebp, %esi
callq 0xed47
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x4d, (%r14,%rcx)
jne 0xe259
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
decl 0x404(%r14)
cmpl $0x3, 0x404(%r14)
ja 0xe042
movq %r14, %rdi
movl %ebp, %esi
callq 0xef52
testl %eax, %eax
jg 0xdfcf
cmpl $-0x1, %eax
jne 0xe03a
callq 0x4040
cmpl $0x4, (%rax)
je 0xdfcf
movq %rax, %r15
movl $0x4, %edi
callq 0x4190
movl (%r15), %ecx
movl %ecx, (%rax)
jmp 0xe248
testl %ebx, %ebx
jg 0xdf86
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0xeb1e(%rip), %rsi      # 0x1cb50
movq %rbx, %rdi
jmp 0xe252
testl %eax, %eax
je 0xe238
movq %r13, 0x10(%rsp)
movl 0x400(%r14), %r13d
leal -0x400(%r13), %r15d
cmpl $0x400, %r13d           # imm = 0x400
cmovbl %r13d, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xe0a8
movl $0x400, %ebx            # imm = 0x400
subl %r15d, %ebx
movl %r15d, %esi
addq %r14, %rsi
leaq 0xc(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rdx
callq 0x4270
leaq (%rsp,%rbx), %rdi
addq $0xc, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r14, %rsi
movq %r15, %rdx
callq 0x4270
jmp 0xe0ae
movl %r15d, %r12d
addq %r14, %r12
movl (%r12), %ebx
leal 0x4(%r13), %eax
addl $0xfffffc04, %r13d      # imm = 0xFFFFFC04
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r13d
movl %r13d, 0x400(%r14)
movl 0x404(%r14), %r15d
addl $-0x4, %r15d
movl %r15d, 0x404(%r14)
movq 0x10(%rsp), %r13
leaq 0x10(%r13), %rax
movq %rax, 0x18(%rsp)
movq %rax, (%r13)
movq $0x0, 0x8(%r13)
movb $0x0, 0x10(%r13)
testl %ebx, %ebx
je 0xe1f4
testl %r15d, %r15d
jne 0xe136
jmp 0xe11b
callq 0x4040
cmpl $0x4, (%rax)
jne 0xe215
movq %r14, %rdi
movl %ebp, %esi
callq 0xef52
testl %eax, %eax
je 0xe203
jle 0xe10d
movl 0x404(%r14), %r15d
cmpl %r15d, %ebx
cmovbl %ebx, %r15d
movq 0x8(%r13), %r12
leaq (%r12,%r15), %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x40d0
addq (%r13), %r12
movl 0x400(%r14), %ecx
leal -0x400(%rcx), %eax
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
leal (%rax,%r15), %ecx
cmpl $0x401, %ecx            # imm = 0x401
jb 0xe1a4
movl $0x400, %r13d           # imm = 0x400
subl %eax, %r13d
movl %eax, %esi
addq %r14, %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x4270
addq %r13, %r12
movl %r15d, %edx
subl %r13d, %edx
movq 0x10(%rsp), %r13
movq %r12, %rdi
movq %r14, %rsi
jmp 0xe1af
movl %eax, %esi
addq %r14, %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x4270
movl 0x400(%r14), %eax
movl 0x404(%r14), %ecx
leal (%rax,%r15), %edx
cmpl $0x400, %edx            # imm = 0x400
leal -0x400(%rax,%r15), %eax
cmovbl %edx, %eax
movl %eax, 0x400(%r14)
subl %r15d, %ecx
movl %ecx, 0x404(%r14)
subl %r15d, %ebx
movl %ecx, %r15d
jne 0xe106
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
jmp 0xe227
movq %rax, %r15
movl $0x4, %edi
callq 0x4190
movl (%r15), %ecx
movl %ecx, (%rax)
leaq 0xe912(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
leaq 0xe8f1(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x1, %edi
callq 0x4190
leaq 0xe896(%rip), %rsi      # 0x1cb00
jmp 0xe24f
jmp 0xe26e
movq %rax, %r14
movq (%r13), %rdi
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xe28a
movq (%rax), %rsi
incq %rsi
callq 0x42f0
movq %r14, %rdi
callq 0x44f0