// File: 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 namespace std;

    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." << endl;
        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." << endl;
            return 1;
        }
        if (rbuffer[0] != (char)cp_rply::ACK) {
            cerr << "dinitctl: protocol error." << endl;
            return 1;
        }
        rbuffer.consume(1);
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %cl, %al
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl -0x8(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0xccc0
cmpl $0x1, %eax
jne 0x987c
movl $0x1, -0x4(%rbp)
jmp 0x9a10
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x11350
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x3c, %eax
jne 0x98c9
movq 0x28746(%rip), %rdi     # 0x31fe8
leaq 0x1ad08(%rip), %rsi     # 0x245b1
callq 0x53d0
movq %rax, %rdi
movq 0x286b0(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0x9a10
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %r8d
callq 0xcd90
cmpl $0x0, %eax
je 0x98f4
movl $0x1, -0x4(%rbp)
jmp 0x9a10
movb $0x9, -0x28(%rbp)
leaq -0x27(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x11b60
movb %al, -0x26(%rbp)
leaq -0x26(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x131e0
movl %eax, %ecx
movl %ecx, -0x25(%rbp)
shrq $0x20, %rax
movb %al, -0x21(%rbp)
movl -0x8(%rbp), %edi
leaq -0x25(%rbp), %rsi
callq 0x13220
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x11350
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x33, %eax
jne 0x997a
movq 0x28695(%rip), %rdi     # 0x31fe8
leaq 0x1ac75(%rip), %rsi     # 0x245cf
callq 0x53d0
movq %rax, %rdi
movq 0x285ff(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0x9a10
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x32, %eax
je 0x99b8
movq 0x28654(%rip), %rdi     # 0x31fe8
leaq 0x1a7aa(%rip), %rsi     # 0x24145
callq 0x53d0
movq %rax, %rdi
movq 0x285be(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0x9a10
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
testb $0x1, -0x19(%rbp)
je 0x9a09
movq 0x285c5(%rip), %rdi     # 0x31f98
leaq 0x1a68b(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x1ac38(%rip), %rsi     # 0x2462d
callq 0x53d0
movq %rax, %rdi
movq 0x28564(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)