// File: davmac314[P]dinit/src/includes/dinit-client.h
// Function: get_service_description_dirs[abi:cxx11](int, cpbuffer<1024u>&)
inline std::vector<std::string> get_service_description_dirs(int socknum, cpbuffer_t &rbuffer)
{
    using namespace std;

    char buf[1] = { (char)cp_cmd::QUERY_LOAD_MECH };
    write_all_x(socknum, buf, 1);

    wait_for_reply(rbuffer, socknum);

    if (rbuffer[0] != (char)cp_rply::LOADER_MECH) {
        throw dinit_protocol_error();
    }

    // Packet type, load mechanism type, packet size:
    fill_buffer_to(rbuffer, socknum, 2 + sizeof(uint32_t));

    if (rbuffer[1] != SSET_TYPE_DIRLOAD) {
        throw dinit_unknown_sd_conf();
    }

    vector<string> paths;

    uint32_t pktsize;
    rbuffer.extract(&pktsize, 2, sizeof(uint32_t));

    fill_buffer_to(rbuffer, socknum, 2 + sizeof(uint32_t) * 3); // path entries, cwd length

    uint32_t path_entries;  // number of service directories
    rbuffer.extract(&path_entries, 2 + sizeof(uint32_t), sizeof(uint32_t));

    uint32_t cwd_len;
    rbuffer.extract(&cwd_len, 2 + sizeof(uint32_t) * 2, sizeof(uint32_t));
    rbuffer.consume(2 + sizeof(uint32_t) * 3);
    pktsize -= 2 + sizeof(uint32_t) * 3;

    // Read current working directory of daemon:
    std::string dinit_cwd = read_string(socknum, rbuffer, cwd_len);

    // dinit daemon base directory against which service paths are resolved is in dinit_cwd

    for (uint32_t i = 0; i < path_entries; ++i) {
        uint32_t plen;
        fill_buffer_to(rbuffer, socknum, sizeof(uint32_t));
        rbuffer.extract(&plen, 0, sizeof(uint32_t));
        rbuffer.consume(sizeof(uint32_t));
        //paths.push_back(read_string(socknum, rbuffer, plen));
        string sd_rel_path = read_string(socknum, rbuffer, plen);
        paths.push_back(combine_paths(dinit_cwd, sd_rel_path.c_str()));
    }

    return paths;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movb 0xfb40(%rip), %al       # 0x2307d
movb %al, -0x19(%rbp)
movl -0xc(%rbp), %edi
leaq -0x19(%rbp), %rsi
movl $0x1, %edx
callq 0x112c0
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x11350
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x40, %eax
je 0x1358d
movl $0x1, %edi
callq 0x51c0
movq %rax, %rdi
leaq 0x1e55c(%rip), %rsi     # 0x31ae0
xorl %eax, %eax
movl %eax, %edx
callq 0x56b0
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x6, %edx
callq 0x11440
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x1, %eax
je 0x135d1
movl $0x1, %edi
callq 0x51c0
movq %rax, %rdi
leaq 0x1e700(%rip), %rsi     # 0x31cc8
xorl %eax, %eax
movl %eax, %edx
callq 0x56b0
movq -0xc0(%rbp), %rdi
movb $0x0, -0x1a(%rbp)
callq 0x134a0
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x2, %edx
movl $0x4, %ecx
callq 0x11540
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0xe, %edx
callq 0x11440
jmp 0x1360b
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x6, %edx
movl $0x4, %ecx
movl %ecx, -0xc4(%rbp)
callq 0x11540
movl -0xc4(%rbp), %ecx
movq -0x18(%rbp), %rdi
leaq -0x34(%rbp), %rsi
movl $0xa, %edx
callq 0x11540
movq -0x18(%rbp), %rdi
movl $0xe, %esi
callq 0x115f0
movl -0x20(%rbp), %eax
addl $-0xe, %eax
movl %eax, -0x20(%rbp)
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x34(%rbp), %ecx
leaq -0x58(%rbp), %rdi
callq 0x14550
jmp 0x1366c
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x1378f
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x4, %edx
callq 0x11440
jmp 0x13692
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
movl $0x4, %ecx
movl %ecx, -0xc8(%rbp)
callq 0x11540
movl -0xc8(%rbp), %esi
movq -0x18(%rbp), %rdi
callq 0x115f0
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x60(%rbp), %ecx
leaq -0x80(%rbp), %rdi
callq 0x14550
jmp 0x136d0
leaq -0xb0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x14240
jmp 0x136e2
leaq -0x80(%rbp), %rdi
callq 0x5160
movq %rax, %rcx
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x13f20
jmp 0x1370a
movq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x146a0
jmp 0x1371f
leaq -0xa0(%rbp), %rdi
callq 0x5280
leaq -0x80(%rbp), %rdi
callq 0x5280
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x13673
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x137cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x137a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x13784
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5280
leaq -0x80(%rbp), %rdi
callq 0x5280
jmp 0x137a4
movb $0x1, -0x1a(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5280
testb $0x1, -0x1a(%rbp)
jne 0x137bb
jmp 0x137af
leaq -0x58(%rbp), %rdi
callq 0x5280
jmp 0x137cb
movq -0xc0(%rbp), %rdi
callq 0x13810
movq -0xb8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x13810
movq -0x28(%rbp), %rdi
callq 0x56f0