// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore.xo.c
// Function: bcore_huffman_selftest
void bcore_huffman_selftest( void )
{
    // bcore_huffman.x:567:1
    BLM_INIT_LEVEL(0);
    bcore_prsg_lcg_u3_00_s prsg;BLM_T_INIT_SPUSH(bcore_prsg_lcg_u3_00_s, &prsg);;
    
    sz_t n = 100000;
    
    bcore_arr_s3_s arr_s3;BLM_T_INIT_SPUSH(bcore_arr_s3_s, &arr_s3);;
    for(sz_t i = 0; i < n; i++ )
    {
        f3_t v = bcore_prsg_lcg_u3_00_s_gen_f3(&(prsg),0.0, 1.0 );
        s3_t x = pow( sin( v * 3.141 * 2.0 ), 10 + 1 ) * 1000;
        bcore_arr_s3_s_push(&(arr_s3),x );
    }
    
    
    /// huffman codec
    {BLM_INIT_LEVEL(1);
        bcore_huffman_codec_s codec;BLM_T_INIT_SPUSH(bcore_huffman_codec_s, &codec);;
        bcore_huffman_codec_s_scan_start(&(codec));
        for(sz_t i = 0; i < n; i++ ) bcore_huffman_codec_s_scan_s3(&(codec),arr_s3.data[ i ] );
        bcore_huffman_codec_s_scan_end(&(codec));
    
        bcore_huffman_bit_buffer_s bit_buffer;BLM_T_INIT_SPUSH(bcore_huffman_bit_buffer_s, &bit_buffer);;
    
        bcore_huffman_codec_s_encode(&(codec),&(bit_buffer ));
        for(sz_t i = 0; i < n; i++ ) bcore_huffman_codec_s_encode_s3(&(codec),arr_s3.data[ i ],&( bit_buffer ));
    
        bcore_huffman_bit_buffer_iterator_s iterator;BLM_T_INIT_SPUSH(bcore_huffman_bit_buffer_iterator_s, &iterator);bcore_huffman_bit_buffer_iterator_s_setup(&(iterator),&(bit_buffer ));
    
        bcore_huffman_codec_s codec2;BLM_T_INIT_SPUSH(bcore_huffman_codec_s, &codec2);bcore_huffman_codec_s_decode(&(codec2),&(iterator ));
        for(sz_t i = 0; i < n; i++ ) ASSERT( bcore_huffman_codec_s_decode_s3(&(codec2),&(iterator )) == arr_s3.data[ i ] );
    BLM_DOWN();}
    
    /// direct s3 codec
    {BLM_INIT_LEVEL(1);
        s3_t max = bcore_arr_s3_s_max(&(arr_s3));
        s3_t min = bcore_arr_s3_s_min(&(arr_s3));
        sz_t bits = 0;
        while( ( max >> bits ) > 0 || ( min >> bits ) < -1 ) bits++;
        bits++;
    
        bcore_huffman_bit_buffer_s bit_buffer;BLM_T_INIT_SPUSH(bcore_huffman_bit_buffer_s, &bit_buffer);;
        for(sz_t i = 0; i < n; i++ ) bcore_huffman_bit_buffer_s_push_s3(&(bit_buffer),arr_s3.data[ i ], bits );
    
        bcore_huffman_bit_buffer_iterator_s iterator;BLM_T_INIT_SPUSH(bcore_huffman_bit_buffer_iterator_s, &iterator);bcore_huffman_bit_buffer_iterator_s_setup(&(iterator),&(bit_buffer ));
        for(sz_t i = 0; i < n; i++ ) ASSERT( bcore_huffman_bit_buffer_iterator_s_read_s3(&(iterator),bits ) == arr_s3.data[ i ] );
    BLM_DOWN();}
    
    BLM_DOWN();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
leaq 0x12ed7f(%rip), %rax    # 0x19bdd0
movq (%rax), %rsi
leaq 0xf0(%rsp), %r14
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0xd6675
movq $0x0, 0x10(%r14)
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x59077
movabsq $-0x1804b258fae5f3f6, %rsi # imm = 0xE7FB4DA7051A0C0A
movq %r14, %rdi
movq %rbx, %rdx
callq 0xd68d9
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0xb7e91
movabsq $0x2cabd5fd9af9a7b7, %rsi # imm = 0x2CABD5FD9AF9A7B7
movq %r14, %rdi
movq %rbx, %rdx
callq 0xd68d9
movl $0x186a0, %r14d         # imm = 0x186A0
movabsq $0x1c140000000001cd, %r15 # imm = 0x1C140000000001CD
movq 0x40(%rsp), %rax
imulq %r15, %rax
incq %rax
movq %rax, 0x40(%rsp)
movq %rax, %xmm1
punpckldq 0xca1fd(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xca205(%rip), %xmm1    # 0x1372f0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0xca189(%rip), %xmm0    # 0x137288
addsd 0xca1a1(%rip), %xmm0    # 0x1372a8
mulsd 0xca181(%rip), %xmm0    # 0x137290
addsd %xmm0, %xmm0
callq 0xd4b0
movsd 0xca178(%rip), %xmm1    # 0x137298
callq 0xd470
mulsd 0xca173(%rip), %xmm0    # 0x1372a0
cvttsd2si %xmm0, %rsi
movq %rbx, %rdi
callq 0xb8150
decq %r14
jne 0x6d0c5
movabsq $0x7dbd1c5e923a8433, %r15 # imm = 0x7DBD1C5E923A8433
leaq 0x48(%rsp), %r14
movq %r14, 0x8(%rsp)
leaq 0xf0(%rsp), %rsi
movq %r14, %rdi
callq 0xd6675
movq $0x1, 0x10(%r14)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x68b2c
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd68d9
movq %rbx, %rdi
callq 0x68fcf
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq (%rax,%r12,8), %rax
leaq (%rax,%rax), %rcx
testq %rax, %rax
notq %rax
leaq 0x1(%rax,%rax), %r14
cmovnsq %rcx, %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0x68ffb
shrq $0x20, %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0x68ffb
incq %r12
cmpq $0x186a0, %r12          # imm = 0x186A0
jne 0x6d194
movabsq $-0x20f7792dc858395f, %r12 # imm = 0xDF0886D237A7C6A1
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x69072
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x69f24
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xd68d9
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x6d220
leaq 0x78(%rsp), %rsi
callq 0x69902
xorl %r13d, %r13d
leaq 0xa0(%rsp), %r14
leaq 0x78(%rsp), %rbx
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rax
leaq (%rax,%rax), %rcx
testq %rax, %rax
notq %rax
leaq 0x1(%rax,%rax), %r12
cmovnsq %rcx, %r12
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x695c1
shrq $0x20, %r12
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x695c1
incq %r13
cmpq $0x186a0, %r13          # imm = 0x186A0
jne 0x6d230
movabsq $0x93943e0ef30024c, %r14 # imm = 0x93943E0EF30024C
leaq 0x120(%rsp), %r13
movq %r13, %rdi
callq 0x6af34
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xd68d9
movq $0x0, 0x10(%r13)
movq %rbx, 0x8(%r13)
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
callq 0x68b2c
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xd68d9
movq %rbp, %rdi
movq %r13, %rsi
callq 0x69b81
leaq 0xca8ce(%rip), %r14     # 0x137baf
leaq 0xca046(%rip), %r12     # 0x13732e
xorl %r15d, %r15d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x69738
movl %eax, %ebx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x69738
shlq $0x20, %rax
leaq (%rax,%rbx), %rcx
addq %rbx, %rax
decq %rax
shrq %rax
shrq %rcx
testb $0x1, %bl
notq %rax
cmoveq %rcx, %rax
movq 0x20(%rsp), %rcx
cmpq (%rcx,%r15,8), %rax
je 0x6d34d
leaq 0xc0314(%rip), %rdi     # 0x12d647
leaq 0xca829(%rip), %rsi     # 0x137b63
movq %r14, %rdx
movq %r12, %rcx
movl $0xc2c, %r8d            # imm = 0xC2C
xorl %eax, %eax
callq 0xbe4ef
incq %r15
cmpq $0x186a0, %r15          # imm = 0x186A0
jne 0x6d2eb
leaq 0x8(%rsp), %rdi
callq 0xd6d0d
leaq 0x48(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
leaq 0xf0(%rsp), %rsi
callq 0xd6675
movq $0x1, 0x58(%rsp)
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0xb8565
movq %rax, %rbx
movq %r14, %rdi
callq 0xb8597
xorl %r15d, %r15d
movq %rbx, %rsi
movl %r15d, %ecx
sarq %cl, %rsi
movq %rax, %rdx
sarq %cl, %rdx
incq %r15
testq %rsi, %rsi
jg 0x6d3a1
cmpq $-0x1, %rdx
jl 0x6d3a1
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
callq 0x69f24
leaq 0x48(%rsp), %rdi
movabsq $-0x20f7792dc858395f, %rsi # imm = 0xDF0886D237A7C6A1
movq %r12, %rdx
callq 0xd68d9
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %r14
xorl %r13d, %r13d
xorl %esi, %esi
btq %r13, %r14
setb %sil
movq %r12, %rdi
callq 0x696de
incq %r13
cmpq %r13, %r15
jne 0x6d3f3
incq %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jne 0x6d3e7
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x6af34
leaq 0x48(%rsp), %rdi
movabsq $0x93943e0ef30024c, %rsi # imm = 0x93943E0EF30024C
movq %rbx, %rdx
callq 0xd68d9
movq $0x0, 0x10(%rbx)
movq %r12, 0x8(%rbx)
leaq 0xca776(%rip), %r12     # 0x137bc6
leaq 0xca758(%rip), %r13     # 0x137baf
leaq 0xc9ed0(%rip), %rbp     # 0x13732e
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6b44d
movq 0x20(%rsp), %rcx
cmpq (%rcx,%r14,8), %rax
je 0x6d494
leaq 0xc01c9(%rip), %rdi     # 0x12d647
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movl $0xc3b, %r8d            # imm = 0xC3B
xorl %eax, %eax
callq 0xbe4ef
incq %r14
cmpq $0x186a0, %r14          # imm = 0x186A0
jne 0x6d461
leaq 0xc8(%rsp), %rdi
callq 0xd6d0d
leaq 0x10(%rsp), %rdi
callq 0xd6d0d
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq