// File: /workspace/github_cpp_makefile_star2_O1/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 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) {
        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.\n";
        }
        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.\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 << "' reloaded.\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 0x9e64
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r15)
decl 0x404(%r15)
movl %r12d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0xd59c
movq %r15, %rdi
movl %r12d, %esi
callq 0xedbd
movq %rsp, %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd69a
movl %eax, %ebx
testl %eax, %eax
sete %al
andb %r13b, %al
cmpb $0x1, %al
jne 0xa034
movq 0x13180(%rip), %rbx     # 0x1cfa8
leaq 0xc263(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
testq %r14, %r14
je 0x9efe
movq %r14, %rdi
callq 0x4150
movq 0x13154(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0x9f15
xorl %ebp, %ebp
movq %rsp, %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd69a
testl %eax, %eax
jne 0xa034
movl %r13d, 0x4(%rsp)
movq %r14, 0x8(%rsp)
movl (%rsp), %eax
movq %rax, %rcx
shlq $0x8, %rcx
orq $0x10, %rcx
shrl $0x18, %eax
leaq 0x10(%rsp), %r13
movb %al, 0x4(%r13)
movl %ecx, (%r13)
movl $0x5, %r14d
movl %r14d, %edx
movl %r12d, %edi
movq %r13, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0x9ed4
addl %eax, %ebp
movslq %eax, %rcx
addq %rcx, %r13
subl %eax, %r14d
xorl %ecx, %ecx
jmp 0x9ef2
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0x9ef2
testl %ebp, %ebp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmovgl %ebp, %ebx
movl $0x1, %ecx
testb $0x1, %cl
jne 0x9f34
testl %r14d, %r14d
jg 0x9eb2
jmp 0x9f36
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x1308c(%rip), %rdi     # 0x1cfa8
leaq 0xc749(%rip), %rsi      # 0x1666c
movl $0xc, %edx
callq 0x4330
xorl %ebx, %ebx
jmp 0xa034
movl %ebx, %ebp
cmpl $-0x1, %ebp
movl 0x4(%rsp), %ebp
je 0xa045
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 0x9f94
movq 0x1306a(%rip), %rdi     # 0x1cfe8
cmpl $0x33, %ecx
jne 0x9ff6
leaq 0xc6ef(%rip), %rsi      # 0x16679
movl $0x6d, %edx
jmp 0xa02f
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 0xa034
movq 0x12fe7(%rip), %r15     # 0x1cfa8
leaq 0xc0ca(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %r15, %rdi
callq 0x4330
testq %r14, %r14
je 0xa004
movq %r14, %rdi
callq 0x4150
movq 0x12fbf(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xa01c
leaq 0xc175(%rip), %rsi      # 0x16172
movl $0x1a, %edx
jmp 0xa02f
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x12f85(%rip), %rdi     # 0x1cfa8
leaq 0xc642(%rip), %rsi      # 0x1666c
movl $0xc, %edx
callq 0x4330
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x12aee(%rip), %rsi     # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0