LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::kill_with_fire()
void base_process_service::kill_with_fire() noexcept
{
    if (pid != -1) {
        log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid,
                " exceeded allowed stop time; killing.");
        kill_pg(SIGKILL);
    }
}

// Assembly:
cmpl $-0x1, 0x4d8(%rdi)
je 0x22ee4
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0xcb98(%rip), %rsi      # 0x2fa37
pushq $0x2
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x23011
leaq 0xcd18(%rip), %rdi      # 0x2fbce
callq 0x28f17
movl 0x4d8(%rbx), %edi
callq 0x23019
leaq 0xcd0d(%rip), %rdi      # 0x2fbda
callq 0x28f31
pushq $0x9
popq %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x22e4c
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::timer_expired()
void base_process_service::timer_expired() noexcept
{
    waiting_stopstart_timer = false;

    // Timer expires if:
    // We are stopping, including after having startup cancelled (stop timeout, state is STOPPING); We are
    // starting (start timeout, state is STARTING); We are waiting for restart timer before restarting,
    // including smooth recovery (restart timeout, state is STARTING or STARTED).
    if (get_state() == service_state_t::STOPPING) {
        kill_with_fire();
    }
    else if (pid != -1) {
        // Starting, start timed out.
        log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid,
                " exceeded allowed start time; cancelling.");
        interrupt_start();
        stop_reason = stopped_reason_t::TIMEDOUT;
        failed_to_start(false, false);
    }
    else {
        // STARTING / STARTED, and we have no pid: must be restarting (smooth recovery if STARTED)
        do_restart();
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
andb $-0x3, 0x4f4(%rdi)
cmpb $0x3, 0x2c(%rdi)
jne 0x22f0d
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *0x88(%rax)
cmpl $-0x1, 0x4d8(%rbx)
je 0x22f7a
leaq 0x8(%rbx), %r14
leaq 0xcb16(%rip), %rsi      # 0x2fa37
pushq $0x2
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x23011
leaq 0xcc96(%rip), %rdi      # 0x2fbce
callq 0x28f17
movl 0x4d8(%rbx), %edi
callq 0x23019
leaq 0xd052(%rip), %rdi      # 0x2ffa1
callq 0x28f31
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movl $0x5, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1ed2e
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x22ca0
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::queue_packet(char const*, unsigned int)
bool control_conn_t::queue_packet(const char *pkt, unsigned size) noexcept
{
    bool was_empty = outbuf.empty();

    // If the queue is empty, we can try to write the packet out now rather than queueing it.
    // If the write is unsuccessful or partial, we queue the remainder.
    if (was_empty) {
        int wr = bp_sys::write(iob.get_watched_fd(), pkt, size);
        if (wr == -1) {
            if (errno == EPIPE) {
                return false;
            }
            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
                log(loglevel_t::WARN, "Error writing to control connection: ", strerror(errno));
                return false;
            }
            // EAGAIN etc: fall through to below
        }
        else {
            if ((unsigned)wr == size) {
                // Ok, all written.
                return true;
            }
            pkt += wr;
            size -= wr;
        }
    }
    
    // Create a vector out of the (remaining part of the) packet:
    try {
        outbuf.emplace_back(pkt, pkt + size);
        outbuf_size += size;
        return true;
    }
    catch (std::bad_alloc &baexc) {
        // Mark the connection bad, and stop reading further requests
        bad_conn_close = true;
        oom_close = true;
        if (was_empty) {
            // We can't send out-of-memory response as we already wrote as much as we
            // could above. Neither can we later send the response since we have currently
            // sent an incomplete packet. All we can do is close the connection.
            return false;
        }
        else {
            return true;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, (%rsp)
leaq 0x4f0(%rdi), %r14
cmpq %r14, 0x4f0(%rdi)
setne %r12b
je 0x23545
movl %ebp, %eax
addq %r15, %rax
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x2647e
addl %ebp, 0x508(%rbx)
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x2c(%rbx), %edi
movl %ebp, %edx
movq %r15, %rsi
callq 0x81d0
movq %rax, %rcx
cmpl $-0x1, %ecx
je 0x2356c
movb $0x1, %al
subl %ecx, %ebp
je 0x23538
movslq %ecx, %rax
addq %rax, %r15
movq %r15, (%rsp)
jmp 0x23518
callq 0x8040
movl (%rax), %edi
cmpl $0x4, %edi
je 0x23518
cmpl $0xb, %edi
je 0x23518
cmpl $0x20, %edi
je 0x23597
callq 0x81c0
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
pushq $0x2
popq %rdi
callq 0x25aa7
xorl %eax, %eax
jmp 0x23538
cmpl $0x2, %edx
jne 0x235b8
movq %rax, %rdi
callq 0x8200
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a40
movl %r12d, %eax
jmp 0x23538
movq %rax, %rdi
callq 0xaebb
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_close_handle()
bool control_conn_t::process_close_handle()
{
    constexpr int pkt_size = 1 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t handle;
    rbuf.extract((char *) &handle, 1, sizeof(handle));

    rbuf.consume(pkt_size);
    chklen = 0;

    auto key_it = key_service_map.find(handle);
    if (key_it == key_service_map.end()) {
        // Service handle is bad
        char badreq_rep[] = { (char)cp_rply::BADREQ };
        if (!queue_packet(badreq_rep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    service_record *service = key_it->second;
    key_service_map.erase(key_it);

    bool have_other_handle = false;
    auto handle_range = service_key_map.equal_range(service);
    auto it = handle_range.first;
    while (it->second != handle) {
        have_other_handle = true;
        ++it;
    }
    if (!have_other_handle) {
        // check if more handles beyond the found handle
        have_other_handle = std::next(it) != handle_range.second;
    }
    service_key_map.erase(it);

    if (!have_other_handle) {
        service->remove_listener(this);
    }

    char ack_reply[] = { (char)cp_rply::ACK };
    return queue_packet(ack_reply, sizeof(ack_reply));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x2387a
movl $0x5, 0x7c(%rbx)
movb $0x1, %al
jmp 0x23971
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
leaq 0x4c0(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2766e
leaq 0x4c8(%rbx), %rcx
cmpq %rcx, %rax
je 0x23956
movq 0x28(%rax), %rcx
leaq 0x8(%rsp), %r15
movq %rcx, (%r15)
movq %r14, %rdi
movq %rax, %rsi
callq 0x276a2
leaq 0x488(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x276f0
movq %rax, %r15
movq %rdx, %r12
xorl %ebp, %ebp
movl 0x4(%rsp), %eax
cmpl %eax, 0x10(%r15)
je 0x2390b
movq (%r15), %r15
movb $0x1, %bpl
jmp 0x238fd
testb $0x1, %bpl
jne 0x23923
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x26018
cmpq %r12, %rax
setne %bpl
movq %r14, %rdi
movq %r15, %rsi
callq 0x27792
testb $0x1, %bpl
jne 0x23941
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x26036
leaq 0x2(%rsp), %rsi
movb $0x32, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
jmp 0x23971
leaq 0x3(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x23971
movb $0x1, 0x78(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_unpin_service()
bool control_conn_t::process_unpin_service()
{
    using std::string;
    
    constexpr int pkt_size = 1 + sizeof(handle_t);
    
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }
    
    // 1 byte: packet type
    // 4 bytes: service handle
    
    handle_t handle;
    rbuf.extract((char *) &handle, 1, sizeof(handle));
    
    service_record *service = find_service_for_key(handle);
    if (service == nullptr) {
        // Service handle is bad
        char badreqRep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreqRep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    service->unpin();
    services->process_queues();
    char ack_buf[] = { (char) cp_rply::ACK };
    if (! queue_packet(ack_buf, 1)) return false;
    
    // Clear the packet from the buffer
    rbuf.consume(pkt_size);
    chklen = 0;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x23cc8
movl $0x5, 0x7c(%rbx)
movb $0x1, %bpl
jmp 0x23d4d
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x23d30
movq %rax, %rdi
callq 0x1f440
movq 0x70(%rbx), %rdi
callq 0xcdd2
leaq 0x2(%rsp), %rsi
movb $0x32, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebp
testb %al, %al
je 0x23d4d
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
jmp 0x23d4d
leaq 0x3(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebp
testb %al, %al
je 0x23d4d
movb $0x1, 0x78(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_unload_service()
bool control_conn_t::process_unload_service()
{
    using std::string;

    constexpr int pkt_size = 1 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    // 1 byte: packet type
    // 4 bytes: service handle

    handle_t handle;
    rbuf.extract((char *) &handle, 1, sizeof(handle));

    service_record *service = find_service_for_key(handle);
    if (service == nullptr) {
        // Service handle is bad
        char badreq_rep[] = { (char)cp_rply::BADREQ };
        if (! queue_packet(badreq_rep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    if (!service->has_lone_ref() || service->get_state() != service_state_t::STOPPED) {
        // Cannot unload: has other references
        char nak_rep[] = { (char)cp_rply::NAK };
        if (!queue_packet(nak_rep, 1)) return false;
    }
    else {
        // unload (this may fail with bad_alloc)
        services->unload_service(service);

        // drop handle
        service_key_map.erase(service);
        key_service_map.erase(handle);

        // send ack
        char ack_buf[] = { (char) cp_rply::ACK };
        if (!queue_packet(ack_buf, 1)) return false;
    }

    // Clear the packet from the buffer
    rbuf.consume(pkt_size);
    chklen = 0;
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x23d78
movl $0x5, 0x7c(%rbx)
jmp 0x23de9
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x23df5
movq %rax, %r15
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x260aa
testb %al, %al
je 0x23dc3
cmpb $0x0, 0x2c(%r15)
je 0x23e16
leaq 0x2(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x23e12
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x23deb
movb $0x1, 0x78(%rbx)
jmp 0x23deb
xorl %eax, %eax
jmp 0x23deb
movq 0x70(%rbx), %rdi
movq %r15, %rsi
callq 0x260e2
leaq 0x488(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x27894
leaq 0x4c0(%rbx), %rdi
leaq 0x4(%rsp), %rsi
callq 0x27968
leaq 0x1(%rsp), %rsi
movb $0x32, (%rsi)
jmp 0x23dcb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::list_services()
bool control_conn_t::list_services()
{
    rbuf.consume(1); // clear request packet
    chklen = 0;
    
    try {
        auto slist = services->list_services();
        for (auto sptr : slist) {
            if (sptr->get_type() == service_type_t::PLACEHOLDER) continue;

            std::vector<char> pkt_buf;
            int hdrsize = 2 + STATUS_BUFFER_SIZE;

            const std::string &name = sptr->get_name();
            int nameLen = std::min((size_t)256, name.length());
            pkt_buf.resize(hdrsize + nameLen);
            
            pkt_buf[0] = (char)cp_rply::SVCINFO;
            pkt_buf[1] = nameLen;
            
            fill_status_buffer(&pkt_buf[2], sptr);

            for (int i = 0; i < nameLen; i++) {
                pkt_buf[hdrsize+i] = name[i];
            }
            
            if (!queue_packet(std::move(pkt_buf))) return false;
        }
        
        char ack_buf[] = { (char) cp_rply::LISTDONE };
        if (!queue_packet(ack_buf, 1)) return false;

        return true;
    }
    catch (std::bad_alloc &exc)
    {
        do_oom_close();
        return true;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
addq $0x80, %rdi
pushq $0x1
popq %rsi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movq %rbx, 0x8(%rsp)
movq 0x70(%rbx), %rsi
addq $0x10, %rsi
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x26232
movl $0x100, %r13d           # imm = 0x100
leaq 0x10(%rsp), %r15
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0x2409b
movq 0x10(%r14), %r12
cmpl $0x0, 0x28(%r12)
je 0x23ffa
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq 0x10(%r12), %rbp
cmpq %r13, %rbp
cmovaeq %r13, %rbp
leaq 0xc(%rbp), %rsi
movq %r15, %rdi
callq 0x17940
movq 0x10(%rsp), %rax
movb $0x3e, (%rax)
movq 0x10(%rsp), %rax
movb %bpl, 0x1(%rax)
movq 0x10(%rsp), %rdi
addq $0x2, %rdi
movq %r12, %rsi
callq 0x25686
xorl %eax, %eax
cmpq %rax, %rbp
je 0x24077
movq 0x8(%r12), %rcx
movb (%rcx,%rax), %cl
movq 0x10(%rsp), %rdx
movb %cl, 0xc(%rdx,%rax)
incq %rax
jmp 0x2405c
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x253ac
movl %eax, %ebp
movq %r15, %rdi
callq 0xc3e8
testb %bpl, %bpl
jne 0x23ffa
xorl %ebx, %ebx
jmp 0x240b2
leaq 0x10(%rsp), %rsi
movb $0x3f, (%rsi)
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x234ec
movl %eax, %ebx
leaq 0x30(%rsp), %rdi
callq 0xcc24
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rax, %r14
jmp 0x240ef
movq %rdx, %r15
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xc3e8
leaq 0x30(%rsp), %rdi
callq 0xcc24
movq %r14, %rdi
cmpl $0x1, %r15d
jne 0x24111
callq 0x8200
movq 0x8(%rsp), %rax
movw $0x101, 0x78(%rax)      # imm = 0x101
callq 0x8a40
movb $0x1, %bl
jmp 0x240bc
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::list_services5()
bool control_conn_t::list_services5()
{
    rbuf.consume(1); // clear request packet
    chklen = 0;

    try {
        auto slist = services->list_services();
        for (auto sptr : slist) {
            if (sptr->get_type() == service_type_t::PLACEHOLDER) continue;

            std::vector<char> pkt_buf;
            int hdrsize = 2 + STATUS_BUFFER5_SIZE;

            const std::string &name = sptr->get_name();
            int nameLen = std::min((size_t)256, name.length());
            pkt_buf.resize(hdrsize + nameLen);

            pkt_buf[0] = (char)cp_rply::SVCINFO;
            pkt_buf[1] = nameLen;

            fill_status_buffer5(&pkt_buf[2], sptr);

            for (int i = 0; i < nameLen; i++) {
                pkt_buf[hdrsize+i] = name[i];
            }

            if (!queue_packet(std::move(pkt_buf))) return false;
        }

        char ack_buf[] = { (char) cp_rply::LISTDONE };
        if (!queue_packet(ack_buf, 1)) return false;
        
        return true;
    }
    catch (std::bad_alloc &exc)
    {
        do_oom_close();
        return true;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
addq $0x80, %rdi
pushq $0x1
popq %rsi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movq %rbx, 0x8(%rsp)
movq 0x70(%rbx), %rsi
addq $0x10, %rsi
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x26232
movl $0x100, %r13d           # imm = 0x100
leaq 0x10(%rsp), %r15
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0x24203
movq 0x10(%r14), %r12
cmpl $0x0, 0x28(%r12)
je 0x24162
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq 0x10(%r12), %rbp
cmpq %r13, %rbp
cmovaeq %r13, %rbp
leaq 0x10(%rbp), %rsi
movq %r15, %rdi
callq 0x17940
movq 0x10(%rsp), %rax
movb $0x3e, (%rax)
movq 0x10(%rsp), %rax
movb %bpl, 0x1(%rax)
movq 0x10(%rsp), %rdi
addq $0x2, %rdi
movq %r12, %rsi
callq 0x2572b
xorl %eax, %eax
cmpq %rax, %rbp
je 0x241df
movq 0x8(%r12), %rcx
movb (%rcx,%rax), %cl
movq 0x10(%rsp), %rdx
movb %cl, 0x10(%rdx,%rax)
incq %rax
jmp 0x241c4
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x253ac
movl %eax, %ebp
movq %r15, %rdi
callq 0xc3e8
testb %bpl, %bpl
jne 0x24162
xorl %ebx, %ebx
jmp 0x2421a
leaq 0x10(%rsp), %rsi
movb $0x3f, (%rsi)
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x234ec
movl %eax, %ebx
leaq 0x30(%rsp), %rdi
callq 0xcc24
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rax, %r14
jmp 0x24257
movq %rdx, %r15
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xc3e8
leaq 0x30(%rsp), %rdi
callq 0xcc24
movq %r14, %rdi
cmpl $0x1, %r15d
jne 0x24279
callq 0x8200
movq 0x8(%rsp), %rax
movw $0x101, 0x78(%rax)      # imm = 0x101
callq 0x8a40
movb $0x1, %bl
jmp 0x24224
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_service_status()
bool control_conn_t::process_service_status()
{
    constexpr int pkt_size = 1 + sizeof(handle_t);
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t handle;
    rbuf.extract(&handle, 1, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::SERVICESTATUS
    // 1 byte reserved ( = 0)
    // STATUS_BUFFER_SIZE bytes status

    std::vector<char> pkt_buf(2 + STATUS_BUFFER_SIZE);
    pkt_buf[0] = (char)cp_rply::SERVICESTATUS;
    pkt_buf[1] = 0;
    fill_status_buffer(pkt_buf.data() + 2, service);

    return queue_packet(std::move(pkt_buf));
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x242a1
movl $0x5, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2434c
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x242ea
movq %rax, %r14
cmpq $0x10000, 0x10(%rax)    # imm = 0x10000
jb 0x24301
leaq 0x8(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebx
jmp 0x2434c
leaq 0x8(%rsp), %r15
pushq $0xc
popq %rsi
leaq 0x3(%rsp), %rdx
movq %r15, %rdi
callq 0x178ee
movq (%r15), %rax
movb $0x46, (%rax)
movq (%r15), %rax
movb $0x0, 0x1(%rax)
movq (%r15), %rdi
addq $0x2, %rdi
movq %r14, %rsi
callq 0x25686
leaq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x253ac
movl %eax, %ebx
movq %r14, %rdi
callq 0xc3e8
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_service_status5()
bool control_conn_t::process_service_status5()
{
    constexpr int pkt_size = 1 + sizeof(handle_t);
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t handle;
    rbuf.extract(&handle, 1, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::SERVICESTATUS
    // 1 byte reserved ( = 0)
    // STATUS_BUFFER5_SIZE bytes status

    std::vector<char> pkt_buf(2 + STATUS_BUFFER5_SIZE);
    pkt_buf[0] = (char)cp_rply::SERVICESTATUS;
    pkt_buf[1] = 0;
    fill_status_buffer5(pkt_buf.data() + 2, service);

    return queue_packet(std::move(pkt_buf));
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x24391
movl $0x5, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2443c
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x243da
movq %rax, %r14
cmpq $0x10000, 0x10(%rax)    # imm = 0x10000
jb 0x243f1
leaq 0x8(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebx
jmp 0x2443c
leaq 0x8(%rsp), %r15
pushq $0x10
popq %rsi
leaq 0x3(%rsp), %rdx
movq %r15, %rdi
callq 0x178ee
movq (%r15), %rax
movb $0x46, (%rax)
movq (%r15), %rax
movb $0x0, 0x1(%rax)
movq (%r15), %rdi
addq $0x2, %rdi
movq %r14, %rsi
callq 0x2572b
leaq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x253ac
movl %eax, %ebx
movq %r14, %rdi
callq 0xc3e8
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_query_name()
bool control_conn_t::process_query_name()
{
    // 1 byte packet type
    // 1 byte reserved
    // handle: service
    constexpr int pkt_size = 2 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t handle;
    rbuf.extract(&handle, 2, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::SERVICENAME
    // 1 byte reserved
    // uint16_t length
    // N bytes name

    std::vector<char> reply;
    const std::string &name = service->get_name();
    uint16_t name_length = name.length();
    reply.resize(2 + sizeof(uint16_t) + name_length);
    reply[0] = (char)cp_rply::SERVICENAME;
    memcpy(reply.data() + 2, &name_length, sizeof(name_length));
    memcpy(reply.data() + 2 + sizeof(uint16_t), name.c_str(), name_length);

    return queue_packet(std::move(reply));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpl $0x5, 0x484(%rdi)
ja 0x24b27
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x24be1
leaq 0x80(%rbx), %r14
leaq 0xc(%rsp), %r15
pushq $0x2
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x24b73
movq %rax, %r14
movq 0x10(%rax), %r15
cmpq $0x10000, %r15          # imm = 0x10000
jb 0x24b8a
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebx
jmp 0x24be1
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x4(%r15), %rsi
callq 0x17940
leaq 0x10(%rsp), %r12
movq (%r12), %rax
movb $0x42, (%rax)
movq (%r12), %rax
movw %r15w, 0x2(%rax)
movq (%r12), %rdi
addq $0x4, %rdi
movq 0x8(%r14), %rsi
movq %r15, %rdx
callq 0x84d0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x253ac
movl %eax, %ebx
movq %r12, %rdi
callq 0xc3e8
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_getallenv()
bool control_conn_t::process_getallenv()
{
    // 1 byte packet type
    // 1 byte reserved - must be 0

    constexpr int pkt_size = 2;
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    uint8_t reserved_byte = rbuf[1];
    if (reserved_byte != 0) {
        char badreqRep[] = { (char)cp_rply::BADREQ };
        if (!queue_packet(badreqRep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    // The reply looks like:
    // 1 byte - reply type
    // sizeof(size_t) - reply data size
    // n bytes - reply data (NAME=VALUE, separated by nul characters)

    std::vector<char> env_block;
    constexpr size_t env_block_hdr_size = sizeof(size_t) + 1;
    env_block.resize(env_block_hdr_size);

    rbuf.consume(pkt_size);
    auto env = main_env.build();
    for (const char *env_var : env.env_list) {
        if (env_var != nullptr) {
            env_block.insert(env_block.end(), env_var, env_var + strlen(env_var) + 1);
        }
    }

    env_block[0] = (char)cp_rply::ALLENV;
    size_t block_size = env_block.size() - env_block_hdr_size;
    memcpy(env_block.data() + 1, &block_size, sizeof(block_size));
    if (!queue_packet(std::move(env_block))) return false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
cmpl $0x1, 0x484(%rdi)
ja 0x24d95
movl $0x2, 0x7c(%rbx)
movb $0x1, %bpl
jmp 0x24e8f
movl 0x480(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
cmpb $0x0, 0x80(%rbx,%rax)
je 0x24ddc
leaq 0x18(%rsp), %rsi
movb $0x34, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebp
testb %al, %al
je 0x24e8f
movb $0x1, 0x78(%rbx)
jmp 0x24e8f
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
pushq $0x9
popq %rsi
callq 0x17940
leaq 0x80(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0x25df2
leaq 0x23008(%rip), %rsi     # 0x47e10
leaq 0x18(%rsp), %rdi
callq 0x167b8
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rbp
movq %rsp, %r14
cmpq %rbp, %r13
je 0x24e55
movq (%r13), %r15
testq %r15, %r15
je 0x24e4f
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x8220
leaq (%r15,%rax), %rcx
incq %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x26370
addq $0x8, %r13
jmp 0x24e1f
movq %rsp, %r14
movq (%r14), %rax
movb $0x4e, (%rax)
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
addq $-0x9, %rcx
movq %rcx, 0x1(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x253ac
movl %eax, %ebp
leaq 0x18(%rsp), %rdi
callq 0x16f40
movq %r14, %rdi
callq 0xc3e8
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24ea2
movq %rax, %rbx
jmp 0x24eb4
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x16f40
movq %rsp, %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_listenenv()
bool control_conn_t::process_listenenv()
{
    // 1 byte packet type, nothing else
    rbuf.consume(1);

    main_env.add_listener(this);

    char ack_rep[] = { (char)cp_rply::ACK };
    return queue_packet(ack_rep, 1);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
addq $0x80, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x25df2
leaq 0x8(%rbx), %rsi
leaq 0x22f2a(%rip), %rdi     # 0x47e10
callq 0x26390
leaq 0x7(%rsp), %rsi
movb $0x32, (%rsi)
movq %rbx, %rdi
movl %ebp, %edx
callq 0x234ec
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_set_trigger()
bool control_conn_t::process_set_trigger()
{
    // 1 byte packet type
    // handle: service
    // 1 byte trigger value
    constexpr int pkt_size = 2 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    handle_t handle;
    trigger_val_t trigger_val;

    rbuf.extract(&handle, 1, sizeof(handle));
    rbuf.extract(&trigger_val, 1 + sizeof(handle), sizeof(trigger_val));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || service->get_type() != service_type_t::TRIGGERED) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    triggered_service *tservice = static_cast<triggered_service *>(service);
    tservice->set_trigger(trigger_val != 0);
    services->process_queues();

    char ack_rep[] = { (char)cp_rply::ACK };
    return queue_packet(ack_rep, 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x5, 0x484(%rdi)
ja 0x24f25
movl $0x6, 0x7c(%rbx)
movb $0x1, %al
jmp 0x24fb4
leaq 0x80(%rbx), %r14
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rbp
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x25e18
leaq 0x1(%rsp), %rsi
pushq $0x5
popq %rdx
movq %r14, %rdi
movl %ebp, %ecx
callq 0x25e18
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x24fa1
cmpl $0x5, 0x28(%rax)
jne 0x24fa1
xorl %esi, %esi
cmpb $0x0, 0x1(%rsp)
setne %sil
movq %rax, %rdi
callq 0x263a8
movq 0x70(%rbx), %rdi
callq 0xcdd2
leaq 0x2(%rsp), %rsi
movb $0x32, (%rsi)
jmp 0x24fa9
leaq 0x3(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_signal()
bool control_conn_t::process_signal()
{
    // packet contains signal number and process handle
    constexpr int pkt_size = 1 + sizeof(int) + sizeof(handle_t);
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    sig_num_t sig_num;
    rbuf.extract(&sig_num, 1, sizeof(sig_num));
    handle_t handle;
    rbuf.extract(&handle, 1 + sizeof(sig_num), sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::*

    pid_t spid = service->get_pid();
    // we probably don't want to kill/signal every process (in the current group),
    // but get_pid() sometimes returns -1 if e.g. service is not 'started'
    if (spid == -1 || spid == 0) {
        char nak_rep[] = { (char)cp_rply::SIGNAL_NOPID };
        return queue_packet(nak_rep, 1);
    }
    else {
        if (bp_sys::kill(spid, sig_num) != 0) {
            if (errno == EINVAL) {
                log(loglevel_t::ERROR, "Requested signal not in valid signal range.");
                char nak_rep[] = { (char)cp_rply::SIGNAL_BADSIG };
                return queue_packet(nak_rep, 1);
            }
            log(loglevel_t::ERROR, "Error sending signal to process: ", strerror(errno));
            char nak_rep[] = { (char)cp_rply::SIGNAL_KILLERR };
            return queue_packet(nak_rep, 1);
        }
    }
    char ack_rep[] = { (char)cp_rply::ACK };
    return queue_packet(ack_rep, 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x8, 0x484(%rdi)
ja 0x25154
movl $0x9, 0x7c(%rbx)
movb $0x1, %al
jmp 0x25239
leaq 0x80(%rbx), %r14
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %rbp
movq %r14, %rdi
movl %ebp, %ecx
callq 0x25e18
leaq 0x14(%rsp), %r15
pushq $0x5
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %ecx
callq 0x25e18
pushq $0x9
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
testq %rax, %rax
je 0x251bf
movq (%rax), %rcx
movq %rax, %rdi
callq *0x48(%rcx)
leal 0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x251c9
leaq 0xe(%rsp), %rsi
movb $0x4a, (%rsi)
jmp 0x2522e
leaq 0xf(%rsp), %rsi
movb $0x33, (%rsi)
jmp 0x2522e
movl 0x10(%rsp), %esi
movl %eax, %edi
callq 0x88c0
testl %eax, %eax
je 0x251fd
callq 0x8040
movl (%rax), %edi
cmpl $0x16, %edi
jne 0x25207
leaq 0xb281(%rip), %rsi      # 0x3046c
pushq $0x3
popq %rdi
callq 0x28d42
leaq 0xd(%rsp), %rsi
movb $0x4b, (%rsi)
jmp 0x2522e
leaq 0xb(%rsp), %rsi
movb $0x32, (%rsi)
jmp 0x2522e
callq 0x81c0
movq %rax, %r14
leaq 0xb282(%rip), %rsi      # 0x30498
pushq $0x3
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x28f31
leaq 0xc(%rsp), %rsi
movb $0x4c, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_query_dsc_dir()
bool control_conn_t::process_query_dsc_dir()
{
    // packet contains command byte, spare byte, and service handle
    constexpr int pkt_size = 2 + sizeof(handle_t);

    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    bool spare_ok = (rbuf[1] == 0);
    handle_t handle;
    rbuf.extract(&handle, 2, sizeof(handle));
    rbuf.consume(pkt_size);
    chklen = 0;

    service_record *service = find_service_for_key(handle);
    if (service == nullptr || !spare_ok) {
        char nak_rep[] = { (char)cp_rply::NAK };
        return queue_packet(nak_rep, 1);
    }

    // Reply:
    // 1 byte packet type = cp_rply::SVCDSCDIR
    // 4 bytes (uint32_t) = directory length (no nul terminator)
    // N bytes            = directory (no nul)
    std::vector<char> reppkt;
    auto sdir_len = static_cast<uint32_t>(strlen(service->get_service_dsc_dir()));
    reppkt.resize(1 + sizeof(uint32_t) + sdir_len);  // packet type, dir length, dir
    reppkt[0] = (char)cp_rply::SVCDSCDIR;
    std::memcpy(&reppkt[1], &sdir_len, sizeof(sdir_len));
    std::memcpy(&reppkt[1 + sizeof(uint32_t)], service->get_service_dsc_dir(), sdir_len);

    if (! queue_packet(std::move(reppkt))) return false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpl $0x5, 0x484(%rdi)
ja 0x2526c
movl $0x6, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2535b
movl 0x480(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
leaq 0x80(%rbx), %r14
cmpb $0x0, 0x80(%rbx,%rax)
sete %bpl
leaq 0xc(%rsp), %r15
pushq $0x2
popq %rdx
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
movl (%r15), %esi
movq %rbx, %rdi
callq 0x26056
movq %rax, %r14
testq %rax, %rax
setne %al
testb %al, %bpl
je 0x25346
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
movq 0x100(%r14), %rdi
callq 0x8220
movq %rax, %r12
movl %r12d, %r15d
leaq 0x5(%r15), %rsi
movq %r13, %rdi
callq 0x17940
leaq 0x10(%rsp), %r13
movq (%r13), %rax
movb $0x4d, (%rax)
movq (%r13), %rax
movl %r12d, 0x1(%rax)
movq (%r13), %rdi
addq $0x5, %rdi
movq 0x100(%r14), %rsi
movq %r15, %rdx
callq 0x84d0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x253ac
movl %eax, %ebx
movq %r13, %rdi
callq 0xc3e8
jmp 0x2535b
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
movl %eax, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::queue_packet(std::vector<char, std::allocator<char>>&&)
bool control_conn_t::queue_packet(std::vector<char> &&pkt) noexcept
{
    bool was_empty = outbuf.empty();
    
    if (was_empty) {
        outpkt_index = 0;
        // We can try sending the packet immediately:
        int wr = bp_sys::write(iob.get_watched_fd(), pkt.data(), pkt.size());
        if (wr == -1) {
            if (errno == EPIPE) {
                return false;
            }
            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
                log(loglevel_t::WARN, "Error writing to control connection: ", strerror(errno));
                return false;
            }
            // EAGAIN etc: fall through to below
        }
        else {
            if ((unsigned)wr == pkt.size()) {
                // Ok, all written.
                return true;
            }
            outpkt_index = wr;
        }
    }
    
    try {
        outbuf.emplace_back(std::move(pkt));
        outbuf_size += pkt.size();
        return true;
    }
    catch (std::bad_alloc &baexc) {
        // Mark the connection bad, and stop reading further requests
        bad_conn_close = true;
        oom_close = true;
        if (was_empty) {
            // We can't send out-of-memory response as we already wrote as much as we
            // could above. Neither can we later send the response since we have currently
            // sent an incomplete packet. All we can do is close the connection.
            return false;
        }
        else {
            return true;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4f0(%rdi), %r15
cmpq %r15, 0x4f0(%rdi)
setne %bpl
je 0x253f4
movq %r15, %rdi
movq %r14, %rsi
callq 0x2649a
movl 0x8(%r14), %eax
subl (%r14), %eax
addl %eax, 0x508(%rbx)
movb $0x1, %cl
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x50c(%rbx)
movl 0x2c(%rbx), %edi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
subq %rsi, %rdx
callq 0x81d0
cmpl $-0x1, %eax
je 0x2542a
movl %eax, %edx
movq 0x8(%r14), %rsi
subq (%r14), %rsi
movb $0x1, %cl
cmpq %rsi, %rdx
je 0x253e7
movl %eax, 0x50c(%rbx)
jmp 0x253cd
callq 0x8040
movl (%rax), %edi
cmpl $0x4, %edi
je 0x253cd
cmpl $0xb, %edi
je 0x253cd
cmpl $0x20, %edi
je 0x25453
callq 0x81c0
movq %rsp, %rsi
movq %rax, (%rsi)
pushq $0x2
popq %rdi
callq 0x25aa7
xorl %ecx, %ecx
jmp 0x253e7
cmpl $0x2, %edx
jne 0x25476
movq %rax, %rdi
callq 0x8200
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a40
movl %ebp, %ecx
jmp 0x253e7
movq %rax, %rdi
callq 0xaebb
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::allocate_service_handle(service_record*)
handle_t control_conn_t::allocate_service_handle(service_record *record)
{
    // Try to find a unique handle (integer) in a single pass. Since the map is ordered, we can search until
    // we find a gap in the handle values.
    handle_t candidate = 0;
    for (auto p : key_service_map) {
        if (p.first == candidate) ++candidate;
        else break;
    }

    bool is_unique = (service_key_map.find(record) == service_key_map.end());

    // The following operations perform allocation (can throw std::bad_alloc). If an exception occurs we
    // must undo any previous actions:
    if (is_unique) {
        record->add_listener(this);
    }
    
    try {
        key_service_map[candidate] = record;
        service_key_map.insert(std::make_pair(record, candidate));
    }
    catch (...) {
        if (is_unique) {
            record->remove_listener(this);
        }

        key_service_map.erase(candidate);
    }
    
    return candidate;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movq %rsi, 0x10(%rsp)
leaq 0x4c0(%rdi), %rbx
movq 0x4d8(%rdi), %rax
leaq 0x4c8(%rdi), %r15
xorl %ebp, %ebp
cmpq %r15, %rax
je 0x254c1
cmpl 0x20(%rax), %ebp
jne 0x254c1
incl %ebp
movq %rax, %rdi
callq 0x8420
jmp 0x254ab
movl %ebp, 0xc(%rsp)
leaq 0x488(%r14), %r12
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x27716
movq %rax, %r15
testq %rax, %rax
jne 0x254ee
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x26418
movq 0x10(%rsp), %r13
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x26430
movq %r13, (%rax)
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
movq %r12, %rdi
callq 0x2852a
movl 0xc(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25534
movq %rax, %rdi
callq 0x8200
testq %r15, %r15
jne 0x2554e
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x26036
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x27968
callq 0x8a40
jmp 0x2551f
movq %rax, %rbx
callq 0x8a40
movq %rbx, %rdi
callq 0x8a90
movq %rax, %rdi
callq 0xaebb
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::check_dependents(service_record*, bool&)
bool control_conn_t::check_dependents(service_record *service, bool &had_dependents)
{
    std::vector<char> reply_pkt;
    size_t num_depts = 0;

    for (service_dep *dep : service->get_dependents()) {
        if (dep->dep_type == dependency_type::REGULAR && dep->holding_acq) {
            num_depts++;
            // find or allocate a service handle
            handle_t dept_handle = allocate_service_handle(dep->get_from());
            if (reply_pkt.empty()) {
                // packet type, size
                reply_pkt.reserve(1 + sizeof(size_t) + sizeof(handle_t));
                reply_pkt.resize(1 + sizeof(size_t));
                reply_pkt[0] = (char)cp_rply::DEPENDENTS;
            }
            auto old_size = reply_pkt.size();
            reply_pkt.resize(old_size + sizeof(handle_t));
            memcpy(reply_pkt.data() + old_size, &dept_handle, sizeof(dept_handle));
        }
    }

    if (num_depts != 0) {
        // There are affected dependents
        had_dependents = true;
        memcpy(reply_pkt.data() + 1, &num_depts, sizeof(num_depts));
        return queue_packet(std::move(reply_pkt));
    }

    had_dependents = false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
xorps %xmm0, %xmm0
movq %rsp, %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
addq $0x130, %rbx            # imm = 0x130
xorl %ebp, %ebp
pushq $0xd
popq %r14
movq %rbx, %r15
movq (%r15), %r15
cmpq %rbx, %r15
je 0x25638
movq 0x10(%r15), %rax
cmpl $0x0, 0x14(%rax)
jne 0x255a9
cmpb $0x1, 0x11(%rax)
jne 0x255a9
movq %rdx, 0x20(%rsp)
movq (%rax), %rsi
movq %rdi, 0x18(%rsp)
callq 0x2547e
movl %eax, %r13d
movq (%rsp), %rax
movq 0x8(%rsp), %r12
cmpq %r12, %rax
jne 0x2560e
movq %rsp, %rdi
movq %r14, %rsi
callq 0x25f74
movq %rsp, %rdi
pushq $0x9
popq %rsi
callq 0x17940
movq (%rsp), %rax
movb $0x41, (%rax)
movq (%rsp), %rax
movq 0x8(%rsp), %r12
subq %rax, %r12
leaq 0x4(%r12), %rsi
movq %rsp, %rdi
callq 0x17940
incq %rbp
movq (%rsp), %rax
movl %r13d, (%rax,%r12)
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
jmp 0x255a9
testq %rbp, %rbp
je 0x25653
movb $0x1, (%rdx)
movq %rsp, %rsi
movq (%rsi), %rax
movq %rbp, 0x1(%rax)
callq 0x253ac
movl %eax, %ebx
jmp 0x25658
movb $0x0, (%rdx)
movb $0x1, %bl
movq %rsp, %rdi
callq 0xc3e8
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25673
movq %rax, %rbx
movq %rsp, %rdi
callq 0xc3e8
movq %rbx, %rdi
callq 0x8a90
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: fill_status_buffer(char*, service_record*)
static void fill_status_buffer(char *buffer, service_record *service)
{
    buffer[0] = static_cast<char>(service->get_state());
    buffer[1] = static_cast<char>(service->get_target_state());

    pid_t proc_pid = service->get_pid();

    char b0 = service->is_waiting_for_console() ? 1 : 0;
    b0 |= service->has_console() ? 2 : 0;
    b0 |= service->was_start_skipped() ? 4 : 0;
    b0 |= service->is_marked_active() ? 8 : 0;
    b0 |= (proc_pid != -1) ? 16 : 0;
    buffer[2] = b0;
    buffer[3] = static_cast<char>(service->get_stop_reason());

    buffer[4] = 0; // (if exec failed, these are replaced with stage)
    buffer[5] = 0;

    if (proc_pid != -1) {
        memcpy(buffer + 6, &proc_pid, sizeof(proc_pid));
    }
    else {
        // These values only make sense in STOPPING/STOPPED, but we'll fill them in regardless:
        if (buffer[3] == (char)stopped_reason_t::EXECFAILED) {
            base_process_service *bsp = (base_process_service *)service;
            run_proc_err exec_err = bsp->get_exec_err_info();
            uint16_t stage = (uint16_t)exec_err.stage;
            memcpy(buffer + 4, &stage, 2);
            memcpy(buffer + 6, &exec_err.st_errno, sizeof(int));
        }
        else {
            auto exit_status_ps = service->get_exit_status();
            // There is no portable way to derive the correct exit status value corresponding
            // to any condition except for a clean exit (0) which is the most important anyway.
            // We'll use -1 for any other status although this may not be valid.
            int exit_status = exit_status_ps.did_exit_clean() ? 0 : -1;
            memcpy(buffer + 6, &exit_status, sizeof(exit_status));
        }
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movb 0x2c(%rsi), %al
movb %al, (%rdi)
movb 0x2d(%rsi), %al
movb %al, 0x1(%rdi)
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x48(%rax)
cmpl $-0x1, %eax
setne %cl
movl 0x10c(%r14), %edx
movl %edx, %esi
shrb $0x5, %sil
movl %edx, %edi
shrl $0xe, %edi
andb $0x4, %dil
shrl $0x5, %edx
andb $0x8, %dl
shlb $0x4, %cl
andb $0x3, %sil
orb %cl, %sil
orb %dil, %sil
orb %dl, %sil
movb %sil, 0x2(%rbx)
movb 0x1c4(%r14), %cl
andw $0x0, 0x4(%rbx)
movb %cl, 0x3(%rbx)
cmpl $-0x1, %eax
je 0x256f3
movl %eax, 0x6(%rbx)
jmp 0x25723
cmpb $0x4, %cl
jne 0x2570c
movq 0x4f8(%r14), %rax
movw %ax, 0x4(%rbx)
shrq $0x20, %rax
movl %eax, 0x6(%rbx)
jmp 0x25723
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
shrq $0x20, %rax
xorl %ecx, %ecx
negq %rax
sbbl %ecx, %ecx
movl %ecx, 0x6(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq