// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
cmpl $0x3, 0x484(%rdi)
ja 0x28102
movl $0x4, 0x7c(%rbx)
movb $0x1, %r14b
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ebp
leaq 0x80(%rbx), %r15
movl 0x480(%rbx), %r14d
leal 0x1(%r14), %eax
movl $0xfffffc01, %ecx       # imm = 0xFFFFFC01
addl %ecx, %r14d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r14d
addl %r14d, %ecx
cmpl $0xfffffbfe, %ecx       # imm = 0xFFFFFBFE
ja 0x2816b
movl $0x400, %r12d           # imm = 0x400
subl %r14d, %r12d
movl %r14d, %esi
addq %r15, %rsi
leaq 0xa(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc02, %r14d      # imm = 0xFFFFFC02
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x84d0
jmp 0x28178
movl %r14d, %eax
movzwl (%r15,%rax), %eax
movw %ax, 0xa(%rsp)
movzwl 0xa(%rsp), %ecx
leal -0x3fe(%rcx), %eax
movzwl %ax, %eax
cmpl $0xfc02, %eax           # imm = 0xFC02
ja 0x281b6
leaq 0x38(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
movl %eax, %r14d
testb %al, %al
je 0x280f0
movb $0x1, 0x78(%rbx)
jmp 0x280f0
leal 0x3(%rcx), %eax
movl %eax, 0x7c(%rbx)
movb $0x1, %r14b
cmpl %eax, 0x484(%rbx)
jb 0x280f0
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
movl $0x3, %edx
callq 0x2b8c0
movl 0x7c(%rbx), %eax
movl 0x480(%rbx), %ecx
leal (%rcx,%rax), %edx
cmpl $0x400, %edx            # imm = 0x400
leal -0x400(%rcx,%rax), %ecx
cmovbl %edx, %ecx
movl %ecx, 0x480(%rbx)
subl %eax, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movq 0x70(%rbx), %r14
cmpb $0x2, %bpl
jne 0x2822c
movq 0x38(%rsp), %rsi
movq (%r14), %rax
movb $0x3c, %bpl
movq %r14, %rdi
callq *0x10(%rax)
movq %rax, %r14
jmp 0x28272
movq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0xd652
leaq 0x10(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x222fc
movq %rax, %r14
movq (%r15), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2826f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8620
movb $0x3c, %bpl
testq %r14, %r14
je 0x2831d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ae90
movl %eax, 0xc(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x7, %esi
callq 0x2b9b4
leaq 0x9(%rsp), %rsi
movb $0x3b, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2ce2c
movb 0x2c(%r14), %al
leaq 0x9(%rsp), %rsi
movb %al, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2ce2c
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
leaq (%rsp,%r12), %rdx
addq $0xc, %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x282f5
movb (%rdx), %al
movb %al, (%rsi)
incq 0x18(%rsp)
jmp 0x282fd
movq %r15, %rdi
callq 0x2cf4a
incq %r12
cmpq $0x4, %r12
jne 0x282d6
movb 0x2d(%r14), %al
leaq 0x9(%rsp), %rsi
movb %al, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2ce2c
jmp 0x28339
leaq 0xc(%rsp), %rsi
movb %bpl, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0x9(%rsp), %rcx
movl $0x1, %edx
callq 0x2b970
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ada4
movl %eax, %r14d
movq (%r15), %rdi
testq %rdi, %rdi
je 0x28361
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x280f0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x8620
jmp 0x280f0
jmp 0x2841a
jmp 0x2841a
movq %rax, %r14
cmpl $0x3, %edx
jne 0x283b1
movq %r14, %rdi
callq 0x8210
movq %rax, %rdi
callq 0xb7d5
callq 0x8a50
movb $0x47, %bpl
jmp 0x283f2
cmpl $0x2, %edx
jne 0x283d1
movq %r14, %rdi
callq 0x8210
leaq 0x20(%rax), %rsi
movq %rax, %rdi
callq 0x2ad66
callq 0x8a50
jmp 0x283f2
cmpl $0x1, %edx
jne 0x28439
movq %r14, %rdi
callq 0x8210
leaq 0x20(%rax), %rsi
movq %rax, %rdi
callq 0x2ad66
callq 0x8a50
movb $0x48, %bpl
xorl %r14d, %r14d
jmp 0x28272
jmp 0x2841a
jmp 0x2841a
jmp 0x2841a
movq %rax, %r14
callq 0x8a50
jmp 0x28439
movq %rax, %rdi
callq 0xb8be
jmp 0x2841f
jmp 0x2841f
jmp 0x2841f
jmp 0x2841f
movq %rax, %r14
jmp 0x28439
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x28439
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28454
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x8620
movq %r14, %rdi
callq 0x8ab0