// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_catlog()
bool control_conn_t::process_catlog()
{
    // 1 byte packet type
    // 1 byte reserved for future use
    // handle
    constexpr int pkt_size = 2 + sizeof(handle_t);

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

    handle_t handle;
    char flags = rbuf[1];

    rbuf.extract(&handle, 2, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || (service->get_type() != service_type_t::PROCESS
            && service->get_type() != service_type_t::BGPROCESS
            && service->get_type() != service_type_t::SCRIPTED)) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    base_process_service *bps = static_cast<base_process_service *>(service);
    if (bps->get_log_mode() != log_type_id::BUFFER) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    auto buffer_details = bps->get_log_buffer();
    const char *bufaddr = buffer_details.first;
    unsigned buflen = buffer_details.second;

    std::vector<char> pkt = { (char)cp_rply::SERVICE_LOG, 0 /* flags; reserved for future */ };
    pkt.insert(pkt.end(), (char *)(&buflen), (char *)(&buflen + 1));
    pkt.insert(pkt.end(), bufaddr, bufaddr + buflen);
    if ((flags & 1) != 0) {
        bps->clear_log_buffer();
    }
    return queue_packet(std::move(pkt));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpl $0x5, 0x484(%rdi)
ja 0x2a7d8
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2a975
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r15d
leal 0x1(%r15), %eax
leal -0x3ff(%r15), %ecx
movl $0x400, %r12d           # imm = 0x400
cmpl %r12d, %eax
cmovbl %eax, %ecx
movb 0x80(%rbx,%rcx), %bpl
leal 0x2(%r15), %eax
addl $0xfffffc02, %r15d      # imm = 0xFFFFFC02
cmpl %r12d, %eax
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x2a858
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x2a863
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x480(%rbx), %eax
leal 0x6(%rax), %ecx
addl $0xfffffc06, %eax       # imm = 0xFFFFFC06
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x480(%rbx)
addl $-0x6, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0x2ba66
testq %rax, %rax
je 0x2a95e
movq %rax, %r14
movl 0x28(%rax), %eax
decl %eax
cmpl $0x3, %eax
jae 0x2a95e
cmpl $0x2, 0x298(%r14)
jne 0x2a95e
movq 0x2d8(%r14), %r15
movl 0x2d0(%r14), %eax
leaq 0x8(%rsp), %r12
movl %eax, -0x4(%r12)
leaq 0xe(%rsp), %rsi
movw $0x49, (%rsi)
leaq 0x10(%rsp), %r13
leaq 0x3(%rsp), %rcx
movl $0x2, %edx
movq %r13, %rdi
callq 0x2b970
movq 0x8(%r13), %rsi
leaq 0x4(%rsp), %rdx
movq %r13, %rdi
movq %r12, %rcx
callq 0x2d9f0
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl 0x4(%rsp), %ecx
addq %r15, %rcx
movq %r15, %rdx
callq 0x2d810
testb $0x1, %bpl
je 0x2a935
movq %r14, %rdi
callq 0x2be06
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ada4
movl %eax, %ebx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2a975
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
jmp 0x2a975
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
movl %eax, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a988
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2a9a2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0