// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_find_load(cp_cmd)
bool control_conn_t::process_find_load(cp_cmd pktType)
{
    using std::string;
    
    constexpr int pkt_size = 4;
    
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }
    
    srvname_len_t srvname_len;
    rbuf.extract(&srvname_len, 1, sizeof(srvname_len));
    if (srvname_len <= 0 || srvname_len > (1024 - 3)) {
        // Queue error response / mark connection bad
        char badreqRep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreqRep, 1)) return false;
        bad_conn_close = true;
        return true;
    }
    chklen = srvname_len + 3; // packet type + (2 byte) length + service name
    
    if (rbuf.get_length() < chklen) {
        // packet not complete yet; read more
        return true;
    }
    
    service_record * record = nullptr;
    
    string service_name = rbuf.extract_string(3, srvname_len);

    // Clear the packet from the buffer
    rbuf.consume(chklen);
    chklen = 0;
    
    cp_rply fail_code = cp_rply::NOSERVICE;

    if (pktType == cp_cmd::LOADSERVICE) {
        // LOADSERVICE
        try {
            record = services->load_service(service_name.c_str());
        }
        catch (service_description_exc &sdexc) {
            log_service_load_failure(sdexc);
            fail_code = cp_rply::SERVICE_DESC_ERR;
        }
        catch (service_not_found &snf) {
            log(loglevel_t::ERROR, "Could not load service ", snf.service_name, ": ",
                    snf.exc_description);
            // fail_code = cp_rply::NOSERVICE;   (already set)
        }
        catch (service_load_exc &slexc) {
            log(loglevel_t::ERROR, "Could not load service ", slexc.service_name, ": ",
                    slexc.exc_description);
            fail_code = cp_rply::SERVICE_LOAD_ERR;
        }
    }
    else {
        // FINDSERVICE
        record = services->find_service(service_name.c_str());
    }
    
    if (record == nullptr) {
        std::vector<char> rp_buf = { (char)fail_code };
        if (! queue_packet(std::move(rp_buf))) return false;
        return true;
    }

    // Allocate a service handle
    handle_t handle = allocate_service_handle(record);
    std::vector<char> rp_buf;
    rp_buf.reserve(7);
    rp_buf.push_back((char)cp_rply::SERVICERECORD);
    rp_buf.push_back(static_cast<char>(record->get_state()));
    for (int i = 0; i < (int) sizeof(handle); i++) {
        rp_buf.push_back(*(((char *) &handle) + i));
    }
    rp_buf.push_back(static_cast<char>(record->get_target_state()));
    if (! queue_packet(std::move(rp_buf))) return false;
    
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
cmpl $0x3, 0x484(%rdi)
ja 0x235f2
movl $0x4, 0x7c(%rbx)
movb $0x1, %r14b
movl %r14d, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ebp
leaq 0x80(%rbx), %r15
leaq 0xe(%rsp), %r14
pushq $0x1
popq %rdx
pushq $0x2
popq %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x25e18
movzwl (%r14), %ecx
leal -0x3fe(%rcx), %eax
cmpw $0xfc02, %ax            # imm = 0xFC02
ja 0x23641
leaq 0x30(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %r14d
testb %al, %al
je 0x235e2
movb $0x1, 0x78(%rbx)
jmp 0x235e2
leal 0x3(%rcx), %eax
movl %eax, 0x7c(%rbx)
movb $0x1, %r14b
cmpl %eax, 0x484(%rbx)
jb 0x235e2
leaq 0x30(%rsp), %rdi
pushq $0x3
popq %rdx
movq %r15, %rsi
callq 0x25e94
movl 0x7c(%rbx), %esi
movq %r15, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movq 0x70(%rbx), %r14
cmpb $0x2, %bpl
jne 0x2368e
movq 0x30(%rsp), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %rax, %r14
jmp 0x236bf
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xcc4e
leaq 0x10(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x1e1b0
movq %rax, %r14
movq %r15, %rdi
callq 0x8b98
testq %r14, %r14
je 0x23750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2547e
movl %eax, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
pushq $0x7
popq %rsi
callq 0x25f74
leaq 0x7(%rsp), %rsi
movb $0x3b, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
movb 0x2c(%r14), %al
leaq 0x7(%rsp), %rsi
movb %al, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
cmpq $0x4, %r12
je 0x23739
leaq (%rsp,%r12), %rsi
addq $0x8, %rsi
movq %r15, %rdi
callq 0x25ffe
incq %r12
jmp 0x2371e
movb 0x2d(%r14), %al
leaq 0x7(%rsp), %rsi
movb %al, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
jmp 0x2376d
movb $0x3c, %bpl
leaq 0x8(%rsp), %rsi
movb %bpl, (%rsi)
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x25f3e
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x253ac
movl %eax, %r14d
movq %r15, %rdi
callq 0xc3e8
leaq 0x30(%rsp), %rdi
callq 0x8b98
jmp 0x235e2
jmp 0x2382f
jmp 0x2382f
movq %rax, %r14
cmpl $0x3, %edx
jne 0x237c3
movq %r14, %rdi
callq 0x8200
movq %rax, %rdi
callq 0xade0
movb $0x47, %bpl
callq 0x8a40
jmp 0x23753
cmpl $0x2, %edx
jne 0x237e9
movq %r14, %rdi
callq 0x8200
leaq 0x20(%rax), %rsi
movq %rax, %rdi
callq 0x25381
movb $0x3c, %bpl
callq 0x8a40
jmp 0x23753
cmpl $0x1, %edx
jne 0x23841
movq %r14, %rdi
callq 0x8200
leaq 0x20(%rax), %rsi
movq %rax, %rdi
callq 0x25381
movb $0x48, %bpl
callq 0x8a40
jmp 0x23753
jmp 0x2382f
jmp 0x2382f
jmp 0x2382f
movq %rax, %r14
callq 0x8a40
jmp 0x23841
movq %rax, %rdi
callq 0xaebb
jmp 0x23834
jmp 0x23834
jmp 0x23834
jmp 0x23834
movq %rax, %r14
jmp 0x23841
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xc3e8
leaq 0x30(%rsp), %rdi
callq 0x8b98
movq %r14, %rdi
callq 0x8a90
nop