LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2bd0c
movb $0x1, %bpl
cmpl $-0x1, %eax
je 0x2b52e
testl %eax, %eax
je 0x2b581
movl 0x484(%rbx), %eax
cmpl 0x7c(%rbx), %eax
jb 0x2b510
movq %rbx, %rdi
callq 0x27dac
testb %al, %al
je 0x2b57f
cmpb $0x0, 0x78(%rbx)
jne 0x2b57f
movl 0x7c(%rbx), %ecx
cmpl $0x1, %ecx
adcl $0x0, %ecx
movl %ecx, 0x7c(%rbx)
movl 0x484(%rbx), %eax
cmpl %ecx, %eax
jae 0x2b4e0
cmpl $0x400, %eax            # imm = 0x400
jne 0x2b57f
leaq 0xafe2(%rip), %rsi      # 0x36500
movl $0x2, %edi
callq 0x2e33a
movb $0x1, 0x78(%rbx)
jmp 0x2b57f
callq 0x8050
movl (%rax), %edi
cmpl $0x4, %edi
je 0x2b57f
cmpl $0xb, %edi
je 0x2b57f
cmpl $0x68, %edi
je 0x2b581
callq 0x81d0
movq %rax, %rbx
leaq 0xaf85(%rip), %rsi      # 0x364d8
movl $0x2, %edi
callq 0x2e412
movq %rbx, %rdi
callq 0x2e53c
jmp 0x2b581
cmpl $0x2, %edx
jne 0x2b58a
movq %rax, %rdi
callq 0x8210
movw $0x101, 0x78(%rbx)      # imm = 0x101
callq 0x8a50
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq %rax, %rdi
callq 0xb74e
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b5db
cmpb $0x1, 0x78(%rbx)
jne 0x2b5db
movb $0x1, %bpl
cmpb $0x1, 0x79(%rbx)
jne 0x2b662
movl 0x2c(%rbx), %edi
leaq 0xae6c(%rip), %rsi      # 0x36438
movl $0x1, %edx
callq 0x81e0
jmp 0x2b662
movl 0x2c(%rbx), %edi
movl 0x50c(%rbx), %esi
addq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
subq %rsi, %rdx
callq 0x81e0
cmpl $-0x1, %eax
je 0x2b647
addl 0x50c(%rbx), %eax
movl %eax, 0x50c(%rbx)
movq 0x18(%r15), %rcx
subq 0x10(%r15), %rcx
cmpq %rax, %rcx
jne 0x2b660
subl %eax, 0x508(%rbx)
movq 0x4f0(%rbx), %rsi
movq %r14, %rdi
callq 0x2dfbe
movl $0x0, 0x50c(%rbx)
cmpb $0x0, 0x79(%rbx)
jne 0x2b660
cmpq %r14, (%r14)
jne 0x2b660
movb $0x1, %bpl
cmpb $0x0, 0x78(%rbx)
je 0x2b660
jmp 0x2b662
callq 0x8050
movl (%rax), %edi
cmpl $0x4, %edi
je 0x2b660
movb $0x1, %bpl
cmpl $0x20, %edi
je 0x2b662
cmpl $0xb, %edi
jne 0x2b66f
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x81d0
movq %rax, %rbx
leaq 0xae34(%rip), %rsi      # 0x364b2
movl $0x3, %edi
callq 0x2e412
movq %rbx, %rdi
callq 0x2e53c
jmp 0x2b662
movq %rax, %rdi
callq 0xb74e
// File: /workspace/github_cpp_makefile_star2_O3/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 0x1a55d(%rip), %rax     # 0x45c08
movq %rax, (%rdi)
leaq 0x1a583(%rip), %rax     # 0x45c38
movq %rax, 0x8(%rdi)
leaq 0x10(%rdi), %rsi
movl 0x2c(%rdi), %ebp
movq 0x68(%rdi), %rdi
movl %ebp, %edx
callq 0x2dff2
movl %ebp, %edi
callq 0x8b60
leaq 0x8(%rbx), %r14
movq 0x498(%rbx), %r15
testq %r15, %r15
je 0x2b6f3
movq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x2b8e6
movq (%r15), %r15
jmp 0x2b6dd
leaq 0x488(%rbx), %r15
leaq 0x1d70f(%rip), %rdi     # 0x48e10
movq %r14, %rsi
callq 0x2bd60
leaq 0x1b48c(%rip), %rax     # 0x46b9c
decl (%rax)
leaq 0x4f0(%rbx), %rdi
callq 0xcd00
addq $0x4c0, %rbx            # imm = 0x4C0
movq %rbx, %rdi
callq 0xcd44
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xcd94
movq %rax, %rdi
callq 0xb74e
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_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 0xa0(%rdi), %edi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x8860
leaq 0xf(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xd5d8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e044
movq %r14, %rdi
movq %r15, %rsi
callq 0xd604
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2e07d
leaq 0x10(%rbx), %r15
movq 0x10(%rbx), %rsi
cmpq $-0x1, %rsi
je 0x2e06c
movq %r14, %rdi
callq 0xc4e8
movq %r14, %rdi
movq %r15, %rsi
callq 0xc75c
orb $0x1, 0x48(%rbx)
jmp 0x2e08e
orb $0x2, %al
movb %al, 0xc(%rbx)
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0xc75c
movb 0x34(%rbx), %al
testb $0x1, %al
jne 0x2e0bd
movq 0x38(%rbx), %rsi
cmpq $-0x1, %rsi
je 0x2e0a7
movq %r14, %rdi
callq 0xc4e8
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0xc75c
movb 0x48(%rbx), %al
orb $0x2, %al
movb %al, 0x48(%rbx)
jmp 0x2e0d1
orb $0x2, %al
movb %al, 0x34(%rbx)
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0xc75c
movb 0x48(%rbx), %al
notb %al
testb $0x3, %al
jne 0x2e0e5
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_O3/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 0x19c7a(%rip), %al      # 0x47dca
movl %eax, %ecx
andb %dil, %cl
cmpb $0x1, %cl
jne 0x2e1af
movl $0x1, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x8390
orl $0x800, %eax            # imm = 0x800
movl $0x1, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x8390
movl $0x1, 0x1ac59(%rip)     # 0x48de8
movb $0x0, 0x19c34(%rip)     # 0x47dca
leaq 0x19c03(%rip), %rdi     # 0x47da0
leaq 0x1888c(%rip), %rsi     # 0x46a30
movl $0x1, %edx
popq %rax
jmp 0xd486
orb %dil, %al
jne 0x2e1e9
movb $0x1, 0x19c0f(%rip)     # 0x47dca
movl 0x1ac27(%rip), %esi     # 0x48de8
leaq 0x19bd8(%rip), %rdi     # 0x47da0
callq 0x2e7f2
cmpl $0x3, %eax
je 0x2e1eb
cmpl $0x1, %eax
jne 0x2e1e9
leaq 0x19bc2(%rip), %rdi     # 0x47da0
leaq 0x1884b(%rip), %rsi     # 0x46a30
xorl %edx, %edx
jmp 0x2e1a9
popq %rax
retq
movl 0x19bcb(%rip), %edx     # 0x47dbc
leaq 0x18838(%rip), %rdi     # 0x46a30
leaq 0x19ba1(%rip), %rsi     # 0x47da0
popq %rax
jmp 0xd520
movq %rax, %rdi
callq 0xb74e
// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsp, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x8560
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq 0x18a41(%rip), %rcx     # 0x46d38
movq 0x18a42(%rip), %rax     # 0x46d40
xorl %esi, %esi
cmpq %rax, %rdx
setl %sil
subq %rsi, %rcx
cmpq $0x1, %rcx
jg 0x2e329
leaq 0x3b9aca00(%rdx), %rsi
cmpq %rax, %rdx
cmovgeq %rdx, %rsi
cmpq $0x1, %rcx
jne 0x2e334
subq %rax, %rsi
js 0x2e334
movq $0x0, 0x1aaac(%rip) # 0x48de0
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18375(%rip)     # 0x466cc
setle %al
andb %sil, %al
cmpl %edi, 0x18365(%rip)     # 0x466c8
movb %al, 0x1aa90(%rip)      # 0x48df9
setle 0x1aa88(%rip)           # 0x48df8
leaq 0x8229(%rip), %rsi      # 0x365a0
leaq 0x5765(%rip), %rcx      # 0x33ae3
movl $0x1, %edi
callq 0x2eb57
cmpb $0x1, 0x1aa69(%rip)     # 0x48df8
jne 0x2e3e4
cmpb $0x1, 0x18339(%rip)     # 0x466d1
jne 0x2e3ed
movl $0x1a, %ecx
cmpl $0x3, %ebp
ja 0x2e3b0
movl %ebp, %eax
leaq 0x81e3(%rip), %rcx      # 0x36590
movl (%rcx,%rax,4), %ecx
leaq 0x81f1(%rip), %rdx      # 0x365a8
leaq 0x6(%rsp), %r14
movl $0xa, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x89e0
leaq 0x81ce(%rip), %rsi      # 0x365a0
leaq 0x570a(%rip), %rcx      # 0x33ae3
movq %r14, %rdi
movq %rbx, %rdx
callq 0x2ec43
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x81ac(%rip), %rsi      # 0x365a0
leaq 0x56e8(%rip), %rcx      # 0x33ae3
xorl %edi, %edi
movq %rbx, %rdx
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x2eb57
// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x18, %rsp
cmpl %edi, 0x182ad(%rip)     # 0x466cc
setle 0x1a9d3(%rip)           # 0x48df9
movq %rsi, %rbx
cmpl %edi, 0x18299(%rip)     # 0x466c8
setle 0x1a9c2(%rip)           # 0x48df8
jg 0x2e47c
cmpb $0x1, 0x18292(%rip)     # 0x466d1
jne 0x2e47c
movl $0x1a, %ecx
cmpl $0x3, %edi
ja 0x2e457
movl %edi, %eax
leaq 0x813c(%rip), %rcx      # 0x36590
movl (%rcx,%rax,4), %ecx
leaq 0x814a(%rip), %rdx      # 0x365a8
leaq 0xe(%rsp), %r14
movl $0xa, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x89e0
xorl %edi, %edi
movq %r14, %rsi
callq 0x2e4b5
leaq 0x811d(%rip), %r14      # 0x365a0
xorl %edi, %edi
movq %r14, %rsi
callq 0x2e4b5
xorl %edi, %edi
movq %rbx, %rsi
callq 0x2e4b5
movl $0x1, %edi
movq %r14, %rsi
callq 0x2e4b5
movl $0x1, %edi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x2e4b5
// File: /workspace/github_cpp_makefile_star2_O3/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 0x1a934(%rip), %r15     # 0x48df8
cmpb $0x1, (%r14,%r15)
jne 0x2e50d
movq %rsi, %rbx
movq %rsi, %rdi
callq 0x8230
imulq $0x1050, %r14, %rcx     # imm = 0x1050
leaq 0x1886c(%rip), %rdx     # 0x46d50
leaq (%rdx,%rcx), %rdi
movl $0x1000, %esi           # imm = 0x1000
subl 0x1040(%rcx,%rdx), %esi
cmpl %eax, %esi
jge 0x2e513
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 0x2eac7
// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb $0x1, %bpl
xorl %r12d, %r12d
leaq 0x558c(%rip), %r14      # 0x33ae3
leaq 0x1a89a(%rip), %r13     # 0x48df8
leaq 0x187eb(%rip), %r15     # 0x46d50
movl %r12d, %edi
movq %rbx, %rsi
callq 0x2e4b5
movl %r12d, %edi
movq %r14, %rsi
callq 0x2e4b5
cmpb $0x1, (%r12,%r13)
jne 0x2e5be
imulq $0x1050, %r12, %rdi     # imm = 0x1050
cmpl $0x0, 0x1044(%rdi,%r15)
movl 0x1040(%rdi,%r15), %eax
movl %eax, 0x1044(%rdi,%r15)
jne 0x2e5be
addq %r15, %rdi
cmpb $0x0, 0x2a(%rdi)
jne 0x2e5be
leaq 0x1847c(%rip), %rsi     # 0x46a30
movl $0x1, %edx
callq 0xd486
movl $0x1, %r12d
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x2e565
addq $0x8, %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/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, 0x1808f(%rip)     # 0x466c8
jg 0x2e688
movq %rdx, %rbx
movq %rsi, %r14
movw $0x1, 0x1a7ae(%rip)     # 0x48df8
cmpb $0x1, 0x18080(%rip)     # 0x466d1
jne 0x2e692
leaq 0x7f4e(%rip), %rdx      # 0x365a8
leaq 0x6(%rsp), %r15
movl $0xa, %esi
movq %r15, %rdi
movl $0x1d, %ecx
xorl %eax, %eax
callq 0x89e0
leaq 0x7f3d(%rip), %rsi      # 0x365b7
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x2ec43
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x7f1e(%rip), %rsi      # 0x365b7
xorl %edi, %edi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2eb57
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2e7c4
callq 0x8b60
movl $0xffffffff, 0x1048(%rbx) # imm = 0xFFFFFFFF
movb $0x1, 0x2a(%rbx)
leaq 0x18577(%rip), %rax     # 0x46d50
cmpq %rax, %rbx
jne 0x2e7e8
leaq 0x183b3(%rip), %rax     # 0x46b98
movb $0x0, (%rax)
popq %rbx
retq
movq %rax, %rdi
callq 0xb74e
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2eac6
pushq %rbx
movq %rdi, %rbx
movl $0x1, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x8390
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl $0x1, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x8390
movq 0x1a34c(%rip), %rdi     # 0x48df0
testq %rdi, %rdi
je 0x2eaae
callq 0x23cd2
cmpb $0x1, 0x2a(%rbx)
popq %rbx
jne 0x2eac6
leaq 0x1827c(%rip), %rsi     # 0x46d38
movl $0x1, %edi
jmp 0x8560
retq
// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/dinit-log.cc
// Function: void push_to_log<char const*, char const*, char const*>(int, 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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebp
leaq 0x1a28d(%rip), %rax     # 0x48df8
cmpb $0x1, (%rbp,%rax)
jne 0x2ec12
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rsi, %rdi
callq 0x8230
movq %rax, %r12
movq %r14, %rdi
callq 0x8230
movq %rax, %r13
movq %rbx, %rdi
callq 0x8230
addl %r12d, %r13d
addl %eax, %r13d
imulq $0x1050, %rbp, %rax     # imm = 0x1050
leaq 0x1819f(%rip), %rcx     # 0x46d50
leaq (%rcx,%rax), %r12
movl $0x1000, %edx           # imm = 0x1000
subl 0x1040(%rax,%rcx), %edx
cmpl %r13d, %edx
jge 0x2ebce
movb $0x1, 0x29(%r12)
jmp 0x2ec12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2eac7
movq %r12, %rdi
movq %r14, %rsi
callq 0x2eac7
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2eac7
cmpl $0x0, 0x1044(%r12)
movl 0x1040(%r12), %eax
movl %eax, 0x1044(%r12)
jne 0x2ec12
cmpb $0x0, 0x2a(%r12)
je 0x2ec21
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17e08(%rip), %rsi     # 0x46a30
movq %r12, %rdi
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd486
// File: /workspace/github_cpp_makefile_star2_O3/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 0x949c
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rdx, %r14
movq %rax, %rdi
cmpl $0x3, %r14d
jne 0x2ee14
callq 0x8210
movq 0x1718b(%rip), %rdi     # 0x45f80
leaq 0x7957(%rip), %rsi      # 0x36753
movl $0x2a, %edx
callq 0x86c0
movq 0x17173(%rip), %rdi     # 0x45f80
callq 0x82b0
jmp 0x2ee80
callq 0x8210
cmpl $0x2, %r14d
jne 0x2ee5c
movq %rax, %rbx
movq 0x17157(%rip), %rdi     # 0x45f80
leaq 0x78ec(%rip), %rsi      # 0x3671c
movl $0x36, %edx
callq 0x86c0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x17136(%rip), %rdi     # 0x45f80
movq %rax, %rsi
callq 0x85e0
movq %rax, %rdi
callq 0x82b0
jmp 0x2ee80
movq 0x1711d(%rip), %rdi     # 0x45f80
leaq 0x7884(%rip), %rsi      # 0x366ee
movl $0x2d, %edx
callq 0x86c0
movq 0x17105(%rip), %rdi     # 0x45f80
callq 0x82b0
callq 0x8a50
movl $0x1, %eax
jmp 0x2edd5
movq %rax, %rbx
callq 0x8a50
jmp 0x2eeab
movq %rax, %rbx
callq 0x8a50
jmp 0x2eeab
movq %rax, %rbx
callq 0x8a50
movq %rbx, %rdi
callq 0x8ab0
movq %rax, %rdi
callq 0xb74e
nop
// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %edi
je 0x2facc
movl %edi, %ebp
cmpl %esi, %edi
je 0x2faca
movl %ebp, %edi
callq 0x8590
cmpl $-0x1, %eax
je 0x2facc
movl %ebp, %edi
callq 0x8b60
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
testl %r8d, %r8d
jle 0x4dd0
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, %r13
movl %esi, %r12d
xorl %ebx, %ebx
movq %rdi, (%rsp)
cmpl $0x20, %ebp
jb 0x4d99
movl %r12d, %eax
shrl $0x3, %eax
movl %r12d, %ecx
movl (%rdi,%rax), %r15d
bswapl %r15d
andl $0x7, %ecx
je 0x4d67
shll %cl, %r15d
movzbl 0x4(%rdi,%rax), %edx
movb $0x8, %al
subb %cl, %al
movl %eax, %ecx
shrl %cl, %edx
orl %edx, %r15d
movl %r14d, %esi
shrl $0x3, %esi
movl %r14d, %ecx
movl (%r13,%rsi), %eax
bswapl %eax
movl $0x20, %edx
andl $0x7, %ecx
je 0x4db9
shll %cl, %eax
movzbl 0x4(%r13,%rsi), %r9d
movb $0x8, %sil
subb %cl, %sil
movl %esi, %ecx
shrl %cl, %r9d
orl %r9d, %eax
jmp 0x4db9
movl %r12d, %esi
movl %ebp, %edx
callq 0x4a0c
movl %eax, %r15d
movq %r13, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x4a0c
movq (%rsp), %rdi
movl %ebp, %edx
cmpl %eax, %r15d
jne 0x4dd4
addl %edx, %r12d
addl %edx, %r14d
addl %edx, %ebx
subl %edx, %ebp
jg 0x4d3a
jmp 0x4dfb
xorl %ebx, %ebx
jmp 0x4dfb
decb %dl
movl $0x1, %esi
movl %edx, %ecx
shll %cl, %esi
xorl %r15d, %eax
movzbl %dl, %ecx
btl %ecx, %eax
jb 0x4dfb
jmp 0x4df4
shrl %esi
movl %esi, %ecx
andl %eax, %ecx
jne 0x4dfb
incl %ebx
cmpl $0x2, %esi
jae 0x4dec
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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:
testl %r8d, %r8d
jle 0x4f3b
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
cmpl $0x20, %ebx
jb 0x4f03
movl %r15d, %eax
shrl $0x3, %eax
movl %r15d, %ecx
movl (%r12,%rax), %edx
bswapl %edx
movl $0x20, %r13d
andl $0x7, %ecx
je 0x4f15
shll %cl, %edx
movzbl 0x4(%r12,%rax), %esi
movb $0x8, %al
subb %cl, %al
movl %eax, %ecx
shrl %cl, %esi
orl %esi, %edx
jmp 0x4f15
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x4a0c
movl %eax, %edx
movl %ebx, %r13d
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %ecx
callq 0x4b12
addl %r13d, %r15d
addl %r13d, %ebp
subl %r13d, %ebx
jg 0x4ed0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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, 0x14da1(%rip)     # 0x19ce4
je 0x4f46
retq
xorl %edx, %edx
leaq 0x142c1(%rip), %rsi     # 0x19210
xorl %eax, %eax
movb $0x1f, %cl
subb (%rdx,%rsi), %cl
movl $0x1, %edi
shlq %cl, %rdi
orl %edi, %eax
incq %rdx
cmpq $0xe, %rdx
jne 0x4f51
xorl %ecx, %ecx
leaq 0x14d7e(%rip), %rdx     # 0x19cf0
movl $0x8, %esi
movl %ecx, %edi
movl %edi, %r8d
andl $0x1, %edi
negl %edi
shrl %r8d
andl %eax, %edi
xorl %r8d, %edi
decl %esi
jne 0x4f79
movl %edi, (%rdx,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x4f72
xorl %edx, %edx
leaq 0x14279(%rip), %rsi     # 0x1921e
xorl %eax, %eax
movb (%rdx,%rsi), %cl
movl $0x1, %edi
shlq %cl, %rdi
orl %edi, %eax
incq %rdx
cmpq $0x3, %rdx
jne 0x4fa7
xorl %ecx, %ecx
leaq 0x1512a(%rip), %rdx     # 0x1a0f0
movl %ecx, %esi
shll $0x8, %esi
movl $0x8, %edi
leal (%rsi,%rsi), %r8d
movswl %si, %esi
sarl $0xf, %esi
andl %eax, %esi
xorl %r8d, %esi
decl %edi
jne 0x4fd0
movw %si, (%rdx,%rcx,2)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x4fc6
xorl %edx, %edx
leaq 0x14225(%rip), %rsi     # 0x19221
xorl %eax, %eax
movb (%rdx,%rsi), %cl
movl $0x1, %edi
shlq %cl, %rdi
orl %edi, %eax
incq %rdx
cmpq $0x3, %rdx
jne 0x4ffe
xorl %ecx, %ecx
leaq 0x152d3(%rip), %rdx     # 0x1a2f0
movl %ecx, %esi
shll $0x8, %esi
movl $0x8, %edi
leal (%rsi,%rsi), %r8d
movswl %si, %esi
sarl $0xf, %esi
andl %eax, %esi
xorl %r8d, %esi
decl %edi
jne 0x5027
movw %si, (%rdx,%rcx,2)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x501d
movl $0x1, 0x14c90(%rip)     # 0x19ce4
retq
// File: /workspace/github_cpp_makefile_star2_O3/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:
testl %esi, %esi
je 0x5085
movl %esi, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %edx, %edx
leaq 0x14c87(%rip), %rsi     # 0x19cf0
movb (%rdi,%rdx), %r8b
xorb %al, %r8b
movzbl %r8b, %r8d
shrl $0x8, %eax
xorl (%rsi,%r8,4), %eax
incq %rdx
cmpl %edx, %ecx
jne 0x5069
notl %eax
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
testl %esi, %esi
je 0x50b6
notl %eax
movl %esi, %ecx
xorl %edx, %edx
leaq 0x14c55(%rip), %rsi     # 0x19cf0
movb (%rdi,%rdx), %r8b
xorb %al, %r8b
movzbl %r8b, %r8d
shrl $0x8, %eax
xorl (%rsi,%r8,4), %eax
incq %rdx
cmpl %edx, %ecx
jne 0x509b
notl %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: CalcCRC_CCITT(unsigned char*, int)
UWORD CalcCRC_CCITT(PUBYTE buf, int len)
{
	UWORD crc=~0;

	while (len--)
		crc=crctab_ccitt[*buf++^(crc>>8)] ^ (crc << 8);

	return crc;
}

// Assembly:
testl %esi, %esi
je 0x50ea
movl %esi, %ecx
movw $0xffff, %ax            # imm = 0xFFFF
xorl %edx, %edx
leaq 0x15026(%rip), %rsi     # 0x1a0f0
movzbl (%rdi,%rdx), %r8d
movzwl %ax, %r9d
shrl $0x8, %r9d
xorl %r8d, %r9d
shll $0x8, %eax
xorw (%rsi,%r9,2), %ax
incq %rdx
cmpl %edx, %ecx
jne 0x50ca
retq
movw $0xffff, %ax            # imm = 0xFFFF
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: CalcCRC16(unsigned char*, int, unsigned int)
UDWORD CalcCRC16(PUBYTE buf, int len, UDWORD seed)
{
	UWORD crc=(UWORD)seed;

	while (len--)
		crc=crctab_ccitt[*buf++^(crc>>8)] ^ (crc << 8);

	return crc;
}

// Assembly:
testl %esi, %esi
je 0x5122
movl %esi, %eax
xorl %ecx, %ecx
leaq 0x14ff2(%rip), %rsi     # 0x1a0f0
movzbl (%rdi,%rcx), %r8d
movzwl %dx, %edx
movl %edx, %r9d
shrl $0x8, %r9d
xorl %r8d, %r9d
movzwl (%rsi,%r9,2), %r8d
shll $0x8, %edx
xorl %r8d, %edx
incq %rcx
cmpl %ecx, %eax
jne 0x50fe
movzwl %dx, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Core/CRC.cpp
// Function: CalcCRC_ANSI(unsigned char*, int)
UWORD CalcCRC_ANSI(PUBYTE buf, int len)
{
	UWORD crc=0;

	while (len--)
		crc=crctab_ansi[*buf++^(crc>>8)] ^ (crc << 8);

	return crc;
}

// Assembly:
testl %esi, %esi
je 0x5157
movl %esi, %ecx
xorl %edx, %edx
leaq 0x151bb(%rip), %rsi     # 0x1a2f0
xorl %eax, %eax
movzbl (%rdi,%rdx), %r8d
movzwl %ax, %r9d
shrl $0x8, %r9d
xorl %r8d, %r9d
shll $0x8, %eax
xorw (%rsi,%r9,2), %ax
incq %rdx
cmpl %edx, %ecx
jne 0x5137
retq
xorl %eax, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodec.cpp
// Function: CCTRawCodec::Free()
void CCTRawCodec::Free()
{
	FreeCompressedDensity();
	FreeUncompressedDensity();
	FreeCompressedTrack();
	FreeUncompressedTrack();
	Clear();
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
je 0x51a8
callq 0x4280
movq $0x0, 0x20(%rbx)
movl $0x0, 0x28(%rbx)
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x51c5
callq 0x4280
movq $0x0, 0x10(%rbx)
movl $0x0, 0x18(%rbx)
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x51e5
callq 0x4280
movq $0x0, 0x88(%rbx)
movl $0x0, 0x90(%rbx)
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5208
callq 0x4280
addq $0x8, %rbx
movl $0xb8, %edx
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x4140
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodec.cpp
// Function: CCTRawCodec::FreeUncompressedTrack(CapsWH*)
void CCTRawCodec::FreeUncompressedTrack(PCAPSWH w)
{
	delete[] w->rawbuf;
	w->rawbuf = NULL;
	w->rawlen = 0;

	for (int trk = 0; trk < CAPS_MTRS; trk++) {
		w->trkbuf[trk] = NULL;
		w->trklen[trk] = 0;
	}

	w->trkcnt = 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
testq %rdi, %rdi
je 0x52fa
callq 0x4280
movq $0x0, 0x30(%rbx)
movl $0x0, 0x38(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x70(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodec.cpp
// Function: CCTRawCodec::Swap(unsigned int*, int)
void CCTRawCodec::Swap(PUDWORD buf, int cnt)
{
#ifdef INTEL
	for (cnt >>= 2; cnt > 0; cnt--, buf++) {
		UDWORD src = *buf;
		UDWORD dst = _lrotl(src, 8) & 0x00ff00ff | _lrotr(src, 8) & 0xff00ff00;
		*buf = dst;
	}
#endif
}

// Assembly:
sarl $0x2, %esi
testl %esi, %esi
jle 0x5338
incl %esi
movl (%rdi), %eax
bswapl %eax
movl %eax, (%rdi)
addq $0x4, %rdi
decl %esi
cmpl $0x1, %esi
ja 0x5327
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodecDecompressor.cpp
// Function: CCTRawCodec::DecompressDump(unsigned char*, int)
int CCTRawCodec::DecompressDump(PUBYTE buf, int len)
{
	CapsPack cpk;
	PCAPSPACK pk;

	// free all buffers
	Free();

	// check dump header
	int hlen = sizeof(CapsRaw);
	if (len < hlen)
		return imgeShort;
	wh.cr = *(PCAPSRAW)buf;
	Swap((PUDWORD)&wh.cr, sizeof(CapsRaw));

	// check dump size
	int tlen = wh.cr.time;
	int rlen = wh.cr.raw;
	if (len < hlen + tlen + rlen)
		return imgeShort;

	// check density information
	PUBYTE denbuf = buf + hlen;
	pk = GetPackHeader(&cpk, denbuf, tlen);
	if (!pk)
		return imgeDensityHeader;

	// check track information
	PUBYTE trkbuf = denbuf + tlen;
	pk = GetPackHeader(&cpk, trkbuf, rlen);
	if (!pk)
		return imgeTrackHeader;

	int err;

	// decompress density information
	wh.cdbuf = denbuf;
	wh.cdlen = tlen;
	if (!(err = DecompressDensity(1)))
		err = DecompressDensity();
	wh.cdbuf = NULL;
	if (err)
		return err;

	// decompress track data
	wh.ctbuf = trkbuf;
	wh.ctlen = rlen;
	if (!(err = DecompressTrack(1)))
		err = DecompressTrack();
	wh.ctbuf = NULL;

	return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
callq 0x5196
movl $0x7, %ebp
cmpl $0x8, %r12d
jl 0x5415
leaq 0x8(%rbx), %rdi
movq (%r15), %rax
movq %rax, 0x8(%rbx)
movl $0x8, %esi
callq 0x531e
movl 0x8(%rbx), %r13d
movl 0xc(%rbx), %r14d
leal (%r14,%r13), %eax
addl $0x8, %eax
cmpl %r12d, %eax
jg 0x5415
addq $0x8, %r15
movq %rsp, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x545a
testq %rax, %rax
je 0x53ef
movslq %r13d, %r12
addq %r15, %r12
movq %rsp, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x545a
testq %rax, %rax
je 0x53f6
movq %r15, 0x20(%rbx)
movl %r13d, 0x28(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x54e0
testl %eax, %eax
je 0x53fd
movl %eax, %ebp
addq $0x20, %rbx
movq %rbx, %r15
movq $0x0, (%r15)
jmp 0x5415
movl $0xb, %ebp
jmp 0x5415
movl $0x8, %ebp
jmp 0x5415
movq %rbx, %rdi
xorl %esi, %esi
callq 0x54e0
movl %eax, %ebp
movq $0x0, 0x20(%rbx)
testl %eax, %eax
je 0x5426
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x88(%rbx), %r15
movq %r12, 0x88(%rbx)
movl %r14d, 0x90(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x55bc
testl %eax, %eax
jne 0x5456
movq %rbx, %rdi
xorl %esi, %esi
callq 0x55bc
movl %eax, %ebp
jmp 0x53e6
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodecDecompressor.cpp
// Function: CCTRawCodec::GetPackHeader(CapsPack*, unsigned char*, int)
PCAPSPACK CCTRawCodec::GetPackHeader(PCAPSPACK cpk, PUBYTE src, int slen)
{
	// check header size
	if (!src || slen<sizeof(CapsPack))
		return NULL;

	// check signature
	if (memcmp(src, CAPS_IDPACK, sizeof(cpk->sign)))
		return NULL;

	// copy header to result
	memcpy(cpk, src, sizeof(CapsPack));

	// change header crc to host format and check crc
	Swap(&cpk->hcrc, sizeof(cpk->hcrc));
	UDWORD hcrc = cpk->hcrc;
	cpk->hcrc = 0;
	if (hcrc != CalcCRC((PUBYTE)cpk, sizeof(CapsPack)))
		return NULL;

	// change header to host format
	Swap(PUDWORD(PUBYTE(cpk) + sizeof(cpk->sign)), sizeof(CapsPack) - sizeof(cpk->sign));

	// buffer length must match the size of header and compressed data size
	if ((UDWORD)slen != sizeof(CapsPack) + cpk->csize)
		return NULL;

	return cpk;
}

// Assembly:
testq %rsi, %rsi
sete %al
cmpl $0x18, %edx
setb %cl
orb %al, %cl
jne 0x5472
cmpl $0x4b434150, (%rsi)     # imm = 0x4B434150
je 0x5475
xorl %eax, %eax
retq
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebp
movq %rdi, %rbx
movq 0x10(%rsi), %rax
movq %rax, 0x10(%rdi)
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
addq $0x14, %rdi
movl $0x4, %esi
callq 0x531e
movl 0x14(%rbx), %r14d
movl $0x0, 0x14(%rbx)
movq %rbx, %rdi
movl $0x18, %esi
callq 0x5055
cmpl %eax, %r14d
jne 0x54d9
leaq 0x4(%rbx), %rdi
movl $0x14, %esi
callq 0x531e
movl %ebp, %ecx
movl 0xc(%rbx), %edx
addq $0x18, %rdx
xorl %eax, %eax
cmpq %rcx, %rdx
cmoveq %rbx, %rax
jmp 0x54db
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodecDecompressor.cpp
// Function: CCTRawCodec::DecompressDensity(int)
int CCTRawCodec::DecompressDensity(int verify)
{
	CapsPack cpk;

	// in decompress mode free result buffer first
	if (!verify)
		FreeUncompressedDensity();

	// get density header
	PCAPSPACK pk = GetPackHeader(&cpk, wh.cdbuf, wh.cdlen);
	if (!pk)
		return imgeDensityHeader;

	// check crc on compressed data in verify mode
	if (verify)
		if (pk->ccrc != CalcCRC(wh.cdbuf + sizeof(CapsPack), pk->csize))
			return imgeDensityStream;

	// decompress density data
	PUDWORD dst = DecompressDensity(wh.cdbuf, wh.cdlen);
	int res = imgeOk;

	if (verify) {
		// in verify mode get density data in target format
		Swap(dst, pk->usize);

		// check crc on uncompressed data
		if (pk->ucrc != CalcCRC((PUBYTE)dst, pk->usize))
			res = imgeDensityData;

		// free density data
		delete[] dst;
	}	else {
		// in decompress mode save density data
		wh.timbuf = dst;
		wh.timlen = pk->usize >> 2;
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movl %esi, %ebp
movq %rdi, %rbx
testl %esi, %esi
jne 0x54fd
movq %rbx, %rdi
callq 0x5262
movq 0x20(%rbx), %rsi
movl 0x28(%rbx), %edx
leaq 0x8(%rsp), %rdi
callq 0x545a
testq %rax, %rax
je 0x5584
movq %rax, %r14
testl %ebp, %ebp
je 0x558c
movl 0xc(%r14), %esi
movl 0x10(%r14), %ebp
movq 0x20(%rbx), %rdi
addq $0x18, %rdi
callq 0x5055
movl $0xc, %r15d
cmpl %eax, %ebp
jne 0x55ab
movq 0x20(%rbx), %rdi
movl 0x28(%rbx), %esi
xorl %r12d, %r12d
xorl %edx, %edx
callq 0x56d0
movq %rax, %rbx
movl 0x4(%r14), %esi
movq %rax, %rdi
callq 0x531e
movl 0x4(%r14), %esi
movl 0x8(%r14), %ebp
movq %rbx, %rdi
callq 0x5055
cmpl %eax, %ebp
movl $0xd, %r15d
cmovel %r12d, %r15d
testq %rbx, %rbx
je 0x55ab
movq %rbx, %rdi
callq 0x4280
jmp 0x55ab
movl $0xb, %r15d
jmp 0x55ab
movq 0x20(%rbx), %rdi
movl 0x28(%rbx), %esi
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x56d0
movq %rax, 0x10(%rbx)
movl 0x4(%r14), %eax
shrl $0x2, %eax
movl %eax, 0x18(%rbx)
movl %r15d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Codec/CTRawCodecDecompressor.cpp
// Function: CCTRawCodec::DecompressTrack(int)
int CCTRawCodec::DecompressTrack(int verify)
{
	CapsPack cpk;
	CapsWH cwh;

	// in decompress mode free result buffer first
	if (!verify)
		FreeUncompressedTrack();

	// get track header
	PCAPSPACK pk = GetPackHeader(&cpk, wh.ctbuf, wh.ctlen);
	if (!pk)
		return imgeTrackHeader;

	// check crc on compressed data in verify mode
	if (verify)
		if (pk->ccrc != CalcCRC(wh.ctbuf + sizeof(CapsPack), pk->csize))
			return imgeTrackStream;

	// decompress track data
	PCAPSWH wb = DecompressTrack(&cwh, wh.ctbuf, wh.ctlen);
	int res = imgeOk;

	if (verify) {
		// in verify mode check crc on uncompressed data
		if (pk->ucrc != CalcCRC(wb->rawbuf, wb->rawlen))
			res = imgeTrackData;

		// free track data
		FreeUncompressedTrack(wb);
	} else {
		// in decompress mode save track data
		wh.rawbuf = wb->rawbuf;
		wh.rawlen = wb->rawlen;

		for (int trk = 0; trk < CAPS_MTRS; trk++) {
			wh.trkbuf[trk] = wb->trkbuf[trk];
			wh.trklen[trk] = wb->trklen[trk];
		}

		wh.trkcnt = wb->trkcnt;
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
testl %esi, %esi
jne 0x55da
movq %rbx, %rdi
callq 0x52b2
movq 0x88(%rbx), %rsi
movl 0x90(%rbx), %edx
leaq 0x8(%rsp), %rdi
callq 0x545a
testq %rax, %rax
je 0x5666
testl %ebp, %ebp
je 0x566d
movq %rax, %r14
movl 0xc(%rax), %esi
movl 0x10(%rax), %r15d
movq 0x88(%rbx), %rdi
addq $0x18, %rdi
callq 0x5055
movl $0x9, %ebp
cmpl %eax, %r15d
jne 0x56c0
movq 0x88(%rbx), %rsi
movl 0x90(%rbx), %edx
xorl %r15d, %r15d
leaq 0x20(%rsp), %rdi
xorl %ecx, %ecx
callq 0x583e
movq %rax, %rbx
movl 0x8(%r14), %ebp
movq 0x30(%rax), %rdi
movl 0x38(%rax), %esi
callq 0x5055
cmpl %eax, %ebp
movl $0xa, %ebp
cmovel %r15d, %ebp
movq %rbx, %rdi
callq 0x52e8
jmp 0x56c0
movl $0x8, %ebp
jmp 0x56c0
movq 0x88(%rbx), %rsi
movl 0x90(%rbx), %edx
xorl %r14d, %r14d
leaq 0x20(%rsp), %rdi
xorl %ecx, %ecx
callq 0x583e
movq 0x30(%rax), %rcx
movq %rcx, 0x38(%rbx)
movl 0x38(%rax), %ecx
movl %ecx, 0x40(%rbx)
movq 0x40(%rax,%r14,2), %rcx
movq %rcx, 0x48(%rbx,%r14,2)
movl 0x68(%rax,%r14), %ecx
movl %ecx, 0x70(%rbx,%r14)
addq $0x4, %r14
cmpq $0x14, %r14
jne 0x5697
movl 0x7c(%rax), %eax
movl %eax, 0x84(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq