// File: davmac314[P]dinit/src/service.cc
// Function: service_record::prepare_for_unload()
void service_record::prepare_for_unload() noexcept
{
    // Remove all dependencies:
    for (auto &dep : depends_on) {
        service_record *dependency = dep.get_to();
        auto &dep_dpts = dependency->dependents;
        dep_dpts.erase(std::find(dep_dpts.begin(), dep_dpts.end(), &dep));
        if (dep.dep_type == dependency_type::AFTER) {
            if (dependency->get_type() == service_type_t::PLACEHOLDER) {
                if (dependency->is_unrefd()) {
                    services->remove_service(dependency);
                    delete dependency;
                }
            }
        }
    }
    depends_on.clear();

    // Also remove all dependents. This should not be necessary except for "before" links.
    for (auto i = dependents.begin(); i != dependents.end();) {
        service_record *before_svc = (*i)->get_from();
        before_svc->rm_dep(**i++);
        if (before_svc->get_type() == service_type_t::PLACEHOLDER && before_svc->is_unrefd()) {
            services->remove_service(before_svc);
            delete before_svc;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30240
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30270
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x302a0
testb $0x1, %al
jne 0x4b904
jmp 0x4ba0d
leaq -0x18(%rbp), %rdi
callq 0x302d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3cda0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x130, %rax            # imm = 0x130
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x304d0
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
callq 0x30530
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x4e140
movq %rax, -0x98(%rbp)
jmp 0x4b96f
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x30680
movq -0xa0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x43c00
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x5, 0x14(%rax)
jne 0x4b9fd
movq -0x30(%rbp), %rdi
callq 0x2d5a0
cmpl $0x0, %eax
jne 0x4b9fb
movq -0x30(%rbp), %rdi
callq 0x2f430
testb $0x1, %al
jne 0x4b9c2
jmp 0x4b9f9
movq -0x90(%rbp), %rax
movq 0x148(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x2f4a0
movq -0x30(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
je 0x4b9f7
movq -0xa8(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
jmp 0x4b9f9
jmp 0x4b9fb
jmp 0x4b9fd
jmp 0x4b9ff
leaq -0x18(%rbp), %rdi
callq 0x30330
jmp 0x4b8ee
movq -0x90(%rbp), %rdi
addq $0x118, %rdi            # imm = 0x118
callq 0x4e190
movq -0x90(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x304d0
movq %rax, -0x70(%rbp)
movq -0x90(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x30530
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x30500
testb $0x1, %al
jne 0x4ba64
jmp 0x4bb0a
leaq -0x70(%rbp), %rdi
callq 0x30590
movq (%rax), %rdi
callq 0x30420
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x4e1c0
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x30590
movq -0xb0(%rbp), %rdi
movq (%rax), %rsi
callq 0x305b0
movq -0x80(%rbp), %rdi
callq 0x2d5a0
cmpl $0x0, %eax
jne 0x4bb05
movq -0x80(%rbp), %rdi
callq 0x2f430
testb $0x1, %al
jne 0x4bace
jmp 0x4bb05
movq -0x90(%rbp), %rax
movq 0x148(%rax), %rdi
movq -0x80(%rbp), %rsi
callq 0x2f4a0
movq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, %rax
je 0x4bb03
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
jmp 0x4bb05
jmp 0x4ba37
addq $0xc0, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopl (%rax,%rax)