// File: davmac314[P]dinit/src/control.cc
// Function: control_conn_t::check_dependents(service_record*, bool&)
bool control_conn_t::check_dependents(service_record *service, bool &had_dependents)
{
    std::vector<char> reply_pkt;
    size_t num_depts = 0;

    for (service_dep *dep : service->get_dependents()) {
        if (dep->dep_type == dependency_type::REGULAR && dep->holding_acq) {
            num_depts++;
            // find or allocate a service handle
            handle_t dept_handle = allocate_service_handle(dep->get_from());
            if (reply_pkt.empty()) {
                // packet type, size
                reply_pkt.reserve(1 + sizeof(size_t) + sizeof(handle_t));
                reply_pkt.resize(1 + sizeof(size_t));
                reply_pkt[0] = (char)cp_rply::DEPENDENTS;
            }
            auto old_size = reply_pkt.size();
            reply_pkt.resize(old_size + sizeof(handle_t));
            memcpy(reply_pkt.data() + old_size, &dept_handle, sizeof(dept_handle));
        }
    }

    if (num_depts != 0) {
        // There are affected dependents
        had_dependents = true;
        memcpy(reply_pkt.data() + 1, &num_depts, sizeof(num_depts));
        return queue_packet(std::move(reply_pkt));
    }

    had_dependents = false;
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x30d60
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30220
movq %rax, -0x90(%rbp)
jmp 0x5c0b5
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x304d0
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdi
callq 0x30530
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x30500
testb $0x1, %al
jne 0x5c0f0
jmp 0x5c1f8
leaq -0x60(%rbp), %rdi
callq 0x30590
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x5c1e8
movq -0x70(%rbp), %rax
testb $0x1, 0x11(%rax)
je 0x5c1e8
movq -0x40(%rbp), %rax
incq %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rdi
callq 0x30420
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x5be40
movl %eax, -0x9c(%rbp)
jmp 0x5c147
movl -0x9c(%rbp), %eax
movl %eax, -0x74(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5e910
testb $0x1, %al
jne 0x5c15f
jmp 0x5c1ab
leaq -0x38(%rbp), %rdi
movl $0xd, %esi
callq 0x5e520
jmp 0x5c16f
leaq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x31490
jmp 0x5c17f
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5e950
movb $0x41, (%rax)
jmp 0x5c1ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x13f20
jmp 0x5c264
leaq -0x38(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x31650
movq -0xa8(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
addq $0x4, %rsi
callq 0x31490
jmp 0x5c1d5
leaq -0x38(%rbp), %rdi
callq 0x31180
movq -0x80(%rbp), %rcx
movl -0x74(%rbp), %edx
movl %edx, (%rax,%rcx)
jmp 0x5c1ea
leaq -0x60(%rbp), %rdi
callq 0x306a0
jmp 0x5c0da
cmpq $0x0, -0x40(%rbp)
je 0x5c238
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
leaq -0x38(%rbp), %rdi
callq 0x31180
movq -0x98(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq %rcx, 0x1(%rax)
leaq -0x38(%rbp), %rsi
callq 0x5bc70
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x5c24d
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x13f20
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xacc0
nopl (%rax)