// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
cmpq $0x0, 0x188(%rsi)
je 0x2bb0e
movl $0x210, %edi            # imm = 0x210
callq 0x8600
movq %rax, %rbx
leaq 0x8(%r14), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1b692
movl $0x18, %edi
callq 0x8600
leaq 0x10(%r15), %rsi
movq %rbx, 0x10(%rax)
movq %rax, %rdi
callq 0x8060
incq 0x20(%r15)
movq (%r14), %rax
movq %r14, %rdi
callq *0x58(%rax)
rorq $0x20, %rax
movq %rax, 0x208(%rbx)
jmp 0x2bb10
xorl %ebx, %ebx
leaq 0x130(%r14), %r12
movq 0x130(%r14), %rbp
cmpq %r12, %rbp
je 0x2bbb0
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%r15), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rbp), %r13
cmpl $0x5, 0x14(%r13)
jne 0x2bba7
testq %rbx, %rbx
jne 0x2bb85
movl $0x210, %edi            # imm = 0x210
callq 0x8600
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1b692
movl $0x18, %edi
callq 0x8600
movq %rbx, 0x10(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x8060
incq 0x20(%r15)
movq %rbx, 0x8(%r13)
leaq 0x130(%rbx), %rdi
movq (%rbp), %r13
movq %rdi, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x2c09c
movq %r13, %rbp
jmp 0x2bbab
movq (%rbp), %rbp
cmpq %r12, %rbp
jne 0x2bb39
leaq 0x118(%r14), %r12
movq 0x118(%r14), %r13
cmpq %r12, %r13
je 0x2bc4c
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%r15), %rax
movq %rax, 0x8(%rsp)
cmpl $0x4, 0x24(%r13)
jne 0x2bc43
testq %rbx, %rbx
jne 0x2bc21
movl $0x210, %edi            # imm = 0x210
callq 0x8600
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1b692
movl $0x18, %edi
callq 0x8600
movq %rbx, 0x10(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x8060
incq 0x20(%r15)
movq %rbx, 0x10(%r13)
leaq 0x118(%rbx), %rdi
movq (%r13), %rbp
movq %rdi, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1fa24
movq %rbp, %r13
jmp 0x2bc47
movq (%r13), %r13
cmpq %r12, %r13
jne 0x2bbd9
movq %r14, %rdi
callq 0x22358
movq %r15, %rdi
movq %r14, %rsi
callq 0x1b726
movq (%r14), %rax
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x38(%rax)
jmp 0x2bc7e
jmp 0x2bc8c
jmp 0x2bc7e
jmp 0x2bc8c
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
jmp 0x2bc9c
movq %rax, %r14
movl $0x210, %esi            # imm = 0x210
movq %rbx, %rdi
callq 0x8620
movq %r14, %rdi
callq 0x8ab0