// File: /workspace/github_cpp_makefile_star2_O3/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 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 0xa07d
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 0xd67c
movq %r15, %rdi
movl %r12d, %esi
callq 0xed47
movq %rsp, %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd75c
movl %eax, %ebx
testl %eax, %eax
sete %al
andb %r13b, %al
cmpb $0x1, %al
jne 0xa263
movq 0x12f67(%rip), %rbx     # 0x1cfa8
leaq 0xc035(%rip), %rsi      # 0x1607d
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
testq %r14, %r14
je 0xa15b
movq %r14, %rdi
callq 0x4150
movq 0x12f3b(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xa172
xorl %ebp, %ebp
movq %rsp, %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xd75c
testl %eax, %eax
jne 0xa263
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 0xa0eb
addl %eax, %ebp
movslq %eax, %rcx
addq %rcx, %r13
subl %eax, %r14d
jmp 0xa0f9
callq 0x4040
cmpl $0x4, (%rax)
jne 0xa204
testl %r14d, %r14d
jg 0xa0cb
cmpl $-0x1, %ebp
je 0xa20c
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
movq 0x8(%rsp), %r14
movl 0x4(%rsp), %edx
je 0xa191
movq 0x12ea7(%rip), %rdi     # 0x1cfe8
cmpl $0x33, %ecx
jne 0xa1f6
leaq 0xc513(%rip), %rsi      # 0x16664
movl $0x6d, %edx
jmp 0xa25e
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x12e2f(%rip), %rdi     # 0x1cfa8
leaq 0xc4d7(%rip), %rsi      # 0x16657
movl $0xc, %edx
callq 0x4330
xorl %ebx, %ebx
jmp 0xa263
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 0xa263
movq 0x12de7(%rip), %r15     # 0x1cfa8
leaq 0xbeb5(%rip), %rsi      # 0x1607d
movl $0x9, %edx
movq %r15, %rdi
callq 0x4330
testq %r14, %r14
je 0xa233
movq %r14, %rdi
callq 0x4150
movq 0x12dbf(%rip), %rdi     # 0x1cfa8
movq %r14, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xa24b
leaq 0xbf60(%rip), %rsi      # 0x1615d
movl $0x1a, %edx
jmp 0xa25e
testl %ebp, %ebp
jg 0xa107
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x12927(%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 0x12d56(%rip), %rdi     # 0x1cfa8
leaq 0xc3fe(%rip), %rsi      # 0x16657
movl $0xc, %edx
callq 0x4330
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq