// File: davmac314[P]dinit/src/dinitctl.cc
// Function: reload_service(int, cpbuffer<1024u>&, char const*, bool)
static int reload_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) {
        rbuffer.consume(1);
        // If the service isn't loaded yet at all, just do a basic load:
        if (issue_load_service(socknum, service_name, false) == 1) {
            return 1;
        }

        wait_for_reply(rbuffer, socknum);

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

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

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

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

        wait_for_reply(rbuffer, socknum);
        if (rbuffer[0] == (char)cp_rply::NAK) {
            cerr << "dinitctl: could not reload service; service in wrong state, incompatible change, "
                    "or bad service description." << 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 << "' reloaded." << 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 0x9a5c
movl $0x1, -0x4(%rbp)
jmp 0x9c79
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 0x9b32
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
movl -0x8(%rbp), %edi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0xccc0
cmpl $0x1, %eax
jne 0x9aac
movl $0x1, -0x4(%rbp)
jmp 0x9c79
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x11350
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 0x9ae3
movl $0x1, -0x4(%rbp)
jmp 0x9c79
testb $0x1, -0x19(%rbp)
je 0x9b26
movq 0x284a8(%rip), %rdi     # 0x31f98
leaq 0x1a56e(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x1ab27(%rip), %rsi     # 0x24639
callq 0x53d0
movq %rax, %rdi
movq 0x28447(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x0, -0x4(%rbp)
jmp 0x9c79
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 0x9b5d
movl $0x1, -0x4(%rbp)
jmp 0x9c79
movb $0x10, -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 0x9be3
movq 0x2842c(%rip), %rdi     # 0x31fe8
leaq 0x1aa82(%rip), %rsi     # 0x24645
callq 0x53d0
movq %rax, %rdi
movq 0x28396(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0x9c79
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movsbl %al, %eax
cmpl $0x32, %eax
je 0x9c21
movq 0x283eb(%rip), %rdi     # 0x31fe8
leaq 0x1a541(%rip), %rsi     # 0x24145
callq 0x53d0
movq %rax, %rdi
movq 0x28355(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0x9c79
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
testb $0x1, -0x19(%rbp)
je 0x9c72
movq 0x2835c(%rip), %rdi     # 0x31f98
leaq 0x1a422(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x1a9db(%rip), %rsi     # 0x24639
callq 0x53d0
movq %rax, %rdi
movq 0x282fb(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)