// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0x484(%rdi), %ebp
cmpl $0x5, %ebp
ja 0x2a6a2
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2a87a
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, 0xa(%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 0x2a72f
subl %r12d, %r15d
movl %r12d, %esi
addq %r13, %rsi
movq %r13, 0x30(%rsp)
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r15, %rdx
callq 0x84d0
leaq (%rsp,%r15), %rdi
addq $0x10, %rdi
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x84d0
jmp 0x2a735
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
testq %rax, %rax
je 0x2a863
movq %rax, %r14
movl 0x28(%rax), %eax
decl %eax
cmpl $0x3, %eax
jae 0x2a863
cmpl $0x2, 0x298(%r14)
jne 0x2a863
movq 0x2d8(%r14), %r15
movl 0x2d0(%r14), %eax
leaq 0x10(%rsp), %r12
movl %eax, -0x4(%r12)
leaq 0x16(%rsp), %rsi
movw $0x49, (%rsi)
leaq 0x18(%rsp), %r13
leaq 0xb(%rsp), %rcx
movl $0x2, %edx
movq %r13, %rdi
callq 0x2b810
movq 0x8(%r13), %rsi
leaq 0xc(%rsp), %rdx
movq %r13, %rdi
movq %r12, %rcx
callq 0x2d7b0
leaq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl 0xc(%rsp), %ecx
addq %r15, %rcx
movq %r15, %rdx
callq 0x2d5c8
testb $0x1, 0xa(%rsp)
je 0x2a83a
movq 0x2d8(%r14), %rax
cmpq %rax, 0x2e0(%r14)
je 0x2a817
movq %rax, 0x2e0(%r14)
cmpq %rax, 0x2e8(%r14)
je 0x2a82f
movq %r14, %rdi
addq $0x2d8, %rdi            # imm = 0x2D8
callq 0x2c6f2
movl $0x0, 0x2d0(%r14)
leaq 0x18(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2acb2
movl %eax, %ebx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2a87a
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
jmp 0x2a87a
leaq 0x18(%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
jmp 0x2a88d
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2a8a7
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
nop