// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore.xo.c
// Function: bcore_huffman_count_map_s_encode
bcore_huffman_count_map_s* bcore_huffman_count_map_s_encode( bcore_huffman_count_map_s* o, bcore_huffman_bit_buffer_s* out )
{
    // bcore_huffman.x:458:1
    
    if( !bcore_huffman_count_map_s_is_sorted(o) ) ERR_fa( "Map is not sorted." );
    
    bcore_huffman_bit_buffer_s_push_packed_u3(out,o->size );
    
    sz_t idx = 0;
    u3_t count = 0;
    
    {
        for(; idx < o->size && o->data[ idx ].c == 1 ; idx++ ) count++;
        bcore_huffman_bit_buffer_s_push_packed_u3(out,count );
    }
    
    sz_t bits = 2;
    while( idx < o->size )
    {
        count = 0;
        for(sz_t i = idx; i < o->size && bcore_huffman_min_bits(o->data[ i ].c, 64 ) == bits ; i++ ) count++;
        if( count > 0 )
        {
            bcore_huffman_bit_buffer_s_push_u3(out,bits - 1, 6 );
            bcore_huffman_bit_buffer_s_push_packed_u3(out,count );
            for(sz_t i = 0; i < count; i++ ) bcore_huffman_bit_buffer_s_push_u3(out,o->data[ idx + i ].c, bits - 1 );
        }
        idx += count;
        bits++;
    }
    
    sz_t max_bits = 0;
    for(sz_t i = 0; i < o->size; i++ ) max_bits = sz_max( max_bits, bcore_huffman_min_bits(o->data[ i ].v, 32 ) );
    bcore_huffman_bit_buffer_s_push_u3(out,max_bits, 6 );
    for(sz_t i = 0; i < o->size; i++ ) bcore_huffman_bit_buffer_s_push_u3(out,o->data[ i ].v, max_bits );
    
    return  o;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r13
callq 0x34afb
testb %al, %al
jne 0x33f46
leaq 0x80feb(%rip), %rdi     # 0xb4f17
leaq 0x8081b(%rip), %rsi     # 0xb474e
leaq 0x80ffe(%rip), %rcx     # 0xb4f38
movl $0xb99, %edx            # imm = 0xB99
xorl %eax, %eax
callq 0x60186
movq 0x10(%r13), %rsi
movq %rbx, (%rsp)
movq %rbx, %rdi
callq 0x34353
movq 0x10(%r13), %rbx
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x33f7a
movq 0x8(%r13), %rdx
cmpq $0x1, (%rdx,%rax)
jne 0x33f77
incq %rcx
addq $0x10, %rax
jmp 0x33f5e
movq %rcx, %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x34353
pushq $0x2
popq %rax
movq %rax, 0x10(%rsp)
movq %r13, 0x8(%rsp)
movq 0x10(%r13), %r15
cmpq %r15, %rbx
jae 0x34036
movq %rbx, %r12
shlq $0x4, %r12
movq %r12, %r13
xorl %ebp, %ebp
leaq (%rbx,%rbp), %r14
cmpq %r15, %r14
jae 0x33fda
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r13), %rdi
pushq $0x40
popq %rsi
callq 0x34397
cmpq 0x10(%rsp), %rax
jne 0x33fda
incq %rbp
addq $0x10, %r13
jmp 0x33fac
testq %rbp, %rbp
movq 0x8(%rsp), %r13
movq (%rsp), %rbx
je 0x34029
movq 0x10(%rsp), %rax
leaq -0x1(%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
pushq $0x6
popq %rdx
callq 0x3430d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34353
subq $0x1, %rbp
jb 0x34029
movq 0x8(%r13), %rax
movq (%rax,%r12), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3430d
addq $0x10, %r12
jmp 0x3400a
incq 0x10(%rsp)
movq %r14, %rbx
jmp 0x33f93
pushq $0x8
popq %r14
xorl %r13d, %r13d
pushq $0x20
popq %r12
movq (%rsp), %rbx
subq $0x1, %r15
jb 0x3406d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rax,%r14), %edi
movq %r12, %rsi
callq 0x34397
cmpq %rax, %r13
cmovleq %rax, %r13
addq $0x10, %r14
jmp 0x34045
pushq $0x6
popq %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3430d
pushq $0x8
popq %rbx
xorl %r14d, %r14d
movq 0x8(%rsp), %r15
cmpq 0x10(%r15), %r14
jae 0x340a8
movq 0x8(%r15), %rax
movl (%rax,%rbx), %esi
movq (%rsp), %rdi
movq %r13, %rdx
callq 0x3430d
incq %r14
addq $0x10, %rbx
jmp 0x34086
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq