LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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
movb %dl, 0x2(%rbx)
movb 0x1c4(%r14), %dl
andw $0x0, 0x4(%rbx)
xorl %ecx, %ecx
movb %dl, 0x3(%rbx)
cmpl $-0x1, %eax
jne 0x257b9
cmpb $0x4, %dl
jne 0x257a9
movq 0x4f8(%r14), %rax
movw %ax, 0x4(%rbx)
shrq $0x20, %rax
jmp 0x257b9
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
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0x10(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movzwl %ax, %esi
addq $0x5, %rsi
callq 0x25f74
leaq 0xd(%rsp), %rsi
movb $0x66, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
leaq 0xd(%rsp), %rsi
movb $0x5, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
leaq 0xd(%rsp), %rsi
movb %bpl, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x274c6
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
leaq 0x10(%rsp), %rcx
leaq 0xe(%rsp), %rdx
callq 0x263c8
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
movzwl 0xe(%rsp), %ecx
addq %r14, %rcx
movq %r14, %rdx
callq 0x26370
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x253ac
movq %r14, %rdi
callq 0xc3e8
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25a6a
jmp 0x25a6a
jmp 0x25a6a
jmp 0x25a6a
jmp 0x25a6a
movq %rdx, %r15
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xc3e8
movq %r14, %rdi
cmpl $0x2, %r15d
jne 0x25a98
callq 0x8200
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a40
jmp 0x25a55
movq %rax, %rdi
callq 0xaebb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::data_ready()
bool control_conn_t::data_ready() noexcept
{
    int fd = iob.get_watched_fd();
    
    int r = rbuf.fill(fd);
    
    // Note file descriptor is non-blocking
    if (r == -1) {
        if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
            if (errno != ECONNRESET) {
                log(loglevel_t::WARN, "Error reading from control connection: ", strerror(errno));
            }
            return true;
        }
        return false;
    }
    
    if (r == 0) {
        return true;
    }
    
    // complete packet?
    while (rbuf.get_length() >= chklen) {
        try {
            if (!process_packet() || bad_conn_close) {
                return false;
            }
        }
        catch (std::bad_alloc &baexc) {
            do_oom_close();
            return false;
        }

        chklen = std::max(chklen, 1u);
    }

    if (rbuf.get_length() == rbuf.get_size()) {
        // Too big packet
        log(loglevel_t::WARN, "Received too-large control packet; dropping connection");
        bad_conn_close = true;
    }
    
    return false;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x2c(%rdi), %esi
addq $0x80, %rdi
callq 0x264b4
movb $0x1, %bpl
cmpl $-0x1, %eax
je 0x25b12
testl %eax, %eax
je 0x25b66
movl 0x7c(%rbx), %eax
movl 0x484(%rbx), %ecx
cmpl %eax, %ecx
jb 0x25b49
movq %rbx, %rdi
callq 0x23278
testb %al, %al
je 0x25b64
cmpb $0x0, 0x78(%rbx)
jne 0x25b64
movl 0x7c(%rbx), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, 0x7c(%rbx)
jmp 0x25ae8
callq 0x8040
movl (%rax), %edi
cmpl $0x4, %edi
je 0x25b64
cmpl $0xb, %edi
je 0x25b64
cmpl $0x68, %edi
je 0x25b66
callq 0x81c0
movq %rax, %rbx
leaq 0xa9a9(%rip), %rsi      # 0x304e0
pushq $0x2
popq %rdi
callq 0x28e0a
movq %rbx, %rdi
callq 0x28f31
jmp 0x25b66
cmpl $0x400, %ecx            # imm = 0x400
jne 0x25b64
leaq 0xa9b0(%rip), %rsi      # 0x30508
pushq $0x2
popq %rdi
callq 0x28d42
movb $0x1, 0x78(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpl $0x2, %edx
jne 0x25b89
movq %rax, %rdi
callq 0x8200
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a40
jmp 0x25b64
movq %rax, %rdi
callq 0xaebb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::send_data()
bool control_conn_t::send_data() noexcept
{
    if (outbuf.empty() && bad_conn_close) {
        if (oom_close) {
            // Send oom response
            char oomBuf[] = { (char)cp_rply::OOM };
            bp_sys::write(iob.get_watched_fd(), oomBuf, 1);
        }
        return true;
    }
    
    vector<char> & pkt = outbuf.front();
    char *data = pkt.data();
    int written = bp_sys::write(iob.get_watched_fd(), data + outpkt_index, pkt.size() - outpkt_index);
    if (written == -1) {
        if (errno == EPIPE) {
            // read end closed
            return true;
        }
        else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
            // spurious readiness notification?
            return false;
        }
        else {
            log(loglevel_t::ERROR, "Error writing to control connection: ", strerror(errno));
            return true;
        }
    }

    outpkt_index += written;
    if (outpkt_index == pkt.size()) {
        // We've finished this packet, move on to the next:
        outbuf_size -= pkt.size();
        outbuf.pop_front();
        outpkt_index = 0;
        if (oom_close) {
            // remain active, try to send cp_rply::OOM shortly
            return false;
        }
        if (outbuf.empty() && bad_conn_close) {
            return true;
        }
    }
    
    // more to send
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x4f0(%rdi), %r14
movq 0x4f0(%rdi), %r15
cmpq %r14, %r15
jne 0x25bd6
cmpb $0x1, 0x78(%rbx)
jne 0x25bd6
movb $0x1, %bpl
cmpb $0x1, 0x79(%rbx)
jne 0x25c53
movl 0x2c(%rbx), %edi
leaq 0xa874(%rip), %rsi      # 0x30440
pushq $0x1
popq %rdx
callq 0x81d0
jmp 0x25c53
movl 0x2c(%rbx), %edi
movl 0x50c(%rbx), %esi
addq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
subq %rsi, %rdx
callq 0x81d0
cmpl $-0x1, %eax
je 0x25c38
addl 0x50c(%rbx), %eax
movl %eax, 0x50c(%rbx)
movq 0x18(%r15), %rcx
subq 0x10(%r15), %rcx
cmpq %rax, %rcx
jne 0x25c51
subl %eax, 0x508(%rbx)
movq %r14, %rdi
callq 0x26508
andl $0x0, 0x50c(%rbx)
cmpb $0x0, 0x79(%rbx)
jne 0x25c51
cmpq %r14, (%r14)
jne 0x25c51
movb $0x1, %bpl
cmpb $0x0, 0x78(%rbx)
je 0x25c51
jmp 0x25c53
callq 0x8040
movl (%rax), %edi
cmpl $0x4, %edi
je 0x25c51
movb $0x1, %bpl
cmpl $0x20, %edi
je 0x25c53
cmpl $0xb, %edi
jne 0x25c60
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x81c0
movq %rsp, %rsi
movq %rax, (%rsi)
pushq $0x3
popq %rdi
callq 0x25aa7
jmp 0x25c53
movq %rax, %rdi
callq 0xaebb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::~control_conn_t()
control_conn_t::~control_conn_t() noexcept
{
    int fd = iob.get_watched_fd();
    iob.deregister(loop);
    bp_sys::close(fd);
    
    // Clear service listeners
    for (auto p : service_key_map) {
        p.first->remove_listener(this);
    }
    main_env.remove_listener(this);
    
    active_control_conns--;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x1ef69(%rip), %rax     # 0x44bf8
movq %rax, (%rdi)
leaq 0x1ef8f(%rip), %rax     # 0x44c28
movq %rax, 0x8(%rdi)
addq $0x10, %rdi
movl 0x2c(%rbx), %ebp
movq 0x68(%rbx), %rsi
callq 0x26510
movl %ebp, %edi
callq 0x8b50
leaq 0x8(%rbx), %r14
leaq 0x498(%rbx), %r15
movq (%r15), %r15
testq %r15, %r15
je 0x25cd5
movq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x26036
jmp 0x25cbf
leaq 0x488(%rbx), %r15
leaq 0x2212d(%rip), %rdi     # 0x47e10
movq %r14, %rsi
callq 0x26522
leaq 0x1feaa(%rip), %rax     # 0x45b9c
decl (%rax)
leaq 0x4f0(%rbx), %rdi
callq 0xc3a8
addq $0x4c0, %rbx            # imm = 0x4C0
movq %rbx, %rdi
callq 0xc414
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xc46c
movq %rax, %rdi
callq 0xaebb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/includes/service.h
// Function: service_record::has_lone_ref(bool)
bool has_lone_ref(bool check_deps = true) noexcept
    {
        if (check_deps) {
            for (auto *dept : dependents) {
                // BEFORE links don't count because they are actually specified via the "to" service i.e.
                // this service. AFTER links don't count because, although they come from the dependent,
                // they do not reflect an actual dependency, just an ordering, and this service can still
                // be unloaded if they exist (and replaced with a placeholder).
                if (!value(dept->dep_type).is_in(dependency_type::BEFORE, dependency_type::AFTER)) {
                    return false;
                }
            }
        }
        auto i = listeners.begin();
        return (++i == listeners.end());
    }

// Assembly:
testl %esi, %esi
je 0x260d2
leaq 0x130(%rdi), %rax
movq %rax, %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
je 0x260d2
movq 0x10(%rcx), %rdx
movl 0x14(%rdx), %edx
andl $-0x2, %edx
cmpl $0x4, %edx
je 0x260b8
xorl %eax, %eax
retq
movq 0x160(%rdi), %rax
cmpq $0x0, (%rax)
sete %al
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/includes/service.h
// Function: service_record::rm_dep(service_record*, dependency_type)
bool rm_dep(service_record *to, dependency_type dep_type) noexcept
    {
        for (auto i = depends_on.begin(); i != depends_on.end(); ++i) {
            auto & dep = *i;
            if (dep.get_to() == to && dep.dep_type == dep_type) {
                rm_dep(i);
                return true;
            }
        }
        return false;
    }

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0x118(%rdi), %r14
movq %r14, %rbx
movq (%rbx), %rbx
cmpq %r14, %rbx
je 0x262bf
cmpq %rsi, 0x18(%rbx)
jne 0x262a4
cmpl %edx, 0x24(%rbx)
jne 0x262a4
movq %rbx, %rsi
callq 0x1b58c
cmpq %r14, %rbx
setne %al
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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_bidi_fd_watcher*, int)
void deregister(base_bidi_fd_watcher *callback, int fd) noexcept
    {
        if (backend_traits_t::has_separate_rw_fd_watches) {
            loop_mech.remove_bidi_fd_watch(fd);
        }
        else {
            loop_mech.remove_fd_watch(fd, callback->watch_flags);
        }
        
        waitqueue_node<T_Mutex> qnode;
        get_attn_lock(qnode);
        
        dispatch_t & ed = (dispatch_t &) loop_mech;
        ed.issue_delete(callback);
        
        release_lock(qnode);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x20(%rsi), %eax
movl %edx, %esi
movl %eax, %edx
callq 0xbf22
leaq 0xf(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xd0c0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x28ae2
movq %r14, %rdi
movq %r15, %rsi
callq 0xd0ec
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/../dasynq/include/dasynq.h
// Function: dasynq::v2::dprivate::event_dispatch<dasynq::v2::epoll_traits, dasynq::v2::default_traits<dasynq::null_mutex>>::issue_delete(dasynq::v2::dprivate::base_bidi_fd_watcher*)
void issue_delete(base_bidi_fd_watcher *watcher) noexcept
        {
            lock.lock();
            
            if (watcher->active) {
                watcher->deleteme = true;
                release_watcher(watcher);
            }
            else {
                dequeue_watcher(watcher);
                release_watcher(watcher);
                watcher->read_removed = true;
            }
            
            base_watcher *secondary = &(watcher->out_watcher);
            if (secondary->active) {
                secondary->deleteme = true;
                release_watcher(watcher);
            }
            else {
                dequeue_watcher(secondary);
                release_watcher(watcher);
                watcher->write_removed = true;
            }
            
            if (watcher->read_removed && watcher->write_removed) {
                lock.unlock();
                watcher->watch_removed();
            }
            else {
                lock.unlock();
            }
        }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movb 0xc(%rsi), %al
testb $0x1, %al
jne 0x28b11
movq %r14, %rdi
movq %rbx, %rsi
callq 0xbc92
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0xbf34
orb $0x1, 0x48(%rbx)
jmp 0x28b22
orb $0x2, %al
movb %al, 0xc(%rbx)
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0xbf34
movb 0x34(%rbx), %al
leaq 0x10(%rbx), %r15
testb $0x1, %al
jne 0x28b4e
leaq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0xbc92
movq %r14, %rdi
movq %r15, %rsi
callq 0xbf34
movb 0x48(%rbx), %al
orb $0x2, %al
movb %al, 0x48(%rbx)
jmp 0x28b61
orb $0x2, %al
movb %al, 0x34(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0xbf34
movb 0x48(%rbx), %al
notb %al
testb $0x3, %al
jne 0x28b75
movq (%rbx), %rax
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmpq *0x20(%rax)
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: enable_console_log(bool)
void enable_console_log(bool enable) noexcept
{
    bool log_to_console = ! log_stream[DLOG_CONS].is_release_set();
    if (enable && ! log_to_console) {
        // Set non-blocking IO:
        int flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
        fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
        // Activate watcher:
        log_stream[DLOG_CONS].init(STDOUT_FILENO);
        log_stream[DLOG_CONS].set_enabled(event_loop, true);
    }
    else if (! enable && log_to_console) {
        log_stream[DLOG_CONS].flush_for_release();
    }
}

// Assembly:
pushq %rax
movb 0x1e20c(%rip), %al      # 0x46dca
movl %eax, %ecx
andb %dil, %cl
cmpb $0x1, %cl
jne 0x28c13
pushq $0x1
popq %rdi
pushq $0x3
popq %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x8380
orl $0x800, %eax            # imm = 0x800
pushq $0x1
popq %rdi
pushq $0x4
popq %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x8380
movl $0x1, 0x1f1f3(%rip)     # 0x47de8
movb $0x0, 0x1e1ce(%rip)     # 0x46dca
leaq 0x1e19d(%rip), %rdi     # 0x46da0
leaq 0x1ce26(%rip), %rsi     # 0x45a30
pushq $0x1
popq %rdx
popq %rax
jmp 0xcf5c
orb %dil, %al
jne 0x28c4d
movb $0x1, 0x1e1ab(%rip)     # 0x46dca
movl 0x1f1c3(%rip), %esi     # 0x47de8
leaq 0x1e174(%rip), %rdi     # 0x46da0
callq 0x29168
cmpl $0x3, %eax
je 0x28c4f
cmpl $0x1, %eax
jne 0x28c4d
leaq 0x1e15e(%rip), %rdi     # 0x46da0
leaq 0x1cde7(%rip), %rsi     # 0x45a30
xorl %edx, %edx
jmp 0x28c0d
popq %rax
retq
leaq 0x1e14a(%rip), %rdi     # 0x46da0
leaq 0x1cdd3(%rip), %rsi     # 0x45a30
popq %rax
jmp 0xd002
movq %rax, %rdi
callq 0xaebb
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: discard_console_log_buffer()
void discard_console_log_buffer() noexcept
{
    // Only discard if more than a second has passed since we released the console.
    dasynq::time_val current_time;
    event_loop.get_time(current_time, clock_type::MONOTONIC);
    if (current_time - release_time >= dasynq::time_val(1, 0)) {
        log_stream[DLOG_CONS].discard();
    }
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
pushq $0x1
popq %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x8560
leaq 0x1d01f(%rip), %rsi     # 0x45d38
movq %rbx, %rdi
callq 0xe931
cmpq $0x1, %rax
jg 0x28d34
setne %al
testq %rdx, %rdx
sets %cl
orb %al, %cl
jne 0x28d3c
andq $0x0, 0x1f0a4(%rip)     # 0x47de0
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: void do_log<char const*, char const*, char const*>(loglevel_t, bool, char const*, char const*, char const*)
static void do_log(loglevel_t lvl, bool to_cons, T ... args) noexcept
{
    log_current_line[DLOG_CONS] = (lvl >= log_level[DLOG_CONS]) && to_cons;
    log_current_line[DLOG_MAIN] = (lvl >= log_level[DLOG_MAIN]);
    push_to_log(DLOG_CONS, args...);
    
    if (log_current_line[DLOG_MAIN]) {
        if (log_format_syslog[DLOG_MAIN]) {
            char svcbuf[10];
            snprintf(svcbuf, 10, "<%d>", LOG_DAEMON | log_level_to_syslog_level(lvl));
            push_to_log(DLOG_MAIN, svcbuf, args...);
        }
        else {
            push_to_log(DLOG_MAIN, args...);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movl %edi, %ebp
cmpl %edi, 0x1c96f(%rip)     # 0x456cc
setle %al
andb %sil, %al
cmpl %edi, 0x1c95f(%rip)     # 0x456c8
movb %al, 0x1f08a(%rip)      # 0x47df9
setle 0x1f082(%rip)           # 0x47df8
leaq 0x7833(%rip), %rsi      # 0x305b0
leaq 0x4d5f(%rip), %rcx      # 0x2dae3
pushq $0x1
popq %rdi
callq 0x2943f
cmpb $0x1, 0x1f065(%rip)     # 0x47df8
jne 0x28ddc
cmpb $0x1, 0x1c935(%rip)     # 0x456d1
jne 0x28de5
movl %ebp, %edi
callq 0x28e96
orl $0x18, %eax
leaq 0x7809(%rip), %rdx      # 0x305b8
leaq 0x6(%rsp), %r14
pushq $0xa
popq %rsi
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x89d0
leaq 0x77e6(%rip), %rsi      # 0x305b0
leaq 0x4d12(%rip), %rcx      # 0x2dae3
movq %r14, %rdi
movq %rbx, %rdx
callq 0x294c7
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x77c4(%rip), %rsi      # 0x305b0
leaq 0x4cf0(%rip), %rcx      # 0x2dae3
xorl %edi, %edi
movq %rbx, %rdx
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x2943f
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: log_msg_begin(loglevel_t, char const*)
void log_msg_begin(loglevel_t lvl, const char *msg) noexcept
{
    log_current_line[DLOG_CONS] = lvl >= log_level[DLOG_CONS];
    log_current_line[DLOG_MAIN] = lvl >= log_level[DLOG_MAIN];

    // Prepend the syslog priority level string ("<N>") for the main log:
    if (log_current_line[DLOG_MAIN]) {
        if (log_format_syslog[DLOG_MAIN]) {
            char svcbuf[10];
            snprintf(svcbuf, 10, "<%d>", LOG_DAEMON | log_level_to_syslog_level(lvl));
            do_log_part(DLOG_MAIN, svcbuf);
        }
    }

    for (int i = 0; i < DLOG_NUM; i++) {
        do_log_part(i, "dinit: ");
        do_log_part(i, msg);
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
cmpl %edi, 0x1c8b4(%rip)     # 0x456cc
setle 0x1efda(%rip)           # 0x47df9
movq %rsi, %rbx
cmpl %edi, 0x1c8a0(%rip)     # 0x456c8
setle 0x1efc9(%rip)           # 0x47df8
jg 0x28e67
cmpb $0x1, 0x1c899(%rip)     # 0x456d1
jne 0x28e67
callq 0x28e96
orl $0x18, %eax
leaq 0x776f(%rip), %rdx      # 0x305b8
leaq 0x6(%rsp), %r14
pushq $0xa
popq %rsi
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x89d0
xorl %edi, %edi
movq %r14, %rsi
callq 0x28eac
xorl %ebp, %ebp
leaq 0x7740(%rip), %r14      # 0x305b0
cmpl $0x2, %ebp
je 0x28e8d
movl %ebp, %edi
movq %r14, %rsi
callq 0x28eac
movl %ebp, %edi
movq %rbx, %rsi
callq 0x28eac
incl %ebp
jmp 0x28e70
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: do_log_part(int, char const*)
static void do_log_part(int idx, const char *arg) noexcept
{
    if (log_current_line[idx]) {
        int amount = sum_length(arg);
        if (log_stream[idx].get_free() >= amount) {
            append(log_stream[idx], arg);
        }
        else {
            // we have to discard the message
            log_stream[idx].rollback_msg();
            log_current_line[idx] = false;
            log_stream[idx].mark_discarded();
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %edi, %r14d
leaq 0x1ef3d(%rip), %r15     # 0x47df8
cmpb $0x1, (%r14,%r15)
jne 0x28f04
movq %rsi, %rbx
movq %rsi, %rdi
callq 0x8220
imulq $0x1050, %r14, %rcx     # imm = 0x1050
leaq 0x1ce75(%rip), %rdx     # 0x45d50
leaq (%rdx,%rcx), %rdi
movl $0x1000, %esi           # imm = 0x1000
subl 0x1040(%rcx,%rdx), %esi
cmpl %eax, %esi
jge 0x28f0a
movl 0x1044(%rdi), %eax
movl %eax, 0x1040(%rdi)
movb $0x0, (%r14,%r15)
movb $0x1, 0x29(%rdi)
popq %rbx
popq %r14
popq %r15
retq
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x293ea
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: log_msg_end(char const*)
void log_msg_end(const char *msg) noexcept
{
    for (int i = 0; i < DLOG_NUM; i++) {
        do_log_part(i, msg);
        do_log_part(i, "\n");
        do_log_commit(i);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0x1ce0c(%rip), %r14     # 0x45d50
xorl %r15d, %r15d
leaq 0x4b95(%rip), %r12      # 0x2dae3
leaq 0x1eea3(%rip), %r13     # 0x47df8
cmpq $0x2, %r15
je 0x28f8c
movl %r15d, %edi
movq %rbx, %rsi
callq 0x28eac
movl %r15d, %edi
movq %r12, %rsi
callq 0x28eac
cmpb $0x1, (%r15,%r13)
jne 0x28f80
movq %r14, %rdi
callq 0x29414
incq %r15
addq $0x1050, %r14           # imm = 0x1050
jmp 0x28f55
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: void do_log_main<char const*, char const*, char const*>(loglevel_t, char const*, char const*, char const*)
static void do_log_main(loglevel_t lvl, T ... args) noexcept
{
    if (lvl < log_level[DLOG_MAIN]) {
        return;
    }

    log_current_line[DLOG_CONS] = false;
    log_current_line[DLOG_MAIN] = true;

    if (log_format_syslog[DLOG_MAIN]) {
        char svcbuf[10];
        snprintf(svcbuf, 10, "<%d>", LOG_DAEMON | LOG_NOTICE);
        push_to_log(DLOG_MAIN, svcbuf, args...);
    }
    else {
        push_to_log(DLOG_MAIN, args...);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
cmpl %edi, 0x1c6cb(%rip)     # 0x456c8
jg 0x29048
movq %rdx, %rbx
movq %rsi, %r14
movw $0x1, 0x1edea(%rip)     # 0x47df8
cmpb $0x1, 0x1c6bc(%rip)     # 0x456d1
jne 0x29052
leaq 0x759a(%rip), %rdx      # 0x305b8
leaq 0x6(%rsp), %r15
pushq $0xa
popq %rsi
pushq $0x1d
popq %rcx
movq %r15, %rdi
xorl %eax, %eax
callq 0x89d0
leaq 0x758d(%rip), %rsi      # 0x305c7
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x294c7
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x756e(%rip), %rsi      # 0x305c7
xorl %edi, %edi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2943f
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: (anonymous namespace)::buffered_log_stream::watch_removed()
void buffered_log_stream::watch_removed() noexcept
{
    if (fd > STDERR_FILENO) {
        bp_sys::close(fd);
    }
    fd = -1;
    release = true; // prevent attempt to enable watch

    // Here we rely on there only being two logs, console and "main"; we can check if we are the
    // main log via identity:
    if (&log_stream[DLOG_MAIN] == this) {
        external_log_open = false;
    }
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl 0x1048(%rdi), %edi
cmpl $0x3, %edi
jl 0x2913c
callq 0x8b50
orl $-0x1, 0x1048(%rbx)
movb $0x1, 0x2a(%rbx)
leaq 0x1cc02(%rip), %rax     # 0x45d50
cmpq %rax, %rbx
jne 0x2915d
leaq 0x1ca3e(%rip), %rax     # 0x45b98
movb $0x0, (%rax)
popq %rbx
retq
movq %rax, %rdi
callq 0xaebb
nop
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: (anonymous namespace)::buffered_log_stream::release_console()
void buffered_log_stream::release_console()
{
    if (release) {
        int flags = fcntl(1, F_GETFL, 0);
        fcntl(1, F_SETFL, flags & ~O_NONBLOCK);
        if (services != nullptr) {
            services->pull_console_queue();
        }
        if (release) {
            // release still set, we didn't immediately get the console back; record the
            // time at which we released:
            event_loop.get_time(release_time, clock_type::MONOTONIC);
        }
    }
}

// Assembly:
cmpb $0x1, 0x2a(%rdi)
jne 0x293e9
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x1
popq %rbp
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x8380
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
pushq $0x4
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x8380
movq 0x1ea2d(%rip), %rdi     # 0x47df0
testq %rdi, %rdi
je 0x293cd
callq 0x1f63e
cmpb $0x1, 0x2a(%rbx)
leaq 0x8(%rsp), %rsp
popq %rbx
popq %rbp
jne 0x293e9
leaq 0x1c957(%rip), %rsi     # 0x45d38
pushq $0x1
popq %rdi
jmp 0x8560
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: (anonymous namespace)::buffered_log_stream::commit_msg()
void commit_msg()
    {
        bool was_first = current_index == 0;
        current_index = log_buffer.get_length();
        if (was_first && ! release) {
            set_enabled(event_loop, true);
        }
    }

// Assembly:
cmpl $0x0, 0x1044(%rdi)
movl 0x1040(%rdi), %eax
movl %eax, 0x1044(%rdi)
jne 0x2942f
cmpb $0x0, 0x2a(%rdi)
je 0x29430
retq
leaq 0x1c5f9(%rip), %rsi     # 0x45a30
pushq $0x1
popq %rdx
jmp 0xcf5c
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-log.cc
// Function: void push_to_log<char*, char const*, char const*, char const*>(int, char*, char const*, char const*, char const*)
static void push_to_log(int idx, T ... args) noexcept
{
    if (! log_current_line[idx]) return;
    int amount = sum_length(args...);
    if (log_stream[idx].get_free() >= amount) {
        append(log_stream[idx], args...);
        log_stream[idx].commit_msg();
    }
    else {
        log_stream[idx].mark_discarded();
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpb $0x1, 0x1e921(%rip)     # 0x47df8
jne 0x29514
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
callq 0x8220
movq %rax, %r13
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x29552
addl %r13d, %eax
movl $0x1000, %ecx           # imm = 0x1000
subl 0x1d887(%rip), %ecx     # 0x46d90
cmpl %eax, %ecx
jge 0x2951e
movb $0x1, 0x1c865(%rip)     # 0x45d79
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x1c82b(%rip), %r13     # 0x45d50
movq %r13, %rdi
movq %r12, %rsi
callq 0x293ea
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x29584
movq %r13, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x29414
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinit-main.cc
// Function: main
int main(int argc, char **argv)
{
    try {
        return dinit_main(argc, argv);
    }
    catch (std::bad_alloc &badalloc) {
        std::cout << "dinit: out-of-memory during initialisation" << std::endl;
        return 1;
    }
    catch (std::system_error &syserr) {
        std::cout << "dinit: unexpected system error during initialisation: " << syserr.what() << std::endl;
        return 1;
    }
    catch (...) {
        std::cout << "dinit: unexpected error during initialisation" << std::endl;
        return 1;
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
callq 0x8f9c
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rdx, %r14
movq %rax, %rdi
cmpl $0x3, %r14d
jne 0x29753
callq 0x8200
movq 0x1b833(%rip), %rdi     # 0x44f70
leaq 0x701f(%rip), %rsi      # 0x30763
callq 0x85d0
movq %rax, %rdi
callq 0x82b0
jmp 0x297b0
callq 0x8200
cmpl $0x2, %r14d
jne 0x29795
movq %rax, %rbx
movq 0x1b808(%rip), %rdi     # 0x44f70
leaq 0x6fbd(%rip), %rsi      # 0x3072c
callq 0x85d0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x85d0
movq %rax, %rdi
callq 0x82b0
jmp 0x297b0
movq 0x1b7d4(%rip), %rdi     # 0x44f70
leaq 0x6f5b(%rip), %rsi      # 0x306fe
callq 0x85d0
movq %rax, %rdi
callq 0x82b0
callq 0x8a40
pushq $0x1
popq %rax
jmp 0x2971d
movq %rax, %rbx
callq 0x8a40
jmp 0x297d9
movq %rax, %rbx
callq 0x8a40
jmp 0x297d9
movq %rax, %rbx
callq 0x8a40
movq %rbx, %rdi
callq 0x8a90
movq %rax, %rdi
callq 0xaebb
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/run-child-proc.cc
// Function: move_fd(int, int)
static int move_fd(int fd, int dest)
{
    if (fd == -1) return -1;
    if (fd == dest) return 0;

    if (dup2(fd, dest) == -1) {
        return -1;
    }

    close(fd);
    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
pushq $-0x1
popq %rbx
cmpl $-0x1, %edi
je 0x2a34f
movl %edi, %ebp
cmpl %esi, %edi
je 0x2a34d
movl %ebp, %edi
callq 0x8590
cmpl $-0x1, %eax
je 0x2a34f
movl %ebp, %edi
callq 0x8b50
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/run-child-proc.cc
// Function: move_reserved_fd(int*, int)
static int move_reserved_fd(int *fd, int min_fd)
{
    int new_fd = fcntl(*fd, F_DUPFD_CLOEXEC, min_fd);
    if (new_fd != -1) {
        close(*fd);
        *fd = new_fd;
    }
    return new_fd;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %edx
movq %rdi, %rbx
movl (%rdi), %edi
movl $0x406, %esi            # imm = 0x406
xorl %eax, %eax
callq 0x8380
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2a37e
movl (%rbx), %edi
callq 0x8b50
movl %ebp, (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::ReadBitWrap(unsigned char*, unsigned int, unsigned int, int)
uint32_t CBitBuffer::ReadBitWrap(uint8_t *buf, uint32_t bufwrap, uint32_t bitpos, int bitcnt)
{
	uint32_t res;

	// slow read mode if buffer would wrap around during reading, otherwise use fast read
	if (bitpos + bitcnt > bufwrap) {
		// slow mode; read bit by bit
		res = 0;

		// read all bits
		while (bitcnt-- > 0) {
			// shift in the next bit
			res <<= 1;
			if (ReadBit(buf, bitpos))
				res |= 1;

			// advance bit position
			bitpos++;

			// handle buffer wrap around
			if (bitpos >= bufwrap)
				bitpos -= bufwrap;
		}
	} else {
		// fast mode; read at once
		res = ReadBit(buf, bitpos, bitcnt);
	}

	return res;
}

// Assembly:
leal (%rcx,%rdx), %eax
cmpl %esi, %eax
jbe 0x3990
xorl %r8d, %r8d
xorl %eax, %eax
testl %ecx, %ecx
jle 0x398f
decl %ecx
movl %edx, %r9d
shrl $0x3, %r9d
movzbl (%rdi,%r9), %r9d
movl %edx, %r10d
notb %r10b
movzbl %r10b, %r10d
andl $0x7, %r10d
xorl %r11d, %r11d
btl %r10d, %r9d
setb %r11b
leal (%r11,%rax,2), %eax
leal 0x1(%rdx), %r9d
cmpl %esi, %r9d
movl %esi, %r9d
cmovbl %r8d, %r9d
negl %r9d
addl %r9d, %edx
incl %edx
jmp 0x3948
retq
movl %edx, %esi
movl %ecx, %edx
jmp 0x399a
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::ClearBitWrap(unsigned char*, unsigned int, unsigned int, int)
void CBitBuffer::ClearBitWrap(uint8_t *buf, uint32_t bufwrap, uint32_t bitpos, int bitcnt)
{
	// slow write mode if buffer would wrap around during writing, otherwise use fast write
	if (bitpos + bitcnt > bufwrap) {
		while (bitcnt > 0) {
			// write largest possible bitfield
			int writebc = (bitcnt >= MAX_BITBUFFER_LEN) ? MAX_BITBUFFER_LEN : bitcnt;

			// write 0 as bitfield
			WriteBitWrap(buf, bufwrap, bitpos, 0, writebc);

			// next write position
			bitcnt -= writebc;
			bitpos += writebc;

			// handle buffer wrap around
			if (bitpos >= bufwrap)
				bitpos -= bufwrap;
		}
	}	else {
		// fast mode; write at once
		ClearBit(buf, bitpos, bitcnt);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebx
movl %edx, %r15d
movq %rdi, %r14
leal (%rbx,%r15), %eax
cmpl %esi, %eax
jbe 0x3b6d
movl %esi, %ebp
xorl %r13d, %r13d
testl %ebx, %ebx
jle 0x3b5e
cmpl $0x20, %ebx
pushq $0x20
popq %r12
cmovbl %ebx, %r12d
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
callq 0x39f4
subl %r12d, %ebx
addl %r15d, %r12d
cmpl %ebp, %r12d
movl %ebp, %eax
cmovbl %r13d, %eax
subl %eax, %r12d
movl %r12d, %r15d
jmp 0x3b26
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b88
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::ClearBit(unsigned char*, unsigned int, int)
void CBitBuffer::ClearBit(uint8_t *buf, uint32_t bitpos, int bitcnt)
{
	while (bitcnt > 0) {
		// write largest possible bitfield
		int writebc = (bitcnt >= MAX_BITBUFFER_LEN) ? MAX_BITBUFFER_LEN : bitcnt;

		// write 0 as bitfield
		WriteBit(buf, bitpos, 0, writebc);

		// next write position
		bitcnt -= writebc;
		bitpos += writebc;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
pushq $0x20
popq %r12
testl %ebx, %ebx
jle 0x3bc0
cmpl $0x20, %ebx
movl %r12d, %r15d
cmovbl %ebx, %r15d
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
movl %r15d, %ecx
callq 0x3a98
subl %r15d, %ebx
addl %r15d, %ebp
jmp 0x3b9b
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::CompareBit(unsigned char*, unsigned int, unsigned char*, unsigned int, int)
int CBitBuffer::CompareBit(uint8_t *buf1, uint32_t buf1pos, uint8_t *buf2, uint32_t buf2pos, int bitcnt)
{
	// compare every bit in the two fields, 32 bit at a time, and finally the remaining bits
	while (bitcnt > 0) {
		uint32_t s1, s2;

		if (bitcnt >= 32) {
			// read 32 bits from each field if the remaining field size is at least 32
			s1 = ReadBit32(buf1, buf1pos);
			s2 = ReadBit32(buf2, buf2pos);
			bitcnt -= 32;
			buf1pos += 32;
			buf2pos += 32;
		} else {
			// read the remaining 1...31 bits
			s1 = ReadBit(buf1, buf1pos, bitcnt);
			s2 = ReadBit(buf2, buf2pos, bitcnt);
			bitcnt = 0;
		}

		// error if fields are different
		if (s1 != s2)
			return -1;
	}

	// all bits compared, the fields are identical
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %r12d
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r13
testl %r12d, %r12d
jle 0x3c35
movq %r13, %rdi
movl %r15d, %esi
cmpl $0x20, %r12d
jb 0x3c12
callq 0x3de0
movl %eax, %ebx
movq %r14, %rdi
movl %ebp, %esi
callq 0x3de0
addl $-0x20, %r12d
addl $0x20, %r15d
addl $0x20, %ebp
jmp 0x3c2c
movl %r12d, %edx
callq 0x399a
movl %eax, %ebx
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x399a
xorl %r12d, %r12d
cmpl %eax, %ebx
je 0x3be3
pushq $-0x1
popq %rax
jmp 0x3c37
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::CompareAndCountBit(unsigned char*, unsigned int, unsigned char*, unsigned int, int)
int CBitBuffer::CompareAndCountBit(uint8_t *buf1, uint32_t buf1pos, uint8_t *buf2, uint32_t buf2pos, int bitcnt)
{
	// number of bits processed, size of current block
	int bitproc = 0, blocksize;
	uint32_t diff;

	// compare every bit in the two fields, in 32 bit blocks, and finally the remaining 1...31 bits
	while (bitcnt > 0) {
		uint32_t s1, s2;

		if (bitcnt >= 32) {
			// process 32 bits if the remaining field size is at least 32
			blocksize = 32;

			// read 32 bits from each field 
			s1 = ReadBit32(buf1, buf1pos);
			s2 = ReadBit32(buf2, buf2pos);
		} else {
			// process the remaining 1...31 bits
			blocksize = bitcnt;

			// read the remaining 1...31 bits from each field
			s1 = ReadBit(buf1, buf1pos, blocksize);
			s2 = ReadBit(buf2, buf2pos, blocksize);
		}

		// bits that are different in the two fiels are set to 1
		diff = s1 ^ s2;

		// stop if fields are different (any of the bits set)
		if (diff)
			break;

		// advance to the next block
		buf1pos += blocksize;
		buf2pos += blocksize;
		bitproc += blocksize;
		bitcnt -= blocksize;
	}

	// difference found, count the remaining identical bits
	if (bitcnt > 0) {
		// find the first bit set from b<blocksize-1>...0
		for (uint32_t mask = 1U << (blocksize - 1); mask; mask >>= 1) {
			if (diff & mask)
				break;

			// bit not set, another identical bit
			bitproc++;
		}
	}

	// return the number of bits processed and found to be identical
	return bitproc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, (%rsp)
movl %esi, %r12d
movq %rdi, %r13
xorl %ebx, %ebx
testl %ebp, %ebp
jle 0x3cd0
movq %r13, %rdi
movl %r12d, %esi
cmpl $0x20, %ebp
jb 0x3c8b
callq 0x3de0
movl %eax, %r15d
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x3de0
pushq $0x20
popq %rcx
jmp 0x3ca5
movl %ebp, %edx
callq 0x399a
movl %eax, %r15d
movq (%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x399a
movl %ebp, %ecx
cmpl %eax, %r15d
jne 0x3cb6
addl %ecx, %r12d
addl %ecx, %r14d
addl %ecx, %ebx
subl %ecx, %ebp
jmp 0x3c63
xorl %r15d, %eax
decb %cl
pushq $0x1
popq %rdx
shll %cl, %edx
testl %edx, %edx
je 0x3cd0
movl %edx, %ecx
andl %eax, %ecx
jne 0x3cd0
incl %ebx
shrl %edx
jmp 0x3cc0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::CopyBitWrap(unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned int, unsigned int, int)
void CBitBuffer::CopyBitWrap(uint8_t *srcbuf, uint32_t srcwrap, uint32_t srcpos, uint8_t *dstbuf, uint32_t dstwrap, uint32_t dstpos, int bitcnt)
{
	// copy areas in largest possible size up to the track wrap points
	while (bitcnt > 0) {
		// clamp size to largest size to copy until the destination wrap point
		int csize = (dstpos + bitcnt > dstwrap) ? dstwrap - dstpos : bitcnt;

		// clamp size to largest size to copy until the source wrap point
		if (srcpos + csize > srcwrap)
			csize = srcwrap - srcpos;

		// copy the field; it is guaranteed that source or destionation does not wrap
		CopyBit(srcbuf, srcpos, dstbuf, dstpos, csize);

		// advance bit positions forward
		srcpos += csize;
		dstpos += csize;
		bitcnt -= csize;

		// handle buffer wrap around
		if (srcpos >= srcwrap)
			srcpos -= srcwrap;

		if (dstpos >= dstwrap)
			dstpos -= dstwrap;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movq %rcx, 0x10(%rsp)
movl %edx, %r15d
movl %esi, %r14d
movq %rdi, 0x8(%rsp)
movl 0x50(%rsp), %r13d
testl %r13d, %r13d
jle 0x3d6b
leal (%rbx,%r13), %eax
movl %ebp, %ecx
subl %ebx, %ecx
cmpl %ebp, %eax
cmovbel %r13d, %ecx
leal (%rcx,%r15), %eax
movl %r14d, %r12d
subl %r15d, %r12d
cmpl %r14d, %eax
cmovbel %ecx, %r12d
movq 0x8(%rsp), %rdi
movl %r15d, %esi
movq 0x10(%rsp), %rdx
movl %ebx, %ecx
movl %r12d, %r8d
callq 0x3d7a
addl %r12d, %r15d
addl %r12d, %ebx
subl %r12d, %r13d
cmpl %r14d, %r15d
movl %r14d, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
subl %eax, %r15d
cmpl %ebp, %ebx
movl %ebp, %eax
cmovbl %ecx, %eax
subl %eax, %ebx
jmp 0x3d0b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/BitBuffer.cpp
// Function: CBitBuffer::CopyBit(unsigned char*, unsigned int, unsigned char*, unsigned int, int)
void CBitBuffer::CopyBit(uint8_t *srcbuf, uint32_t srcpos, uint8_t *dstbuf, uint32_t dstpos, int bitcnt)
{
	// copy the field in 32 bit blocks, and finally the remaining 1...31 bits
	while (bitcnt > 0) {
		uint32_t value;
		int blocksize;

		if (bitcnt >= 32) {
			// process 32 bits if the remaining field size is at least 32
			blocksize = 32;

			// read 32 bits from source
			value = ReadBit32(srcbuf, srcpos);
		} else {
			// process the remaining 1...31 bits
			blocksize = bitcnt;

			// read the remaining 1...31 bits from each field
			value = ReadBit(srcbuf, srcpos, blocksize);
		}

		// write the field
		WriteBit(dstbuf, dstpos, value, blocksize);

		// advance to the next block
		srcpos += blocksize;
		dstpos += blocksize;
		bitcnt -= blocksize;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
testl %ebx, %ebx
jle 0x3dd1
movq %r12, %rdi
movl %r15d, %esi
cmpl $0x20, %ebx
jb 0x3dad
callq 0x3de0
pushq $0x20
popq %r13
jmp 0x3db7
movl %ebx, %edx
callq 0x399a
movl %ebx, %r13d
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
movl %r13d, %ecx
callq 0x3a98
addl %r13d, %r15d
addl %r13d, %ebp
subl %r13d, %ebx
jmp 0x3d93
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/./capsimg/Core/BitBuffer.h
// Function: CBitBuffer::ReadBit32(unsigned char*, unsigned int)
inline uint32_t CBitBuffer::ReadBit32(uint8_t *buf, uint32_t bitpos)
{
	int shf = bitpos & 7;
	uint32_t pos = bitpos >> 3;
	uint32_t res = buf[pos] << 24 | buf[pos + 1] << 16 | buf[pos + 2] << 8 | buf[pos + 3];

	if (!shf)
		return res;

	return ((res << shf) | (buf[pos + 4] >> (8 - shf)));
}

// Assembly:
movl %esi, %edx
shrl $0x3, %edx
movl (%rdi,%rdx), %eax
bswapl %eax
andl $0x7, %esi
je 0x3e01
movl %esi, %ecx
shll %cl, %eax
movzbl 0x4(%rdi,%rdx), %edx
movb $0x8, %cl
subb %sil, %cl
shrl %cl, %edx
orl %edx, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: MakeCRCTable()
void MakeCRCTable()
{
	UDWORD poly=0;
	int i;

	if (crcinit)
		return;

	// crc32
	for (i=0; i < sizeof(crcpoly)/sizeof(UBYTE); i++)
		poly|=1UL<<(31-crcpoly[i]);

	for (i=0; i < 256; i++) {
		UDWORD crc=i;
		int bit;

		for (bit=0; bit < 8; bit++)
			crc=crc & 1 ? poly^(crc>>1) : crc>>1;

		crctab[i]=crc;
	}

	// crc-ccitt
	for (i=0, poly=0; i < sizeof(crcpoly_ccitt)/sizeof(UBYTE); i++)
		poly|=1UL<<crcpoly_ccitt[i];

	for (i=0; i < 256; i++) {
		UWORD crc=i<<8;
		int bit;

		for (bit=0; bit < 8; bit++)
			crc=crc & 0x8000 ? (UWORD)poly^(crc<<1) : crc<<1;

		crctab_ccitt[i]=crc;
	}

	// crc-ansi
	for (i=0, poly=0; i < sizeof(crcpoly_ansi)/sizeof(UBYTE); i++)
		poly|=1UL<<crcpoly_ansi[i];

	for (i=0; i < 256; i++) {
		UWORD crc=i<<8;
		int bit;

		for (bit=0; bit < 8; bit++)
			crc=crc & 0x8000 ? (UWORD)poly^(crc<<1) : crc<<1;

		crctab_ansi[i]=crc;
	}

	crcinit=1;
}

// Assembly:
cmpl $0x0, 0x13ed9(%rip)     # 0x17ce4
je 0x3e0e
retq
xorl %esi, %esi
leaq 0x133f9(%rip), %rdi     # 0x17210
pushq $0x1
popq %rax
xorl %edx, %edx
cmpq $0xe, %rsi
je 0x3e35
movb $0x1f, %cl
subb (%rsi,%rdi), %cl
movq %rax, %r8
shlq %cl, %r8
orl %r8d, %edx
incq %rsi
jmp 0x3e1c
xorl %ecx, %ecx
pushq $0x8
popq %rsi
leaq 0x13eaf(%rip), %rdi     # 0x17cf0
cmpq $0x100, %rcx            # imm = 0x100
je 0x3e74
movl %esi, %r9d
movl %ecx, %r8d
subl $0x1, %r9d
jb 0x3e6b
movl %r8d, %r10d
andl $0x1, %r10d
negl %r10d
shrl %r8d
andl %edx, %r10d
xorl %r10d, %r8d
jmp 0x3e50
movl %r8d, (%rdi,%rcx,4)
incq %rcx
jmp 0x3e41
xorl %esi, %esi
leaq 0x133a1(%rip), %rdi     # 0x1721e
xorl %edx, %edx
cmpq $0x3, %rsi
je 0x3e96
movb (%rsi,%rdi), %cl
movq %rax, %r8
shlq %cl, %r8
orl %r8d, %edx
incq %rsi
jmp 0x3e7f
xorl %ecx, %ecx
pushq $0x8
popq %rsi
leaq 0x1424e(%rip), %rdi     # 0x180f0
cmpq $0x100, %rcx            # imm = 0x100
je 0x3ed9
movl %ecx, %r8d
shll $0x8, %r8d
movl %esi, %r9d
subl $0x1, %r9d
jb 0x3ecf
leal (%r8,%r8), %r10d
movswl %r8w, %r8d
sarl $0xf, %r8d
andl %edx, %r8d
xorl %r10d, %r8d
jmp 0x3eb5
movw %r8w, (%rdi,%rcx,2)
incq %rcx
jmp 0x3ea2
xorl %esi, %esi
leaq 0x1333f(%rip), %rdi     # 0x17221
xorl %edx, %edx
cmpq $0x3, %rsi
je 0x3efb
movb (%rsi,%rdi), %cl
movq %rax, %r8
shlq %cl, %r8
orl %r8d, %edx
incq %rsi
jmp 0x3ee4
xorl %eax, %eax
pushq $0x8
popq %rcx
leaq 0x143e9(%rip), %rsi     # 0x182f0
cmpq $0x100, %rax            # imm = 0x100
je 0x3f37
movl %eax, %edi
shll $0x8, %edi
movl %ecx, %r8d
subl $0x1, %r8d
jb 0x3f2e
leal (%rdi,%rdi), %r9d
movswl %di, %edi
sarl $0xf, %edi
andl %edx, %edi
xorl %r9d, %edi
jmp 0x3f17
movw %di, (%rsi,%rax,2)
incq %rax
jmp 0x3f07
movl $0x1, 0x13da3(%rip)     # 0x17ce4
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: CalcCRC(unsigned char*, int)
UDWORD CalcCRC(PUBYTE buf, int len)
{
	UDWORD crc=~0;

	while (len--)
		crc=crctab[(crc^*buf++) & 0xff] ^ (crc >> 8);

	return crc^~0;
}

// Assembly:
movl %esi, %ecx
pushq $-0x1
popq %rax
xorl %edx, %edx
leaq 0x13da0(%rip), %rsi     # 0x17cf0
cmpl %edx, %ecx
je 0x3f6b
movb (%rdi,%rdx), %r8b
xorb %al, %r8b
movzbl %r8b, %r8d
shrl $0x8, %eax
xorl (%rsi,%r8,4), %eax
incq %rdx
jmp 0x3f50
notl %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: CalcCRC32(unsigned char*, int, unsigned int)
UDWORD CalcCRC32(PUBYTE buf, int len, UDWORD seed)
{
	UDWORD crc=~seed;

	while (len--)
		crc=crctab[(crc^*buf++) & 0xff] ^ (crc >> 8);

	return crc^~0;
}

// Assembly:
movl %edx, %eax
notl %eax
movl %esi, %ecx
xorl %edx, %edx
leaq 0x13d73(%rip), %rsi     # 0x17cf0
cmpl %edx, %ecx
je 0x3f98
movb (%rdi,%rdx), %r8b
xorb %al, %r8b
movzbl %r8b, %r8d
shrl $0x8, %eax
xorl (%rsi,%r8,4), %eax
incq %rdx
jmp 0x3f7d
notl %eax
retq