// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::rm_service_dep()
bool control_conn_t::rm_service_dep()
{
    // 1 byte packet type
    // 1 byte dependency type
    // handle: "from"
    // handle: "to"

    constexpr int pkt_size = 2 + sizeof(handle_t) * 2;

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t from_handle;
    handle_t to_handle;
    rbuf.extract((char *) &from_handle, 2, sizeof(from_handle));
    rbuf.extract((char *) &to_handle, 2 + sizeof(from_handle), sizeof(to_handle));

    service_record *from_service = find_service_for_key(from_handle);
    service_record *to_service = find_service_for_key(to_handle);
    if (from_service == nullptr || to_service == nullptr || from_service == to_service) {
        // Service handle is bad
        char badreq_rep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreq_rep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    // Check dependency type is valid:
    int dep_type_int = rbuf[1];
    if (! contains({dependency_type::MILESTONE, dependency_type::REGULAR,
            dependency_type::WAITS_FOR}, dep_type_int)) {
        char badreqRep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreqRep, 1)) return false;
        bad_conn_close = true;
    }
    dependency_type dep_type = static_cast<dependency_type>(dep_type_int);

    // Remove dependency:
    bool did_remove = from_service->rm_dep(to_service, dep_type);
    services->process_queues();

    char ack_rep[] = { did_remove ? (char)cp_rply::ACK : (char)cp_rply::NAK };
    if (! queue_packet(ack_rep, 1)) return false;
    rbuf.consume(pkt_size);
    chklen = 0;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x9, 0x484(%rdi)
ja 0x29aa4
movl $0xa, 0x7c(%rbx)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r15d
leal 0x2(%r15), %eax
leal -0x3fe(%r15), %r12d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r12d
leal -0x3fd(%r12), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x29b0d
movl $0x400, %r13d           # imm = 0x400
subl %r12d, %r13d
movl %r12d, %esi
addq %r14, %rsi
leaq 0xc(%rsp), %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0xc, %rdi
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq %r14, %rsi
movq %r12, %rdx
callq 0x84d0
jmp 0x29b18
movl %r12d, %eax
movl (%r14,%rax), %eax
movl %eax, 0xc(%rsp)
leal 0x6(%r15), %eax
addl $0xfffffc06, %r15d      # imm = 0xFFFFFC06
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x29b75
movl $0x400, %r13d           # imm = 0x400
subl %r15d, %r13d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x14(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0x14, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x29b7e
movl %r15d, %eax
addq %rax, %r14
movq %r14, %r12
movl (%r12), %ebp
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x2b906
movq %rax, %r14
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2b906
cmpq %rax, %r14
je 0x29c0f
testq %r14, %r14
je 0x29c0f
movq %rax, %r15
testq %rax, %rax
je 0x29c0f
movl 0x480(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movzbl 0x80(%rbx,%rax), %ebp
cmpl $0x3, %ebp
ja 0x29c8f
cmpl $0x1, %ebp
je 0x29c8f
movsbl %bpl, %eax
movq %r14, %rcx
addq $0x118, %rcx            # imm = 0x118
movq %rcx, %rsi
movq (%rsi), %rsi
cmpq %rcx, %rsi
je 0x29c35
cmpq %r15, 0x18(%rsi)
jne 0x29bef
cmpl %eax, 0x24(%rsi)
jne 0x29bef
movq %r14, %rdi
callq 0x1f674
movb $0x32, %bpl
jmp 0x29c38
leaq 0x13(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x29a95
movb $0x1, 0x78(%rbx)
jmp 0x29a95
movb $0x33, %bpl
movq 0x70(%rbx), %rdi
callq 0xd37e
leaq 0x11(%rsp), %rsi
movb %bpl, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x29a95
movl 0x480(%rbx), %ecx
leal 0xa(%rcx), %edx
addl $0xfffffc0a, %ecx       # imm = 0xFFFFFC0A
cmpl $0x400, %edx            # imm = 0x400
cmovbl %edx, %ecx
movl %ecx, 0x480(%rbx)
addl $-0xa, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
jmp 0x29a95
leaq 0x12(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x29cb1
movb $0x1, 0x78(%rbx)
jmp 0x29bde
xorl %eax, %eax
jmp 0x29a95