// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_unload_service()
bool control_conn_t::process_unload_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() || service->get_state() != service_state_t::STOPPED) {
        // Cannot unload: has other references
        char nak_rep[] = { (char)cp_rply::NAK };
        if (!queue_packet(nak_rep, 1)) return false;
    }
    else {
        // unload (this may fail with bad_alloc)
        services->unload_service(service);

        // drop handle
        service_key_map.erase(service);
        key_service_map.erase(handle);

        // send ack
        char ack_buf[] = { (char) cp_rply::ACK };
        if (!queue_packet(ack_buf, 1)) return false;
    }

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

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x28b81
movl $0x5, 0x7c(%rbx)
jmp 0x28ca3
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r15d
leal 0x1(%r15), %eax
addl $0xfffffc01, %r15d      # imm = 0xFFFFFC01
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x28be8
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
movq %rsp, %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x28bf2
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, (%rsp)
movl (%rsp), %esi
movq %rbx, %rdi
callq 0x2ba66
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x28c2d
movq %rax, %rcx
addq $0x130, %rcx            # imm = 0x130
movq %rcx, %rdx
movq (%rdx), %rdx
cmpq %rcx, %rdx
je 0x28c4c
movq 0x10(%rdx), %rsi
movl 0x14(%rsi), %esi
andl $-0x2, %esi
cmpl $0x4, %esi
je 0x28c14
jmp 0x28c5f
leaq 0x7(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x28ca5
movb $0x1, 0x78(%rbx)
jmp 0x28ca5
movq 0x160(%rax), %rcx
cmpq $0x0, (%rcx)
jne 0x28c5f
cmpb $0x0, 0x2c(%rax)
je 0x28cb7
leaq 0x6(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x28cb3
movl 0x480(%rbx), %eax
leal 0x5(%rax), %ecx
addl $0xfffffc05, %eax       # imm = 0xFFFFFC05
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x480(%rbx)
addl $-0x5, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %eax, %eax
jmp 0x28ca5
movq 0x70(%rbx), %rdi
movq %rax, %rsi
callq 0x2baa0
leaq 0x488(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2d1ca
leaq 0x4c0(%rbx), %r14
movq %rsp, %rsi
movq %r14, %rdi
callq 0x2d2ae
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d326
leaq 0x5(%rsp), %rsi
movb $0x32, (%rsi)
jmp 0x28c67