// File: 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 namespace std;
    
    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
movq %rsp, %rbp
subq $0x30, %rsp
movb %r8b, %al
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movb %al, -0x22(%rbp)
cmpb $0x3b, -0x22(%rbp)
jne 0xce22
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
movl $0x6, %edx
callq 0x11440
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x2, %edx
movl $0x4, %ecx
callq 0x11540
cmpq $0x0, -0x20(%rbp)
je 0xce08
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x113e0
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rdi
movl $0x7, %esi
callq 0x115f0
movl $0x0, -0x4(%rbp)
jmp 0xcef3
cmpb $0x3c, -0x22(%rbp)
jne 0xce60
testb $0x1, -0x21(%rbp)
je 0xce54
movq 0x251b3(%rip), %rdi     # 0x31fe8
leaq 0x1737e(%rip), %rsi     # 0x241ba
callq 0x53d0
movq 0x251a0(%rip), %rdi     # 0x31fe8
leaq 0x1739a(%rip), %rsi     # 0x241e9
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xcef3
cmpb $0x47, -0x22(%rbp)
jne 0xce9b
testb $0x1, -0x21(%rbp)
je 0xce92
movq 0x25175(%rip), %rdi     # 0x31fe8
leaq 0x173b9(%rip), %rsi     # 0x24233
callq 0x53d0
movq 0x25162(%rip), %rdi     # 0x31fe8
leaq 0x173cf(%rip), %rsi     # 0x2425c
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xcef3
cmpb $0x48, -0x22(%rbp)
jne 0xced6
testb $0x1, -0x21(%rbp)
je 0xcecd
movq 0x2513a(%rip), %rdi     # 0x31fe8
leaq 0x173f5(%rip), %rsi     # 0x242aa
callq 0x53d0
movq 0x25127(%rip), %rdi     # 0x31fe8
leaq 0x17394(%rip), %rsi     # 0x2425c
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xcef3
movl $0x1, %edi
callq 0x51c0
movq %rax, %rdi
leaq 0x24bf6(%rip), %rsi     # 0x31ae0
xorl %eax, %eax
movl %eax, %edx
callq 0x56b0
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)