// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_query_dsc_dir()
bool control_conn_t::process_query_dsc_dir()
{
    // packet contains command byte, spare byte, and service handle
    constexpr int pkt_size = 2 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    bool spare_ok = (rbuf[1] == 0);
    handle_t handle;
    rbuf.extract(&handle, 2, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || !spare_ok) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::SVCDSCDIR
    // 4 bytes (uint32_t) = directory length (no nul terminator)
    // N bytes            = directory (no nul)
    std::vector<char> reppkt;
    auto sdir_len = static_cast<uint32_t>(strlen(service->get_service_dsc_dir()));
    reppkt.resize(1 + sizeof(uint32_t) + sdir_len);  // packet type, dir length, dir
    reppkt[0] = (char)cp_rply::SVCDSCDIR;
    std::memcpy(&reppkt[1], &sdir_len, sizeof(sdir_len));
    std::memcpy(&reppkt[1 + sizeof(uint32_t)], service->get_service_dsc_dir(), sdir_len);

    if (! queue_packet(std::move(reppkt))) return false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl 0x484(%rdi), %ebp
cmpl $0x5, %ebp
ja 0x2aac6
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2ac41
leaq 0x80(%rbx), %r13
movl 0x480(%rbx), %r14d
leal 0x1(%r14), %eax
leal -0x3ff(%r14), %ecx
movl $0x400, %r15d           # imm = 0x400
cmpl %r15d, %eax
cmovbl %eax, %ecx
movb 0x80(%rbx,%rcx), %al
movb %al, 0xb(%rsp)
leal 0x2(%r14), %eax
leal -0x3fe(%r14), %r12d
cmpl %r15d, %eax
cmovbl %eax, %r12d
leal -0x3fd(%r12), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x2ab53
subl %r12d, %r15d
movl %r12d, %esi
addq %r13, %rsi
movq %r13, 0x30(%rsp)
leaq 0xc(%rsp), %r13
movq %r13, %rdi
movq %r15, %rdx
callq 0x84d0
leaq (%rsp,%r15), %rdi
addq $0xc, %rdi
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x84d0
jmp 0x2ab59
movl %r12d, %eax
addq %rax, %r13
movl (%r13), %esi
leal 0x6(%r14), %eax
addl $0xfffffc06, %r14d      # imm = 0xFFFFFC06
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r14d
movl %r14d, 0x480(%rbx)
addl $-0x6, %ebp
movl %ebp, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movq %rbx, %rdi
callq 0x2b906
cmpb $0x0, 0xb(%rsp)
jne 0x2ac2a
movq %rax, %r14
testq %rax, %rax
je 0x2ac2a
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movq 0x100(%r14), %rdi
callq 0x8230
movq %rax, %r12
movl %r12d, %r15d
leaq 0x5(%r15), %rsi
movq %r13, %rdi
callq 0x1c190
leaq 0x10(%rsp), %r13
movq (%r13), %rax
movb $0x4d, (%rax)
movq (%r13), %rax
movl %r12d, 0x1(%rax)
movq (%r13), %rdi
addq $0x5, %rdi
movq 0x100(%r14), %rsi
movq %r15, %rdx
callq 0x84d0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2acb2
movl %eax, %ebx
movq (%r13), %rdi
testq %rdi, %rdi
je 0x2ac41
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
jmp 0x2ac41
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
movl %eax, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2ac6c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0