// File: /workspace/github_cpp_makefile_star2_O1/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 0x29b94
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
addl $0xfffffc02, %r15d      # imm = 0xFFFFFC02
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x29bfd
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x29c08
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x480(%rbx), %r15d
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 0x29c6a
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x4(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x29c75
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x4(%rsp)
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0x2ba66
movq %rax, %r14
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0x2ba66
cmpq %rax, %r14
je 0x29ce5
testq %r14, %r14
je 0x29ce5
movq %rax, %r15
testq %rax, %rax
je 0x29ce5
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
leaq 0x18(%rsp), %rax
movq $0x3, -0xc(%rax)
movl $0x2, -0x4(%rax)
testl %ebp, %ebp
je 0x29d0b
cmpl $0x3, %ebp
jne 0x29d12
leaq 0xc(%rsp), %rcx
jmp 0x29d1f
leaq 0xc(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x29b85
movb $0x1, 0x78(%rbx)
jmp 0x29b85
leaq 0x10(%rsp), %rcx
jmp 0x29d1f
leaq 0x14(%rsp), %rcx
cmpb $0x2, %bpl
cmovneq %rax, %rcx
cmpq %rax, %rcx
jne 0x29d45
leaq 0xc(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x29dd0
movb $0x1, 0x78(%rbx)
movsbl %bpl, %eax
movq %r14, %rcx
addq $0x118, %rcx            # imm = 0x118
movq %rcx, %rsi
movq (%rsi), %rsi
cmpq %rcx, %rsi
je 0x29d76
cmpq %r15, 0x18(%rsi)
jne 0x29d56
cmpl %eax, 0x24(%rsi)
jne 0x29d56
movq %r14, %rdi
callq 0x1f6ae
movb $0x32, %bpl
jmp 0x29d79
movb $0x33, %bpl
movq 0x70(%rbx), %rdi
callq 0xd8da
leaq 0xc(%rsp), %rsi
movb %bpl, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x29b85
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 0x29b85
xorl %eax, %eax
jmp 0x29b85
nop