LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/../dasynq/include/dasynq.h
// Function: dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>::deregister(dasynq::v2::dprivate::base_timer_watcher*, dasynq::clock_type)
void deregister(base_timer_watcher *callback, clock_type clock) noexcept
    {
        loop_mech.remove_timer(callback->timer_handle, clock);
        
        waitqueue_node<T_Mutex> qnode;
        get_attn_lock(qnode);
        
        loop_mech.issue_delete(callback);
        
        release_lock(qnode);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
addq $0x20, %rsi
callq 0xcf60
leaq 0xf(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xd5d8
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd58c
movq %r14, %rdi
movq %r15, %rsi
callq 0xd604
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/../dasynq/include/dasynq/timerfd.h
// Function: dasynq::timer_fd_events<dasynq::v2::child_proc_events<dasynq::v2::dprivate::event_dispatch<dasynq::v2::epoll_traits, dasynq::v2::default_traits<dasynq::null_mutex>>>>::stop_timer_nolock(dasynq::dary_heap<dasynq::timer_data, dasynq::time_val, dasynq::compare_timespec, 4>::handle_t&, dasynq::clock_type)
void stop_timer_nolock(timer_handle_t &timer_id, clock_type clock = clock_type::MONOTONIC) noexcept
    {
        timer_queue_t &queue = this->queue_for_clock(clock);
        int fd = (clock == clock_type::MONOTONIC) ? timerfd_fd : systemtime_fd;
        if (queue.is_queued(timer_id)) {
            bool was_first = (&queue.get_root()) == &timer_id;
            queue.remove(timer_id);
            if (was_first) {
                set_timer_from_queue(fd, queue);
            }
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
xorl %eax, %eax
xorl %r8d, %r8d
cmpl $0x1, %edx
setne %cl
sete %dl
movq 0x20(%rsi), %rsi
cmpq $-0x1, %rsi
je 0x25fb0
movb %dl, %r8b
shll $0x5, %r8d
leaq (%rdi,%r8), %r14
addq $0x58, %r14
movb %cl, %al
movl 0x98(%rdi,%rax,4), %ebp
movq (%r14), %rax
movq 0x10(%rax), %r15
movq %r14, %rdi
callq 0xcfc6
cmpq %rbx, %r15
je 0x25fbb
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %edi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xd850
nop
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/../dasynq/include/dasynq.h
// Function: dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>::deregister(dasynq::v2::dprivate::base_child_watcher<dasynq::v2::dprivate::proc_status>*, int)
void deregister(base_child_watcher *callback, pid_t child) noexcept
    {
        loop_mech.remove_child_watch(callback->watch_handle);

        waitqueue_node<T_Mutex> qnode;
        get_attn_lock(qnode);
        
        loop_mech.issue_delete(callback);
        
        release_lock(qnode);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
addq $0x20, %rsi
callq 0x26018
leaq 0xf(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xd5d8
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd58c
movq %r14, %rdi
movq %r15, %rsi
callq 0xd604
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::restart_ps_process()
bool base_process_service::restart_ps_process() noexcept
{
    using time_val = dasynq::time_val;

    time_val current_time;
    event_loop.get_time(current_time, clock_type::MONOTONIC);

    // Check if enough time has lapsed since the previous restart. If not, start a timer:
    time_val tdiff = current_time - last_start_time;
    if (restart_delay <= tdiff) {
        // > restart delay (normally 200ms)
        do_restart();
    }
    else {
        time_val timeout = restart_delay - tdiff;
        process_timer.arm_timer_rel(event_loop, timeout);
        waiting_restart_timer = true;
    }
    return true;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %r14
movl $0x1, %edi
movq %r14, %rsi
callq 0x8560
movq (%r14), %rdx
subq 0x438(%rbx), %rdx
movq 0x8(%r14), %rsi
leaq 0x3b9aca00(%rsi), %rcx
movq 0x440(%rbx), %rdi
movq 0x478(%rbx), %rax
xorl %r8d, %r8d
cmpq %rdi, %rsi
cmovgeq %rsi, %rcx
setl %r8b
subq %rdi, %rcx
subq %r8, %rdx
subq %rdx, %rax
jl 0x265f9
setne %sil
movq 0x480(%rbx), %rdx
cmpq %rcx, %rdx
setg %dil
orb %sil, %dil
je 0x265f9
leaq 0x3b9aca00(%rdx), %rdi
xorl %esi, %esi
cmpq %rcx, %rdx
setl %sil
cmovgeq %rdx, %rdi
subq %rcx, %rdi
subq %rsi, %rax
movl 0x3fc(%rbx), %r9d
xorps %xmm0, %xmm0
movq %rsp, %rcx
movaps %xmm0, (%rcx)
leaq 0x3d0(%rbx), %rsi
leaq 0x28(%rsp), %rdx
movq %rax, (%rdx)
movq %rdi, 0x8(%rdx)
leaq 0x2044b(%rip), %rdi     # 0x46a30
movl $0x1, %r8d
callq 0xd65c
orb $0x1, 0x4f4(%rbx)
jmp 0x26601
movq %rbx, %rdi
callq 0x27740
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::bring_up()
bool base_process_service::bring_up() noexcept
{
    if (!open_socket()) {
        return false;
    }

    bool start_success;
    if (in_auto_restart) {
        start_success = restart_ps_process();
    }
    else {
        restart_interval_count = 0;
        start_success = start_ps_process(exec_arg_parts,
                onstart_flags.starts_on_console || onstart_flags.shares_console);
        // start_ps_process updates last_start_time, use it also for restart_interval_time:
        restart_interval_time = last_start_time;

        // Arm start timer. (For restarts, this is only done once the restart interval expires).
        if (start_success) {
            if (start_timeout != time_val(0,0)) {
                process_timer.arm_timer_rel(event_loop, start_timeout);
                waiting_stopstart_timer = true;
            }
            else if (waiting_stopstart_timer) {
                process_timer.stop_timer(event_loop);
                waiting_stopstart_timer = false;
            }
        }
    }

    return start_success;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x26700
testb %al, %al
je 0x266b9
testb $0x2, 0x10e(%rbx)
jne 0x266bd
movl $0x0, 0x458(%rbx)
leaq 0x218(%rbx), %rsi
movzwl 0x2e(%rbx), %eax
xorl %edx, %edx
testb $0x18, %al
setne %dl
movq %rbx, %rdi
callq 0x26974
movups 0x438(%rbx), %xmm0
movups %xmm0, 0x448(%rbx)
testb %al, %al
je 0x266b9
movq 0x498(%rbx), %rax
movq 0x4a0(%rbx), %rdi
movq %rax, %rcx
orq %rdi, %rcx
je 0x266d1
movl 0x3fc(%rbx), %r9d
xorps %xmm0, %xmm0
movq %rsp, %rcx
movaps %xmm0, (%rcx)
leaq 0x3d0(%rbx), %rsi
leaq 0x18(%rsp), %rdx
movq %rax, (%rdx)
movq %rdi, 0x8(%rdx)
leaq 0x2038b(%rip), %rdi     # 0x46a30
movl $0x1, %r8d
callq 0xd65c
orb $0x2, 0x4f4(%rbx)
jmp 0x266c5
xorl %ebp, %ebp
jmp 0x266c8
movq %rbx, %rdi
callq 0x26532
movb $0x1, %bpl
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %rbp
retq
movb $0x1, %bpl
testb $0x2, 0x4f4(%rbx)
je 0x266c8
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x2033f(%rip), %rdi     # 0x46a30
callq 0x25f62
andb $-0x3, 0x4f4(%rbx)
jmp 0x266c8
nop
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::do_restart()
void base_process_service::do_restart() noexcept
{
    // Actually perform process restart. We may be in smooth recovery (state = STARTED) or this may
    // be a regular restart.

    waiting_restart_timer = false;
    auto service_state = get_state();

    if (!start_ps_process(exec_arg_parts, have_console || onstart_flags.shares_console)) {
        if (service_state == service_state_t::STARTING) {
            failed_to_start();
        }
        else {
            // smooth recovery failure
            unrecoverable_stop();
        }
        services->process_queues();
    }
    else {
        // started process successfully (at least as far as fork)
        if (start_timeout != time_val(0,0)) {
            process_timer.arm_timer_rel(event_loop, start_timeout);
            waiting_stopstart_timer = true;
        }
    }
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
andb $-0x2, 0x4f4(%rdi)
movb 0x2c(%rdi), %bpl
leaq 0x218(%rdi), %rsi
movl 0x10c(%rdi), %eax
andl $0x40, %eax
shrl $0x6, %eax
movzwl 0x2e(%rdi), %edx
andl $0x10, %edx
shrl $0x4, %edx
orl %eax, %edx
callq 0x26974
testb %al, %al
je 0x277d5
movq 0x498(%rbx), %rax
movq 0x4a0(%rbx), %rdi
movq %rax, %rcx
orq %rdi, %rcx
je 0x277ce
movl 0x3fc(%rbx), %r9d
xorps %xmm0, %xmm0
movq %rsp, %rcx
movaps %xmm0, (%rcx)
leaq 0x3d0(%rbx), %rsi
leaq 0x18(%rsp), %rdx
movq %rax, (%rdx)
movq %rdi, 0x8(%rdx)
leaq 0x1f274(%rip), %rdi     # 0x46a30
movl $0x1, %r8d
callq 0xd65c
orb $0x2, 0x4f4(%rbx)
addq $0x28, %rsp
popq %rbx
popq %rbp
retq
movq %rbx, %rdi
cmpb $0x1, %bpl
jne 0x277ec
xorl %esi, %esi
movl $0x1, %edx
callq 0x23316
jmp 0x277f1
callq 0x23762
movq 0x148(%rbx), %rdi
addq $0x28, %rsp
popq %rbx
popq %rbp
jmp 0xd37e
nop
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::interrupt_start()
bool base_process_service::interrupt_start() noexcept
{
    if (waiting_restart_timer) {
        process_timer.stop_timer(event_loop);
        waiting_restart_timer = false;
        return service_record::interrupt_start();
    }
    else {
        log(loglevel_t::WARN, "Interrupting start of service ", get_name(), " with pid ", pid,
                " (with SIGINT).");
        kill_pg(SIGINT);

        if (stop_timeout != time_val(0,0)) {
            process_timer.arm_timer_rel(event_loop, stop_timeout);
            waiting_stopstart_timer = true;
        }
        else if (waiting_stopstart_timer) {
            process_timer.stop_timer(event_loop);
            waiting_stopstart_timer = false;
        }

        set_state(service_state_t::STOPPING);
        return false;
    }
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
testb $0x1, 0x4f4(%rdi)
je 0x27846
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x1f205(%rip), %rdi     # 0x46a30
callq 0x25f62
andb $-0x2, 0x4f4(%rbx)
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x23c36
leaq 0xe71e(%rip), %rsi      # 0x35f6b
movl $0x2, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0xe37f(%rip), %rdi      # 0x35be6
callq 0x2e520
movl 0x4d8(%rbx), %ecx
leaq 0xef33(%rip), %rdx      # 0x367ac
movq %rsp, %r14
movl $0xc, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e520
leaq 0xe6f0(%rip), %rdi      # 0x35f8a
callq 0x2e53c
movq %rbx, %rdi
movl $0x2, %esi
callq 0x27940
movq 0x488(%rbx), %rax
movq 0x490(%rbx), %rdi
movq %rax, %rcx
orq %rdi, %rcx
je 0x27901
movl 0x3fc(%rbx), %r9d
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rcx
movaps %xmm0, (%rcx)
leaq 0x3d0(%rbx), %rsi
movq %rsp, %rdx
movq %rax, (%rdx)
movq %rdi, 0x8(%rdx)
leaq 0x1f144(%rip), %rdi     # 0x46a30
movl $0x1, %r8d
callq 0xd65c
movb 0x4f4(%rbx), %al
orb $0x2, %al
jmp 0x2792b
testb $0x2, 0x4f4(%rbx)
je 0x27931
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x1f112(%rip), %rdi     # 0x46a30
callq 0x25f62
movb 0x4f4(%rbx), %al
andb $-0x3, %al
movb %al, 0x4f4(%rbx)
movb $0x3, 0x2c(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/baseproc-service.cc
// Function: base_process_service::kill_pg(int)
void base_process_service::kill_pg(int signo) noexcept
{
    if (onstart_flags.signal_process_only) {
        bp_sys::kill(pid, signo);
    }
    else {
        pid_t pgid = bp_sys::getpgid(pid);
        if (pgid == -1) {
            // On some OSes (eg OpenBSD) we aren't allowed to get the pgid of a process in a different
            // session. If the process is in a different session, however, it must be a process group
            // leader and the pgid must equal the process id.
            pgid = pid;
        }
        bp_sys::kill(-pgid, signo);
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
testb $0x2, 0x2f(%rdi)
movl 0x4d8(%rdi), %edi
jne 0x2796a
callq 0x8ae0
movl %eax, %edi
cmpl $-0x1, %eax
jne 0x27968
movl 0x4d8(%r14), %edi
negl %edi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x88d0
// File: /workspace/github_cpp_makefile_star2_O3/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 0x279fa
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0xe0bd(%rip), %rsi      # 0x35a4f
movl $0x2, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0xe23a(%rip), %rdi      # 0x35be6
callq 0x2e520
movl 0x4d8(%rbx), %ecx
leaq 0xedee(%rip), %rdx      # 0x367ac
leaq 0xc(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e520
leaq 0xe211(%rip), %rdi      # 0x35bf2
callq 0x2e53c
movq %rbx, %rdi
movl $0x9, %esi
callq 0x27940
addq $0x18, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdi, %rbx
andb $-0x3, 0x4f4(%rdi)
cmpb $0x3, 0x2c(%rdi)
jne 0x27a26
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
jmpq *0x88(%rax)
cmpl $-0x1, 0x4d8(%rbx)
je 0x27ab5
leaq 0xe015(%rip), %rsi      # 0x35a4f
movl $0x2, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0xe192(%rip), %rdi      # 0x35be6
callq 0x2e520
movl 0x4d8(%rbx), %ecx
leaq 0xed46(%rip), %rdx      # 0x367ac
leaq 0xc(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e520
leaq 0xe511(%rip), %rdi      # 0x35f9a
callq 0x2e53c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movl $0x5, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x23316
addq $0x18, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x27740
// File: /workspace/github_cpp_makefile_star2_O3/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 0x280a1
movl %ebp, %eax
addq %r15, %rax
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x2dedc
movq %rax, %rdi
movq %r14, %rsi
callq 0x8060
incq 0x500(%rbx)
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 0x81e0
movq %rax, %rcx
cmpl $-0x1, %ecx
je 0x280c8
movb $0x1, %al
subl %ecx, %ebp
je 0x28094
movslq %ecx, %rax
addq %rax, %r15
movq %r15, (%rsp)
jmp 0x28062
callq 0x8050
movl (%rax), %edi
cmpl $0x4, %edi
je 0x28062
cmpl $0xb, %edi
je 0x28062
cmpl $0x20, %edi
je 0x280ff
callq 0x81d0
movq %rax, %rbx
leaq 0xe3c5(%rip), %rsi      # 0x364b2
movl $0x2, %edi
callq 0x2e412
movq %rbx, %rdi
callq 0x2e53c
xorl %eax, %eax
jmp 0x28094
cmpl $0x2, %edx
jne 0x28123
movq %rax, %rdi
callq 0x8210
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a50
movl %r12d, %eax
jmp 0x28094
movq %rax, %rdi
callq 0xb74e
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x484(%rdi)
ja 0x28a37
movl $0x5, 0x7c(%rbx)
movb $0x1, %al
jmp 0x28b31
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r15d
leal 0x1(%r15), %eax
addl $0xfffffc01, %r15d      # imm = 0xFFFFFC01
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x28aa2
movl $0x400, %r13d           # imm = 0x400
subl %r15d, %r13d
movl %r15d, %esi
addq %r14, %rsi
leaq 0xc(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0xc, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x28aab
movl %r15d, %eax
addq %rax, %r14
movq %r14, %r12
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2b906
testq %rax, %rax
je 0x28b14
movq %rax, %rdi
callq 0x23b0e
movq 0x70(%rbx), %rdi
callq 0xd37e
leaq 0xa(%rsp), %rsi
movb $0x32, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x28b31
movl 0x480(%rbx), %ecx
leal 0x5(%rcx), %edx
addl $0xfffffc05, %ecx       # imm = 0xFFFFFC05
cmpl $0x400, %edx            # imm = 0x400
cmovbl %edx, %ecx
movl %ecx, 0x480(%rbx)
addl $-0x5, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
jmp 0x28b31
leaq 0xb(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x28b31
movb $0x1, 0x78(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl 0x484(%rdi), %ebp
cmpl $0x4, %ebp
ja 0x292a8
movl $0x5, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x293ea
leaq 0x80(%rbx), %r12
movl 0x480(%rbx), %r14d
leal 0x1(%r14), %eax
leal -0x3ff(%r14), %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x2931a
movl $0x400, %r13d           # imm = 0x400
subl %r15d, %r13d
movl %r15d, %esi
addq %r12, %rsi
movq %r12, 0x8(%rsp)
leaq 0x4(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0x4, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x29320
movl %r15d, %eax
addq %rax, %r12
movl (%r12), %esi
leal 0x5(%r14), %eax
addl $0xfffffc05, %r14d      # imm = 0xFFFFFC05
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r14d
movl %r14d, 0x480(%rbx)
addl $-0x5, %ebp
movl %ebp, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movq %rbx, %rdi
callq 0x2b906
testq %rax, %rax
je 0x29369
movq %rax, %r14
cmpq $0x10000, 0x10(%rax)    # imm = 0x10000
jb 0x29382
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
movl %eax, %ebx
jmp 0x293ea
movl $0xc, %edi
callq 0x8600
movq %rax, %r15
movq %rax, 0x10(%rsp)
addq $0xc, %rax
movq %rax, 0x20(%rsp)
leaq 0x2(%r15), %rdi
movq $0x0, 0x2(%r15)
movw $0x0, 0xa(%r15)
movq %rax, 0x18(%rsp)
movw $0x46, (%r15)
movq %r14, %rsi
callq 0x2b017
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2acb2
movl %eax, %ebx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x293ea
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0xc, %esi
movq %r15, %rdi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl 0x484(%rdi), %ebp
cmpl $0x4, %ebp
ja 0x2943e
movl $0x5, 0x7c(%rbx)
movb $0x1, %bl
jmp 0x2957b
leaq 0x80(%rbx), %r12
movl 0x480(%rbx), %r14d
leal 0x1(%r14), %eax
leal -0x3ff(%r14), %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x294b0
movl $0x400, %r13d           # imm = 0x400
subl %r15d, %r13d
movl %r15d, %esi
addq %r12, %rsi
movq %r12, 0x8(%rsp)
leaq 0x4(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0x4, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x294b6
movl %r15d, %eax
addq %rax, %r12
movl (%r12), %esi
leal 0x5(%r14), %eax
addl $0xfffffc05, %r14d      # imm = 0xFFFFFC05
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r14d
movl %r14d, 0x480(%rbx)
addl $-0x5, %ebp
movl %ebp, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movq %rbx, %rdi
callq 0x2b906
testq %rax, %rax
je 0x294ff
movq %rax, %r14
cmpq $0x10000, 0x10(%rax)    # imm = 0x10000
jb 0x29518
leaq 0x10(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
movl %eax, %ebx
jmp 0x2957b
movl $0x10, %edi
callq 0x8600
movq %rax, %r15
movq %rax, 0x10(%rsp)
addq $0x10, %rax
movq %rax, 0x20(%rsp)
leaq 0x2(%r15), %rdi
xorl %ecx, %ecx
movq %rcx, 0x2(%r15)
movq %rcx, 0x8(%r15)
movq %rax, 0x18(%rsp)
movw $0x46, (%r15)
movq %r14, %rsi
callq 0x2b0bd
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2acb2
movl %eax, %ebx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2957b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x10, %esi
movq %r15, %rdi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x480(%rdi), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x480(%rdi)
decl 0x484(%rdi)
leaq 0x8(%rdi), %rax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movl $0x98, %edi
addq 0x1bac7(%rip), %rdi     # 0x45f70
leaq 0x8(%rsp), %r14
movq %rdi, (%r14)
movq %r14, %rdx
callq 0x2c464
movb $0x32, (%r14)
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
addq $0x18, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x484(%rdi), %ebp
cmpl $0x5, %ebp
ja 0x2a502
movl $0x6, 0x7c(%rbx)
movb $0x1, %al
jmp 0x2a669
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r13d
leal 0x1(%r13), %eax
leal -0x3ff(%r13), %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x3fd(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x2a56a
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x84d0
leaq (%rsp,%r12), %rdi
addq $0x10, %rdi
addl $0xfffffc04, %r15d      # imm = 0xFFFFFC04
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x2a575
movl %r15d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x10(%rsp)
leal 0x5(%r13), %eax
leal -0x3fb(%r13), %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
leal -0x400(%r15), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0x2a5cf
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0xf(%rsp), %rdi
movq %r12, %rdx
callq 0x84d0
leaq (%rsp,%r12), %rdi
addq $0xf, %rdi
addl $0xfffffc01, %r15d      # imm = 0xFFFFFC01
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x2a5da
movl %r15d, %eax
movb (%r14,%rax), %al
movb %al, 0xf(%rsp)
leal 0x6(%r13), %eax
addl $0xfffffc06, %r13d      # imm = 0xFFFFFC06
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r13d
movl %r13d, 0x480(%rbx)
addl $-0x6, %ebp
movl %ebp, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
movl 0x10(%rsp), %esi
movq %rbx, %rdi
callq 0x2b906
testq %rax, %rax
je 0x2a654
cmpl $0x5, 0x28(%rax)
jne 0x2a654
cmpb $0x0, 0xf(%rsp)
setne 0x208(%rax)
je 0x2a641
cmpb $0x1, 0x2c(%rax)
jne 0x2a641
testb $0x10, 0x10c(%rax)
jne 0x2a641
movq %rax, %rdi
callq 0x23690
movq 0x70(%rbx), %rdi
callq 0xd37e
leaq 0x16(%rsp), %rsi
movb $0x32, (%rsi)
jmp 0x2a65c
leaq 0x17(%rsp), %rsi
movb $0x33, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2acfd
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2df74
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
movl $0x0, 0x50c(%rbx)
movl 0x2c(%rbx), %edi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
subq %rsi, %rdx
callq 0x81e0
cmpl $-0x1, %eax
je 0x2ad36
movl %eax, %edx
movq 0x8(%r14), %rsi
subq (%r14), %rsi
movb $0x1, %cl
cmpq %rsi, %rdx
je 0x2acf0
movl %eax, 0x50c(%rbx)
jmp 0x2acd3
callq 0x8050
movl (%rax), %edi
cmpl $0x4, %edi
je 0x2acd3
cmpl $0xb, %edi
je 0x2acd3
cmpl $0x20, %edi
je 0x2ad6d
callq 0x81d0
movq %rax, %rbx
leaq 0xb757(%rip), %rsi      # 0x364b2
movl $0x2, %edi
callq 0x2e412
movq %rbx, %rdi
callq 0x2e53c
xorl %ecx, %ecx
jmp 0x2acf0
cmpl $0x2, %edx
jne 0x2ad93
movq %rax, %rdi
callq 0x8210
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a50
movl %ebp, %ecx
jmp 0x2acf0
movq %rax, %rdi
callq 0xb74e
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rsi, 0x8(%rsp)
movq 0x4d8(%rdi), %rax
leaq 0x4c8(%rdi), %r14
xorl %ebp, %ebp
cmpq %r14, %rax
je 0x2add8
cmpl 0x20(%rax), %ebp
jne 0x2add8
incl %ebp
movq %rax, %rdi
callq 0x8420
jmp 0x2adc2
leaq 0x4c0(%rbx), %r14
movl %ebp, 0x4(%rsp)
leaq 0x488(%rbx), %r12
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2ce70
movq %rax, %r15
testq %rax, %rax
jne 0x2ae1e
movl $0x150, %edi            # imm = 0x150
addq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x2c812
movq 0x8(%rsp), %r13
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x2bca6
movq %r13, (%rax)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movl %ecx, 0x8(%rdx)
movq %r12, %rdi
xorl %esi, %esi
callq 0x2db9c
movl 0x4(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ae66
movq %rax, %rdi
callq 0x8210
testq %r15, %r15
jne 0x2ae80
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2b8e6
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x2bb44
callq 0x8a50
jmp 0x2ae51
movq %rax, %rbx
callq 0x8a50
movq %rbx, %rdi
callq 0x8ab0
movq %rax, %rdi
callq 0xb74e
// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x130(%rsi), %r14
addq $0x130, %r15            # imm = 0x130
cmpq %r15, %r14
je 0x2af8a
movq %rdi, %rbx
movq %rdx, 0x20(%rsp)
xorl %r13d, %r13d
movq 0x10(%r14), %rax
cmpl $0x0, 0x14(%rax)
jne 0x2af5f
cmpb $0x1, 0x11(%rax)
jne 0x2af5f
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2ad9c
movl %eax, %ebp
movq (%rsp), %rax
movq 0x8(%rsp), %r12
cmpq %r12, %rax
jne 0x2af44
movl $0xd, %esi
movq %rsp, %rdi
callq 0x2b854
movl $0x9, %esi
movq %rsp, %rdi
callq 0x1c190
movq (%rsp), %rax
movb $0x41, (%rax)
movq (%rsp), %rax
movq 0x8(%rsp), %r12
subq %rax, %r12
leaq 0x4(%r12), %rsi
movq %rsp, %rdi
callq 0x1c190
incq %r13
movq (%rsp), %rax
movl %ebp, (%rax,%r12)
movq (%r14), %r14
cmpq %r15, %r14
jne 0x2aeef
testq %r13, %r13
movq 0x20(%rsp), %rdx
je 0x2af8a
movb $0x1, (%rdx)
movq %rsp, %rsi
movq (%rsi), %rax
movq %r13, 0x1(%rax)
movq %rbx, %rdi
callq 0x2acb2
movl %eax, %ebx
jmp 0x2af8f
movb $0x0, (%rdx)
movb $0x1, %bl
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2afa5
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2afb8
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2afd1
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
// File: /workspace/github_cpp_makefile_star2_O3/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
movb %cl, 0x3(%rbx)
movw $0x0, 0x4(%rbx)
cmpl $-0x1, %eax
je 0x2b085
movl %eax, 0x6(%rbx)
jmp 0x2b0b5
cmpb $0x4, %cl
jne 0x2b09e
movq 0x4f8(%r14), %rax
movw %ax, 0x4(%rbx)
shrq $0x20, %rax
movl %eax, 0x6(%rbx)
jmp 0x2b0b5
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
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/control.cc
// Function: fill_status_buffer5(char*, service_record*)
static void fill_status_buffer5(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));
        unsigned remains = STATUS_BUFFER5_SIZE - (6 + sizeof(proc_pid));
        memset(buffer + 6 + sizeof(proc_pid), 0, remains);
    }
    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));
            unsigned remains = STATUS_BUFFER5_SIZE - (6 + sizeof(int));
            memset(buffer + 6 + sizeof(proc_pid), 0, remains);
        }
        else {
            auto exit_status = service->get_exit_status();
            int xs_si_code = exit_status.get_si_code();
            int xs_si_status = exit_status.get_si_status();
            memcpy(buffer + 6, &xs_si_code, sizeof(xs_si_code));
            memcpy(buffer + 6 + sizeof(xs_si_code), &xs_si_status, sizeof(xs_si_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)
movl 0x10c(%r14), %ecx
movl %ecx, %edx
shrb $0x5, %dl
movl %ecx, %esi
shrl $0xe, %esi
andb $0x4, %sil
shrl $0x5, %ecx
andb $0x8, %cl
cmpl $-0x1, %eax
setne %dil
shlb $0x4, %dil
andb $0x3, %dl
orb %dil, %dl
orb %sil, %dl
orb %cl, %dl
xorl %ecx, %ecx
movb %dl, 0x2(%rbx)
movb 0x1c4(%r14), %dl
movb %dl, 0x3(%rbx)
movw $0x0, 0x4(%rbx)
cmpl $-0x1, %eax
jne 0x2b14c
cmpb $0x4, %dl
jne 0x2b13c
movq 0x4f8(%r14), %rax
movw %ax, 0x4(%rbx)
shrq $0x20, %rax
jmp 0x2b14c
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
movq %rax, %rcx
shrq $0x20, %rcx
movl %eax, 0x6(%rbx)
movl %ecx, 0xa(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::environ_event(environment*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
void control_conn_t::environ_event(environment *env, std::string const &var_and_val, bool overridden) noexcept
{
    // packet type (byte) + packet length (byte) + flags byte + data size + data
    // flags byte can be 1 or 0 for now, 1 if the var was overridden and 0 if fresh
    constexpr int pktsize = 3 + sizeof(envvar_len_t);
    envvar_len_t ln = var_and_val.size() + 1;
    auto *ptr = var_and_val.data();

    try {
        std::vector<char> pkt;
        pkt.reserve(pktsize + ln);
        pkt.push_back((char)cp_info::ENVEVENT);
        pkt.push_back(pktsize);
        pkt.push_back(overridden ? 1 : 0);
        pkt.insert(pkt.end(), (char *)&ln, ((char *)&ln) + sizeof(envvar_len_t));
        pkt.insert(pkt.end(), ptr, ptr + ln);
        queue_packet(std::move(pkt));
    } catch (std::bad_alloc &exc) {
        do_oom_close();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebp
movq %rdi, %rbx
movl 0x8(%rdx), %eax
incl %eax
movw %ax, 0xe(%rsp)
movq (%rdx), %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movzwl %ax, %esi
addq $0x5, %rsi
callq 0x2b854
leaq 0xd(%rsp), %rsi
movb $0x66, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2cbf6
leaq 0xd(%rsp), %rsi
movb $0x5, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2cbf6
leaq 0xd(%rsp), %rsi
movb %bpl, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2cbf6
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
leaq 0x10(%rsp), %rcx
leaq 0xe(%rsp), %rdx
callq 0x2d7b0
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
movzwl 0xe(%rsp), %ecx
addq %r14, %rcx
movq %r14, %rdx
callq 0x2d5c8
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2acb2
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2b451
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b466
jmp 0x2b466
jmp 0x2b466
jmp 0x2b466
jmp 0x2b466
movq %rdx, %r15
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2b483
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %r14, %rdi
cmpl $0x2, %r15d
jne 0x2b4a1
callq 0x8210
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a50
jmp 0x2b451
movq %rax, %rdi
callq 0xb74e