// File: davmac314[P]dinit/src/service.cc
// Function: service_record::unpin()
void service_record::unpin() noexcept
{
    if (pinned_started) {
        pinned_started = false;

        if (dept_pinned_started) return;

        // unpin dependencies
        for (auto &dep : depends_on) {
            if (dep.is_hard() && dep.get_to()->dept_pinned_started) {
                dep.get_to()->prop_pin_dpt = true;
                services->add_prop_queue(dep.get_to());
            }
        }

        // We only need special handling here if service was in STARTED state
        if (service_state == service_state_t::STARTED) {
            // If any dependents are stopping, then force_stop should already be set.

            // If we reached required_by 0, we need to propagate release now (since it wasn't
            // propagated as it normally would be when we hit 0, due to the pin)
            if (required_by == 0) {
                prop_release = true;
                services->add_prop_queue(this);
            }

            if (desired_state == service_state_t::STOPPED || force_stop) {
                do_stop();
                services->process_queues();
            }
        }
    }
    if (pinned_stopped) {
        pinned_stopped = false;
        // We don't need to check state. If we're pinned stopped we can't be required and so desired
        // state should always be stopped.
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl 0x10c(%rax), %eax
shrl $0x2, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4dec2
movq -0x30(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $-0x5, %ecx
orl $0x0, %ecx
movl %ecx, 0x10c(%rax)
movl 0x10c(%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4dd79
jmp 0x4deee
movq -0x30(%rbp), %rax
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 0x4ddb7
jmp 0x4de4f
leaq -0x18(%rbp), %rdi
callq 0x302d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4e1f0
movb %al, -0x31(%rbp)
jmp 0x4ddd2
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x4dddb
jmp 0x4de3f
movq -0x28(%rbp), %rdi
callq 0x3cda0
movl 0x10c(%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4de3f
movq -0x28(%rbp), %rdi
callq 0x3cda0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movl 0x10c(%rcx), %edx
andl $0xffffbfff, %edx       # imm = 0xFFFFBFFF
orl $0x4000, %edx           # imm = 0x4000
movl %edx, 0x10c(%rcx)
movq 0x148(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3cda0
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x4e320
jmp 0x4de41
leaq -0x18(%rbp), %rdi
callq 0x30330
jmp 0x4dda1
movq -0x30(%rbp), %rax
cmpb $0x2, 0x2c(%rax)
jne 0x4dec0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x110(%rax)
jne 0x4de8c
movq -0x30(%rbp), %rsi
movl 0x10c(%rsi), %eax
andl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x10c(%rsi)
movq 0x148(%rsi), %rdi
callq 0x4e320
movq -0x30(%rbp), %rax
cmpb $0x0, 0x2d(%rax)
je 0x4dea3
movq -0x30(%rbp), %rax
testb $0x1, 0x190(%rax)
je 0x4debe
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x4c440
movq -0x30(%rbp), %rax
movq 0x148(%rax), %rdi
callq 0x173c0
jmp 0x4dec0
jmp 0x4dec2
movq -0x30(%rbp), %rax
movl 0x10c(%rax), %eax
shrl %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4deee
movq -0x30(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $-0x3, %ecx
orl $0x0, %ecx
movl %ecx, 0x10c(%rax)
addq $0x40, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopl (%rax)