// File: davmac314[P]dinit/src/control.cc
// Function: control_conn_t::list_services5()
bool control_conn_t::list_services5()
{
    rbuf.consume(1); // clear request packet
    chklen = 0;

    try {
        auto slist = services->list_services();
        for (auto sptr : slist) {
            if (sptr->get_type() == service_type_t::PLACEHOLDER) continue;

            std::vector<char> pkt_buf;
            int hdrsize = 2 + STATUS_BUFFER5_SIZE;

            const std::string &name = sptr->get_name();
            int nameLen = std::min((size_t)256, name.length());
            pkt_buf.resize(hdrsize + nameLen);

            pkt_buf[0] = (char)cp_rply::SVCINFO;
            pkt_buf[1] = nameLen;

            fill_status_buffer5(&pkt_buf[2], sptr);

            for (int i = 0; i < nameLen; i++) {
                pkt_buf[hdrsize+i] = name[i];
            }

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

        char ack_buf[] = { (char) cp_rply::LISTDONE };
        if (!queue_packet(ack_buf, 1)) return false;
        
        return true;
    }
    catch (std::bad_alloc &exc)
    {
        do_oom_close();
        return true;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
subq $-0x80, %rdi
movl $0x1, %esi
callq 0x5e1a0
movq -0xb8(%rbp), %rax
movl $0x0, 0x7c(%rax)
movq 0x70(%rax), %rdi
callq 0x5ef10
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x5ef30
jmp 0x59a8d
leaq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x16aa0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x16ad0
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x16b00
testb $0x1, %al
jne 0x59ac5
jmp 0x59ce7
leaq -0x48(%rbp), %rdi
callq 0x16b30
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2d5a0
cmpl $0x0, %eax
jne 0x59af9
jmp 0x59cd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x59c50
leaq -0x70(%rbp), %rdi
callq 0x30d60
movl $0x10, -0x74(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2d420
movq %rax, -0x80(%rbp)
movq $0x100, -0x90(%rbp) # imm = 0x100
movq -0x80(%rbp), %rdi
callq 0xab20
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x12a60
movq %rax, -0xc0(%rbp)
jmp 0x59b4d
movq -0xc0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x74(%rbp), %eax
movl -0x84(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x31490
jmp 0x59b75
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x5e950
movq -0xc8(%rbp), %rdi
movb $0x3e, (%rax)
movb -0x84(%rbp), %al
movb %al, -0xc9(%rbp)
movl $0x1, %esi
callq 0x5e950
movb -0xc9(%rbp), %cl
movq -0xc8(%rbp), %rdi
movb %cl, (%rax)
movl $0x2, %esi
callq 0x5e950
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x5c450
jmp 0x59bd0
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x59c94
movq -0x80(%rbp), %rdi
movslq -0x9c(%rbp), %rsi
callq 0xa7b0
movb (%rax), %al
movb %al, -0xca(%rbp)
movl -0x74(%rbp), %eax
addl -0x9c(%rbp), %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x5e950
movb -0xca(%rbp), %cl
movb %cl, (%rax)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x59bda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x13f20
leaq -0x28(%rbp), %rdi
callq 0x16b80
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x59d44
movq -0x30(%rbp), %rdi
callq 0xa240
movq -0xb8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x5eff0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
callq 0xac30
jmp 0x59d36
movq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5bc70
testb $0x1, %al
jne 0x59cb8
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x59cc2
movl $0x0, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x13f20
movl -0xa0(%rbp), %eax
testl %eax, %eax
jne 0x59d2d
jmp 0x59cd7
jmp 0x59cd9
leaq -0x48(%rbp), %rdi
callq 0x16b60
jmp 0x59aaf
movq -0xb8(%rbp), %rdi
movb 0x1f757(%rip), %al      # 0x7944b
movb %al, -0xa1(%rbp)
leaq -0xa1(%rbp), %rsi
movl $0x1, %edx
callq 0x58340
testb $0x1, %al
jne 0x59d1f
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x59d2d
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x16b80
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0xacc0
nopl (%rax)