// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movl %r8d, %r12d
movq %rcx, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movl %edi, %r15d
cmpl $0x1, 0x404(%r14)
ja 0xd358
movq %r14, %rdi
movl %r15d, %esi
callq 0xef52
testl %eax, %eax
jg 0xd316
cmpl $-0x1, %eax
jne 0xd46c
leaq 0x8ff4(%rip), %rdi      # 0x16333
callq 0x4290
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x64, (%r14,%rcx)
jl 0xd46c
movzbl %r12b, %r12d
movzbl %bl, %r13d
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movzbl (%r14,%rax), %ebx
cmpl %ebx, 0x404(%r14)
jae 0xd3ca
movq %r14, %rdi
movl %r15d, %esi
callq 0xef52
testl %eax, %eax
jg 0xd396
cmpl $-0x1, %eax
jne 0xd3c2
callq 0x4040
cmpl $0x4, (%rax)
je 0xd396
jmp 0xd47f
testl %eax, %eax
je 0xd493
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 0xd40d
movq %r14, %rdi
movl %ebx, %esi
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rcx
movl %r12d, %r8d
movl %r13d, %r9d
callq 0xd980
testl %eax, %eax
js 0xd42e
jmp 0xd349
leal (%rax,%rbx), %ecx
cmpl $0x400, %ecx            # imm = 0x400
leal -0x400(%rax,%rbx), %eax
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
subl %ebx, 0x404(%r14)
cmpl $0x1, 0x404(%r14)
ja 0xd44c
movq %r14, %rdi
movl %r15d, %esi
callq 0xef52
testl %eax, %eax
jg 0xd42e
jmp 0xd32f
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x64, (%r14,%rcx)
jge 0xd380
movl $0x1, %edi
callq 0x4190
leaq 0xf683(%rip), %rsi      # 0x1cb00
jmp 0xd4aa
movq %rax, %rbp
movl $0x4, %edi
callq 0x4190
movl (%rbp), %ecx
movl %ecx, (%rax)
jmp 0xd4a3
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
leaq 0xf696(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0