// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rcx, %r14
movq %rsi, %rbx
movl 0x400(%rsi), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movzbl (%rsi,%rcx), %eax
cmpl $0x48, %eax
je 0xa4f5
cmpl $0x3c, %eax
je 0xa51c
cmpl $0x47, %eax
je 0xa4dd
cmpl $0x3b, %eax
jne 0xa551
movq %rdx, %r15
movl %edi, %esi
pushq $0x6
popq %rdx
movq %rbx, %rdi
callq 0xb33a
pushq $0x2
popq %rdx
pushq $0x4
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb3a0
testq %r14, %r14
je 0xa4ce
movl 0x400(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movb (%rbx,%rax), %al
movb %al, (%r14)
pushq $0x7
popq %rsi
movq %rbx, %rdi
callq 0xb41c
xorl %ebx, %ebx
jmp 0xa549
pushq $0x1
popq %rbx
testb %r8b, %r8b
je 0xa549
movq 0x10b04(%rip), %r14     # 0x1aff0
leaq 0x7d4a(%rip), %rsi      # 0x1223d
jmp 0xa50b
pushq $0x1
popq %rbx
testb %r8b, %r8b
je 0xa549
movq 0x10aec(%rip), %r14     # 0x1aff0
leaq 0x7da9(%rip), %rsi      # 0x122b4
movq %r14, %rdi
callq 0x42f0
leaq 0x7d4c(%rip), %rsi      # 0x12266
jmp 0xa541
pushq $0x1
popq %rbx
testb %r8b, %r8b
je 0xa549
movq 0x10ac5(%rip), %r14     # 0x1aff0
leaq 0x7c92(%rip), %rsi      # 0x121c4
movq %r14, %rdi
callq 0x42f0
leaq 0x7cb2(%rip), %rsi      # 0x121f3
movq %r14, %rdi
callq 0x42f0
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
pushq $0x1
popq %rdi
callq 0x4190
leaq 0x105a0(%rip), %rsi     # 0x1ab00
movq %rax, %rdi
xorl %edx, %edx
callq 0x44f0