// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/dinitctl.cc
// Function: check_load_reply(int, cpbuffer<1024u>&, unsigned int*, service_state_t*, bool)
static int check_load_reply(int socknum, cpbuffer_t &rbuffer, handle_t *handle_p, service_state_t *state_p, bool write_error)
{
    using std::cout;
    using std::cerr;
    
    cp_rply reply_pkt_h = (cp_rply)rbuffer[0];
    if (reply_pkt_h == cp_rply::SERVICERECORD) {
        fill_buffer_to(rbuffer, socknum, 2 + sizeof(*handle_p));
        rbuffer.extract((char *) handle_p, 2, sizeof(*handle_p));
        if (state_p) *state_p = static_cast<service_state_t>(rbuffer[1]);
        //target_state = static_cast<service_state_t>(rbuffer[2 + sizeof(handle)]);
        rbuffer.consume(3 + sizeof(*handle_p));
        return 0;
    }
    else if (reply_pkt_h == cp_rply::NOSERVICE) {
        if (write_error) {
            cerr << "dinitctl: failed to find service description.\n";
            cerr << "dinitctl: check service description file exists / service name spelling.\n";
        }
        return 1;
    }
    else if (reply_pkt_h == cp_rply::SERVICE_DESC_ERR) {
        if (write_error) {
            cerr << "dinitctl: error in service description.\n";
            cerr << "dinitctl: try 'dinitcheck <service-name>' or check log for more information.\n";
        }
        return 1;
    }
    else if (reply_pkt_h == cp_rply::SERVICE_LOAD_ERR) {
        if (write_error) {
            cerr << "dinitctl: error loading service (or dependency of service).\n";
            cerr << "dinitctl: try 'dinitcheck <service-name>' or check log for more information.\n";
        }
        return 1;
    }
    else {
        throw dinit_protocol_error();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl 0x400(%rsi), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movzbl (%rsi,%rcx), %eax
cmpl $0x46, %eax
jg 0xd7cf
cmpl $0x3b, %eax
je 0xd800
cmpl $0x3c, %eax
jne 0xd96d
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd93b
movq 0xf83e(%rip), %r14      # 0x1cfe8
leaq 0x8a23(%rip), %rsi      # 0x161d4
movl $0x2e, %edx
movq %r14, %rdi
callq 0x4330
leaq 0x8a3e(%rip), %rsi      # 0x16203
movl $0x49, %edx
jmp 0xd87b
cmpl $0x47, %eax
je 0xd846
cmpl $0x48, %eax
jne 0xd96d
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd93b
movq 0xf7f6(%rip), %r14      # 0x1cfe8
leaq 0x8acb(%rip), %rsi      # 0x162c4
movl $0x3c, %edx
jmp 0xd867
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, %ebp
cmpl $0x5, 0x404(%rbx)
ja 0xd890
movq %rbx, %rdi
movl %ebp, %esi
callq 0xef52
testl %eax, %eax
jg 0xd808
cmpl $-0x1, %eax
jne 0xd888
callq 0x4040
cmpl $0x4, (%rax)
je 0xd808
movq %rax, %r12
movl $0x4, %edi
callq 0x4190
movl (%r12), %ecx
movl %ecx, (%rax)
jmp 0xd95c
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd93b
movq 0xf78d(%rip), %r14      # 0x1cfe8
leaq 0x89eb(%rip), %rsi      # 0x1624d
movl $0x28, %edx
movq %r14, %rdi
callq 0x4330
leaq 0x8a00(%rip), %rsi      # 0x16276
movl $0x4d, %edx
movq %r14, %rdi
callq 0x4330
jmp 0xd93b
testl %eax, %eax
je 0xd94c
movl 0x400(%rbx), %r12d
leal 0x2(%r12), %eax
addl $0xfffffc02, %r12d      # imm = 0xFFFFFC02
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r12d
leal -0x3fd(%r12), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xd8ef
movl $0x400, %r13d           # imm = 0x400
subl %r12d, %r13d
movl %r12d, %esi
addq %rbx, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x4270
addq %r13, %r15
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4270
jmp 0xd8f8
movl %r12d, %eax
movl (%rbx,%rax), %eax
movl %eax, (%r15)
movl 0x400(%rbx), %eax
testq %r14, %r14
je 0xd91b
leal 0x1(%rax), %ecx
leal -0x3ff(%rax), %edx
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %edx
movb (%rbx,%rdx), %cl
movb %cl, (%r14)
leal 0x7(%rax), %ecx
addl $0xfffffc07, %eax       # imm = 0xFFFFFC07
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%rbx)
addl $-0x7, 0x404(%rbx)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
leaq 0xf1dd(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x1, %edi
callq 0x4190
leaq 0xf182(%rip), %rsi      # 0x1cb00
jmp 0xd963