// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/dinitctl.cc
// Function: unload_service(int, cpbuffer<1024u>&, char const*, bool)
static int unload_service(int socknum, cpbuffer_t &rbuffer, const char *service_name, bool verbose)
{
    using std::cout;
    using std::cerr;

    if (issue_load_service(socknum, service_name, true) == 1) {
        return 1;
    }

    wait_for_reply(rbuffer, socknum);

    handle_t handle;

    if (rbuffer[0] == (char)cp_rply::NOSERVICE) {
        cerr << "dinitctl: service not loaded.\n";
        return 1;
    }

    if (check_load_reply(socknum, rbuffer, &handle, nullptr) != 0) {
        return 1;
    }

    // Issue UNLOAD command.
    {
        auto m = membuf()
                .append((char)cp_cmd::UNLOADSERVICE)
                .append(handle);
        write_all_x(socknum, m);

        wait_for_reply(rbuffer, socknum);
        if (rbuffer[0] == (char)cp_rply::NAK) {
            cerr << "dinitctl: could not unload service; service not stopped, or is a dependency of "
                    "other service.\n";
            return 1;
        }
        if (rbuffer[0] != (char)cp_rply::ACK) {
            cerr << "dinitctl: protocol error.\n";
            return 1;
        }
        rbuffer.consume(1);
    }

    if (verbose) {
        cout << "Service '" << service_name << "' unloaded.\n";
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r13d
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %r12d
movl $0x1, %ebx
movq %rdx, %rsi
movl $0x1, %edx
callq 0xd67c
movq %r15, %rdi
movl %r12d, %esi
callq 0xed47
movl 0x400(%r15), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x3c, (%r15,%rcx)
jne 0x9dce
movq 0x1322d(%rip), %rdi     # 0x1cfe8
leaq 0xc80a(%rip), %rsi      # 0x165cc
movl $0x1e, %edx
callq 0x4330
jmp 0x9dec
xorl %ebp, %ebp
leaq 0xc(%rsp), %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd75c
testl %eax, %eax
je 0x9dfd
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, 0x8(%rsp)
movl 0xc(%rsp), %eax
movq %rax, %rcx
shlq $0x8, %rcx
orq $0x9, %rcx
shrl $0x18, %eax
leaq 0x10(%rsp), %r13
movb %al, 0x4(%r13)
movl %ecx, (%r13)
movl $0x5, %ebx
movl %ebx, %edx
movl %r12d, %edi
movq %r13, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0x9e44
addl %eax, %ebp
movslq %eax, %rcx
addq %rcx, %r13
subl %eax, %ebx
jmp 0x9e52
callq 0x4040
cmpl $0x4, (%rax)
jne 0x9f25
testl %ebx, %ebx
jg 0x9e26
cmpl $-0x1, %ebp
je 0x9f2d
movq %r15, %rdi
movl %r12d, %esi
callq 0xed47
movl 0x400(%r15), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movzbl (%r15,%rcx), %ecx
cmpl $0x32, %ecx
movl $0x1, %ebx
movl 0x8(%rsp), %edx
je 0x9eaf
movq 0x1314f(%rip), %rdi     # 0x1cfe8
cmpl $0x33, %ecx
jne 0x9f14
leaq 0xc746(%rip), %rsi      # 0x165eb
movl $0x5e, %edx
jmp 0x9dc7
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r15)
decl 0x404(%r15)
xorl %ebx, %ebx
testb %dl, %dl
je 0x9dec
movq 0x130c9(%rip), %r15     # 0x1cfa8
leaq 0xc197(%rip), %rsi      # 0x1607d
movl $0x9, %edx
movq %r15, %rdi
callq 0x4330
testq %r14, %r14
je 0x9f54
movq %r14, %rdi
callq 0x4150
movq 0x130a1(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0x9f6c
leaq 0xc242(%rip), %rsi      # 0x1615d
movl $0x1a, %edx
jmp 0x9dc7
testl %ebp, %ebp
jg 0x9e5f
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x12c06(%rip), %rsi     # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x13035(%rip), %rdi     # 0x1cfa8
leaq 0xc6d0(%rip), %rsi      # 0x1664a
movl $0xc, %edx
jmp 0x9dc7