// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_close_handle()
bool control_conn_t::process_close_handle()
{
    constexpr int pkt_size = 1 + sizeof(handle_t);

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

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

    rbuf.consume(pkt_size);
    chklen = 0;

    auto key_it = key_service_map.find(handle);
    if (key_it == key_service_map.end()) {
        // 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;
    }

    service_record *service = key_it->second;
    key_service_map.erase(key_it);

    bool have_other_handle = false;
    auto handle_range = service_key_map.equal_range(service);
    auto it = handle_range.first;
    while (it->second != handle) {
        have_other_handle = true;
        ++it;
    }
    if (!have_other_handle) {
        // check if more handles beyond the found handle
        have_other_handle = std::next(it) != handle_range.second;
    }
    service_key_map.erase(it);

    if (!have_other_handle) {
        service->remove_listener(this);
    }

    char ack_reply[] = { (char)cp_rply::ACK };
    return queue_packet(ack_reply, sizeof(ack_reply));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x28484
movl $0x5, 0x7c(%rbx)
movb $0x1, %al
jmp 0x28615
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 0x284ed
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x8(%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 0x284f8
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x8(%rsp)
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)
movq 0x4d0(%rbx), %rdx
leaq 0x4c8(%rbx), %rax
movq %rax, %rcx
testq %rdx, %rdx
je 0x28557
movl 0x8(%rsp), %esi
movq %rax, %rcx
xorl %edi, %edi
cmpl %esi, 0x20(%rdx)
setb %dil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rdi,8), %rdx
testq %rdx, %rdx
jne 0x28540
movq %rax, %rsi
cmpq %rax, %rcx
je 0x2856d
movl 0x8(%rsp), %edx
cmpl 0x20(%rcx), %edx
cmovbq %rax, %rcx
movq %rcx, %rsi
cmpq %rax, %rsi
je 0x285f8
leaq 0x4c0(%rbx), %rdi
movq 0x28(%rsi), %rax
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
callq 0x2d03c
leaq 0x488(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d078
movl 0x8(%rsp), %ecx
cmpl %ecx, 0x10(%rax)
jne 0x285ad
xorl %ebp, %ebp
jmp 0x285b8
movq (%rax), %rax
cmpl %ecx, 0x10(%rax)
jne 0x285ad
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x285c4
cmpq %rdx, (%rax)
setne %bpl
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d10a
testb %bpl, %bpl
jne 0x285e1
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x2ba46
leaq 0xe(%rsp), %rsi
movb $0x32, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
jmp 0x28615
leaq 0xf(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x28615
movb $0x1, 0x78(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq