// File: /workspace/github_c_makefile_star2_O2/dolphinking[P]slimox/src/slimox-ppm.h
// Function: _o4_context_node
static inline o4_context_t* __o4_context_node(ppm_model_t* model) {
    o4_context_t* o4;
    o4_context_t* o4_prev;
    int i;

    if(model->m_o4_counts >= 1048576) { /* too many o4-context/symbol nodes */
        model->m_o4_counts = 0;
        for(i = 0; i < 262144; i++) {
            while(model->m_o4_buckets[i] && model->m_o4_buckets[i]->m_visited / 2 == 0) {
                o4 = model->m_o4_buckets[i];
                model->m_o4_buckets[i] = model->m_o4_buckets[i]->m_next;
                allocator_free(model->m_o4_allocator, o4);
            }
            for(o4 = model->m_o4_buckets[i]; o4 != NULL; o4 = o4->m_next) {
                if((o4->m_visited /= 2) == 0) {
                    o4_prev->m_next = o4->m_next;
                    allocator_free(model->m_o4_allocator, o4);
                    o4 = o4_prev;
                } else {
                    model->m_o4_counts += 1;
                    o4_prev = o4;
                }
            }
        }
    }

    o4 = model->m_o4_buckets[__o4_hash(model->m_context)];
    o4_prev = NULL;
    while(o4 && o4->m_context != model->m_context) { /* search for o4 context */
        o4_prev = o4;
        o4 = o4->m_next;
    }
    if(o4 != NULL) { /* found -- bring to front of linked-list */
        if(o4_prev != NULL) {
            o4_prev->m_next = o4->m_next;
            o4->m_next = model->m_o4_buckets[__o4_hash(model->m_context)];
            model->m_o4_buckets[__o4_hash(model->m_context)] = o4;
        }
    } else { /* not found -- create new node for context */
        o4 = allocator_alloc(model->m_o4_allocator, sizeof(o4_context_t), 8192);
        memset(o4->m_symbols, 0, sizeof(o4->m_symbols));
        o4->m_context = model->m_context;
        o4->m_sum = 0;
        o4->m_cnt = 0;
        o4->m_visited = 0;
        o4->m_next = model->m_o4_buckets[__o4_hash(model->m_context)];
        model->m_o4_counts += 1;
        model->m_o4_buckets[__o4_hash(model->m_context)] = o4;
    }
    o4->m_visited += (o4->m_visited < 255);
    return o4;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x100000, 0x8(%rdi)    # imm = 0x100000
jb 0x4d09
andl $0x0, 0x8(%rbx)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x40000, %rcx          # imm = 0x40000
je 0x4d09
movq 0x10(%rbx,%rcx,8), %rsi
testq %rsi, %rsi
je 0x4cff
cmpb $0x2, 0xf(%rsi)
jae 0x4cff
movq (%rsi), %rdi
movq %rdi, 0x10(%rbx,%rcx,8)
movq 0x2a0820(%rbx), %rdi
movq 0x8(%rdi), %r8
movq %r8, (%rsi)
movq %rsi, 0x8(%rdi)
jmp 0x4c9a
movb 0xf(%rsi), %dil
movl %edi, %r8d
shrb %r8b
movb %r8b, 0xf(%rsi)
cmpb $0x1, %dil
ja 0x4cf4
movq (%rsi), %rdi
movq %rdi, (%rdx)
movq 0x2a0820(%rbx), %rdi
movq 0x8(%rdi), %r8
movq %r8, (%rsi)
movq %rsi, 0x8(%rdi)
jmp 0x4cfc
incl %eax
movl %eax, 0x8(%rbx)
movq %rsi, %rdx
movq (%rdx), %rsi
testq %rsi, %rsi
jne 0x4cc6
incq %rcx
jmp 0x4c91
movl (%rbx), %ecx
movl %ecx, %eax
shrl $0xe, %eax
movl %ecx, %edx
andl $0x3ffff, %edx          # imm = 0x3FFFF
xorl %eax, %edx
leaq (%rbx,%rdx,8), %rax
addq $0x10, %rax
xorl %esi, %esi
movq %rax, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x4d51
movq %rsi, %rdx
movq %r14, %rsi
cmpl %ecx, 0x8(%r14)
jne 0x4d27
testq %rdx, %rdx
je 0x4da1
movq (%r14), %rcx
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, (%r14)
movq %r14, (%rax)
jmp 0x4da1
movq 0x2a0820(%rbx), %rdi
movl $0x94, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x4dbb
movq %rax, %r14
leaq 0x10(%rax), %rdi
movl $0x84, %edx
xorl %esi, %esi
callq 0x10e0
movl (%rbx), %eax
movl %eax, 0x8(%r14)
andl $0x0, 0xc(%r14)
movl %eax, %ecx
shrl $0xe, %ecx
andl $0x3ffff, %eax          # imm = 0x3FFFF
xorl %ecx, %eax
movq 0x10(%rbx,%rax,8), %rcx
movq %rcx, (%r14)
incl 0x8(%rbx)
movq %r14, 0x10(%rbx,%rax,8)
movb 0xf(%r14), %al
cmpb $-0x1, %al
setne %cl
addb %al, %cl
movb %cl, 0xf(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq