// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_reload_service()
bool control_conn_t::process_reload_service()
{
    using std::string;

    constexpr int pkt_size = 1 + sizeof(handle_t);

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

    // 1 byte: packet type
    // 4 bytes: service handle

    handle_t handle;
    rbuf.extract((char *) &handle, 1, sizeof(handle));

    service_record *service = find_service_for_key(handle);
    if (service == nullptr) {
        // Service handle is bad
        char badreq_rep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreq_rep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    if (!service->has_lone_ref(false)) {
        // Cannot unload: has other references
        char nak_rep[] = { (char)cp_rply::NAK };
        if (! queue_packet(nak_rep, 1)) return false;
    }
    else {
        try {
            // drop handle
            key_service_map.erase(handle);
            service_key_map.erase(service);

            // reload
            service->remove_listener(this);
            services->reload_service(service);
            services->process_queues();

            // send ack
            char ack_buf[] = { (char) cp_rply::ACK };
            if (! queue_packet(ack_buf, 1)) return false;
        }
        catch (service_load_exc &slexc) {
            log(loglevel_t::ERROR, "Could not reload service ", slexc.service_name, ": ",
                    slexc.exc_description);
            char nak_rep[] = { (char)cp_rply::NAK };
            if (! queue_packet(nak_rep, 1)) return false;
        }
    }

    // Clear the packet from the buffer
    rbuf.consume(pkt_size);
    chklen = 0;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x23e76
movl $0x5, 0x7c(%rbx)
jmp 0x23f49
leaq 0x80(%rbx), %r14
leaq 0x1c(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x23ebf
movq 0x160(%rax), %rax
cmpq $0x0, (%rax)
je 0x23edc
leaq 0xf(%rsp), %rsi
movb $0x33, (%rsi)
jmp 0x23f2b
leaq 0xf(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x23f4b
movb $0x1, 0x78(%rbx)
jmp 0x23f4b
leaq 0x4c0(%rbx), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x27968
leaq 0x488(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x27894
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x26036
movq 0x70(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x70(%rbx), %rdi
callq 0xcdd2
leaq 0xf(%rsp), %rsi
movb $0x32, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x23fa5
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
cmpl $0x1, %edx
jne 0x23fa9
callq 0x8200
movq %rax, %r15
leaq 0x20(%rax), %r12
leaq 0xc4df(%rip), %rsi      # 0x30452
pushq $0x3
popq %rdi
callq 0x28e0a
movq %r15, %rdi
movq %r12, %rsi
callq 0x25dd7
leaq 0xf(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebp
callq 0x8a40
testb %bpl, %bpl
jne 0x23f3a
xorl %eax, %eax
jmp 0x23f4b
callq 0x8a90