// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/includes/service.h
// Function: service_set::unload_service(service_record*)
void unload_service(service_record *svc)
    {
        // Check if there are any "after" dependents, or any "before" dependencies. We need a placeholder
        // if so. Note that the placeholder is created before making any destructive changes, so if we fail
        // to create it no rollback is needed.
        placeholder_service *placeholder = nullptr;
        auto make_placeholder = [&]() {
            if (placeholder == nullptr) {
                std::unique_ptr<placeholder_service> ph { new placeholder_service(this, svc->get_name()) };
                add_service(ph.get());
                placeholder = ph.release();
            }
        };

        auto *consumer = svc->get_log_consumer();
        if (consumer != nullptr) {
            make_placeholder();
            placeholder->set_output_pipe(svc->transfer_output_pipe());
        }

        auto &svc_depts = svc->get_dependents();
        for (auto i = svc_depts.begin(); i != svc_depts.end(); ) {
            auto *dept = *i;
            if (dept->dep_type == dependency_type::AFTER) {
                make_placeholder();
                dept->set_to(placeholder);
                auto &ph_depts = placeholder->get_dependents();
                ph_depts.splice(ph_depts.end(), svc_depts, i++);
                continue;
            }
            ++i;
        }

        auto &svc_deps = svc->get_dependencies();
        for (auto i = svc_deps.begin(); i != svc_deps.end(); ) {
            auto &dep = *i;
            if (dep.dep_type == dependency_type::BEFORE) {
                make_placeholder();
                dep.set_from(placeholder);
                auto &ph_deps = placeholder->get_dependencies();
                ph_deps.splice(ph_deps.end(), svc_deps, i++);
                continue;
            }
            ++i;
        }

        // Proceed with unload.
        svc->prepare_for_unload();
        remove_service(svc);
        delete svc;
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rsp), %rax
movq %rsi, (%rax)
leaq 0x10(%rsp), %rcx
andq $0x0, (%rcx)
movq %rcx, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x188(%rsi)
je 0x26149
leaq 0x18(%rsp), %rdi
callq 0x26706
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x58(%rax)
rorq $0x20, %rax
movq %rax, 0x208(%r14)
movq 0x8(%rsp), %r14
movq 0x130(%r14), %r12
addq $0x130, %r14            # imm = 0x130
leaq 0x18(%rsp), %r15
cmpq %r14, %r12
je 0x261a2
movq 0x10(%r12), %r13
cmpl $0x5, 0x14(%r13)
jne 0x2619c
movq %r15, %rdi
callq 0x26706
movq 0x10(%rsp), %rdi
movq %rdi, 0x8(%r13)
addq $0x130, %rdi            # imm = 0x130
movq (%r12), %r13
movq %rdi, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x2677c
movq %r13, %r12
jmp 0x2615c
movq (%r12), %r12
jmp 0x2615c
movq 0x8(%rsp), %r14
movq 0x118(%r14), %r12
addq $0x118, %r14            # imm = 0x118
leaq 0x18(%rsp), %r15
cmpq %r14, %r12
je 0x261fd
cmpl $0x4, 0x24(%r12)
jne 0x261f7
movq %r15, %rdi
callq 0x26706
movq 0x10(%rsp), %rdi
movq %rdi, 0x10(%r12)
addq $0x118, %rdi            # imm = 0x118
movq (%r12), %r13
movq %rdi, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x1bbec
movq %r13, %r12
jmp 0x261ba
movq (%r12), %r12
jmp 0x261ba
movq 0x8(%rsp), %rdi
callq 0x1e204
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x17032
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x26224
movq (%rdi), %rax
callq *0x38(%rax)
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq