// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/dinitctl.cc
// Function: wait_service_state(int, cpbuffer<1024u>&, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, bool)
static int wait_service_state(int socknum, cpbuffer_t &rbuffer, handle_t handle,
        const std::string &service_name, bool do_stop, bool verbose)
{
    // Wait until service started:
    int r = rbuffer.fill_to(socknum, 2);
    while (r > 0) {
        if (rbuffer[0] >= 100) {
            unsigned pktlen = (unsigned char) rbuffer[1];
            fill_buffer_to(rbuffer, socknum, pktlen);

            if (value((cp_info)rbuffer[0]).is_in(cp_info::SERVICEEVENT, cp_info::SERVICEEVENT5)) {
                int ret = process_service_event(rbuffer, pktlen, handle, service_name, do_stop, verbose);
                if (ret >= 0) {
                    return ret;
                }
            }
            else {
                rbuffer.consume(pktlen);
            }

            r = rbuffer.fill_to(socknum, 2);
        }
        else {
            // Not an information packet?
            throw dinit_protocol_error();
        }
    }

    if (r == -1) {
        perror("dinitctl: read");
    }
    else {
        throw dinit_protocol_error();
    }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r12d
movl %r8d, %ebp
movq %rcx, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movl %edi, %r15d
cmpl $0x1, 0x404(%r14)
ja 0xd224
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %ebx
jg 0xd206
jmp 0xd229
movl $0x1, %ebx
movzbl %bpl, %eax
movl %eax, 0x8(%rsp)
movzbl %r12b, %eax
movl %eax, 0x4(%rsp)
testl %ebx, %ebx
jle 0xd371
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x64, (%r14,%rcx)
jl 0xd3c1
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movzbl (%r14,%rax), %ebp
movl $0x1, %r12d
cmpl %ebp, 0x404(%r14)
jae 0xd29c
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %r13d
movl %r13d, %r12d
jg 0xd277
cmpl $-0x1, %r12d
je 0xd2ac
testl %r12d, %r12d
jne 0xd2ba
jmp 0xd38b
callq 0x4040
cmpl $0x4, (%rax)
jne 0xd39d
cmpl $-0x1, %r12d
je 0xd277
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movb (%r14,%rcx), %cl
andb $-0x2, %cl
cmpb $0x64, %cl
jne 0xd30f
movq %r14, %rdi
movl %ebp, %esi
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %r8d
movl 0x4(%rsp), %r9d
callq 0xd8de
testl %eax, %eax
movl (%rsp), %ecx
cmovnsl %eax, %ecx
movl %ecx, (%rsp)
js 0xd330
xorl %ebp, %ebp
jmp 0xd356
leal (%rax,%rbp), %ecx
cmpl $0x400, %ecx            # imm = 0x400
leal -0x400(%rax,%rbp), %eax
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
subl %ebp, 0x404(%r14)
movb $0x1, %bpl
cmpl $0x1, 0x404(%r14)
ja 0xd351
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %ebx
jg 0xd330
jmp 0xd356
movl $0x1, %ebx
testb %bpl, %bpl
jne 0xd239
movl (%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, %ebx
jne 0xd3c1
leaq 0x8fcb(%rip), %rdi      # 0x16348
callq 0x4290
movl $0x1, (%rsp)
jmp 0xd35f
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
jmp 0xd3b0
movq %rax, %r13
movl $0x4, %edi
callq 0x4190
movl (%r13), %ecx
movl %ecx, (%rax)
leaq 0xf789(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x1, %edi
callq 0x4190
leaq 0xf72e(%rip), %rsi      # 0x1cb00
jmp 0xd3b7