// File: /workspace/github_cpp_makefile_star2_O1/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 0xd70d
cmpl $0x3b, %eax
je 0xd745
cmpl $0x3c, %eax
jne 0xd8cb
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd884
movq 0xf900(%rip), %r14      # 0x1cfe8
leaq 0x8afa(%rip), %rsi      # 0x161e9
movl $0x2e, %edx
movq %r14, %rdi
callq 0x4330
leaq 0x8b15(%rip), %rsi      # 0x16218
movl $0x49, %edx
jmp 0xd829
cmpl $0x47, %eax
je 0xd7f4
cmpl $0x48, %eax
jne 0xd8cb
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd884
movq 0xf8b4(%rip), %r14      # 0x1cfe8
leaq 0x8b9e(%rip), %rsi      # 0x162d9
movl $0x3c, %edx
jmp 0xd815
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %r13d
cmpl $0x5, 0x404(%rbx)
ja 0xd771
movq %rbx, %rdi
movl %ebp, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %r12d
movl %r12d, %r13d
jg 0xd74d
cmpl $-0x1, %r13d
je 0xd781
testl %r13d, %r13d
jne 0xd78f
jmp 0xd895
callq 0x4040
cmpl $0x4, (%rax)
jne 0xd8a7
cmpl $-0x1, %r13d
je 0xd74d
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 0xd833
movl $0x400, %r13d           # imm = 0x400
subl %r12d, %r13d
movl %r12d, %esi
addq %rbx, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x4270
addq %r15, %r13
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4270
jmp 0xd83c
movl $0x1, %ebx
testb %r8b, %r8b
je 0xd884
movq 0xf7df(%rip), %r14      # 0x1cfe8
leaq 0x8a52(%rip), %rsi      # 0x16262
movl $0x28, %edx
movq %r14, %rdi
callq 0x4330
leaq 0x8a67(%rip), %rsi      # 0x1628b
movl $0x4d, %edx
movq %r14, %rdi
callq 0x4330
jmp 0xd884
movl %r12d, %eax
movl (%rbx,%rax), %eax
movl %eax, (%r15)
testq %r14, %r14
je 0xd85e
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)
movl 0x400(%rbx), %eax
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)
jmp 0xd8ba
movq %rax, %r12
movl $0x4, %edi
callq 0x4190
movl (%r12), %ecx
movl %ecx, (%rax)
leaq 0xf27f(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x1, %edi
callq 0x4190
leaq 0xf224(%rip), %rsi      # 0x1cb00
jmp 0xd8c1