// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %rbx
cmpl $0x5, 0x484(%rdi)
ja 0x24fe8
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x25108
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movb 0x80(%rbx,%rax), %bpl
leaq 0x34(%rsp), %r15
pushq $0x2
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x250f3
movq %rax, %r14
movl 0x28(%rax), %eax
decl %eax
cmpl $0x3, %eax
jae 0x250f3
cmpl $0x2, 0x298(%r14)
jne 0x250f3
movq 0x2d8(%r14), %r15
movl 0x2d0(%r14), %eax
leaq 0x14(%rsp), %r12
movl %eax, -0x4(%r12)
leaq 0x16(%rsp), %rsi
movw $0x49, (%rsi)
leaq 0x18(%rsp), %r13
pushq $0x2
popq %rdx
leaq 0xf(%rsp), %rcx
movq %r13, %rdi
callq 0x25f3e
movq 0x8(%r13), %rsi
leaq 0x10(%rsp), %rdx
movq %r13, %rdi
movq %r12, %rcx
callq 0x263c8
leaq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl 0x10(%rsp), %ecx
addq %r15, %rcx
movq %r15, %rdx
callq 0x26370
testb $0x1, %bpl
je 0x250d7
movq %r14, %rdi
callq 0x263e8
leaq 0x18(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x253ac
movl %eax, %ebx
movq %r14, %rdi
callq 0xc3e8
jmp 0x25108
leaq 0x18(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2511b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90