// File: /workspace/github_cpp_makefile_star2_O1/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 0xd59c
movq %r15, %rdi
movl %r12d, %esi
callq 0xedbd
movl 0x400(%r15), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x3c, (%r15,%rcx)
jne 0x9b96
movq 0x13465(%rip), %rdi     # 0x1cfe8
leaq 0xca57(%rip), %rsi      # 0x165e1
movl $0x1e, %edx
callq 0x4330
jmp 0x9bb4
xorl %ebp, %ebp
leaq 0x4(%rsp), %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd69a
testl %eax, %eax
je 0x9bc5
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, (%rsp)
movq %r14, 0x8(%rsp)
movl 0x4(%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 0x9c12
addl %eax, %ebp
movslq %eax, %rcx
addq %rcx, %r13
subl %eax, %ebx
xorl %ecx, %ecx
jmp 0x9c32
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0x9c32
testl %ebp, %ebp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmovgl %ebp, %r14d
movl $0x1, %ecx
testb $0x1, %cl
jne 0x9c3d
testl %ebx, %ebx
jg 0x9bf2
jmp 0x9c40
movl %r14d, %ebp
cmpl $-0x1, %ebp
movl (%rsp), %ebp
je 0x9d44
movq %r15, %rdi
movl %r12d, %esi
callq 0xedbd
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
movq 0x8(%rsp), %r14
je 0x9c9d
movq 0x13361(%rip), %rdi     # 0x1cfe8
cmpl $0x33, %ecx
jne 0x9d03
leaq 0xc96d(%rip), %rsi      # 0x16600
movl $0x5e, %edx
jmp 0x9b8f
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 %bpl, %bpl
je 0x9bb4
movq 0x132da(%rip), %r15     # 0x1cfa8
leaq 0xc3bd(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %r15, %rdi
callq 0x4330
testq %r14, %r14
je 0x9d14
movq %r14, %rdi
callq 0x4150
movq 0x132b2(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0x9d2c
leaq 0xc468(%rip), %rsi      # 0x16172
movl $0x1a, %edx
jmp 0x9b8f
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x13275(%rip), %rdi     # 0x1cfa8
leaq 0xc925(%rip), %rsi      # 0x1665f
movl $0xc, %edx
jmp 0x9b8f
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x12def(%rip), %rsi     # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0