// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
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 0xded1
addl %eax, %ebx
movslq %eax, %rcx
addq %rcx, %r15
subl %eax, %r12d
xorl %ecx, %ecx
jmp 0xdef1
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0xdef1
testl %ebx, %ebx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmovgl %ebx, %r13d
movl $0x1, %ecx
testb $0x1, %cl
jne 0xdefd
testl %r12d, %r12d
jg 0xdeb0
jmp 0xdf00
movl %r13d, %ebx
cmpl $-0x1, %ebx
je 0xe1b9
movq %r14, %rdi
movl %ebp, %esi
callq 0xedbd
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x4d, (%r14,%rcx)
jne 0xe1db
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
decl 0x404(%r14)
movl $0x1, %ebx
cmpl $0x3, 0x404(%r14)
ja 0xdf76
movq %r14, %rdi
movl %ebp, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %r15d
movl %r15d, %ebx
jg 0xdf52
cmpl $-0x1, %ebx
je 0xdf84
testl %ebx, %ebx
jne 0xdf92
jmp 0xe184
callq 0x4040
cmpl $0x4, (%rax)
jne 0xe196
cmpl $-0x1, %ebx
je 0xdf52
movl 0x400(%r14), %eax
leal -0x400(%rax), %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xdff5
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0xc(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x4270
addq %r13, %r12
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4270
jmp 0xe000
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %r13
movl 0x400(%r14), %eax
leal 0x4(%rax), %ecx
addl $0xfffffc04, %eax       # imm = 0xFFFFFC04
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
addl $-0x4, 0x404(%r14)
leaq 0x10(%r13), %rax
movq %rax, 0x18(%rsp)
movq %rax, (%r13)
movq $0x0, 0x8(%r13)
movb $0x0, 0x10(%r13)
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
je 0xe13a
movl 0x404(%r14), %r15d
testl %r15d, %r15d
jne 0xe089
jmp 0xe06e
callq 0x4040
cmpl $0x4, (%rax)
jne 0xe161
movq %r14, %rdi
movl %ebp, %esi
callq 0xeffc
testl %eax, %eax
je 0xe14c
jle 0xe060
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 0xe0f7
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 0xe102
movl %eax, %esi
addq %r14, %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x4270
movl 0x400(%r14), %eax
leal (%rax,%r15), %ecx
cmpl $0x400, %ecx            # imm = 0x400
leal -0x400(%rax,%r15), %eax
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
subl %r15d, 0x404(%r14)
subl %r15d, %ebx
jne 0xe052
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x4190
movq %rax, %rdi
movl $0x0, (%rax)
jmp 0xe176
movq %rax, %r15
movl $0x4, %edi
callq 0x4190
movq %rax, %rdi
movl (%r15), %eax
movl %eax, (%rdi)
leaq 0xe9c3(%rip), %rsi      # 0x1cb40
xorl %edx, %edx
callq 0x44d0
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
jmp 0xe1a8
movq %rax, %r15
movl $0x4, %edi
callq 0x4190
movl (%r15), %ecx
movl %ecx, (%rax)
leaq 0xe991(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0xe97a(%rip), %rsi      # 0x1cb50
movq %rbx, %rdi
jmp 0xe1b2
movl $0x1, %edi
callq 0x4190
leaq 0xe914(%rip), %rsi      # 0x1cb00
jmp 0xe1af
jmp 0xe1f0
movq %rax, %r14
movq (%r13), %rdi
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xe20c
movq (%rax), %rsi
incq %rsi
callq 0x42f0
movq %r14, %rdi
callq 0x44f0