// File: /workspace/github_c_makefile_star2_O2/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 0xe31d1(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0xc8(%rsp), %r14
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x717f5
andq $0x0, 0x10(%r14)
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x2fe03
movabsq $-0x1804b258fae5f3f6, %rsi # imm = 0xE7FB4DA7051A0C0A
movq %r14, %rdi
movq %rbx, %rdx
callq 0x71998
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x5a9e5
movabsq $0x2cabd5fd9af9a7b7, %rsi # imm = 0x2CABD5FD9AF9A7B7
movq %r14, %rdi
movq %rbx, %rdx
callq 0x71998
movl $0x186a0, %r14d         # imm = 0x186A0
movabsq $0x1c140000000001cd, %r15 # imm = 0x1C140000000001CD
subq $0x1, %r14
jb 0x34ced
movq 0x40(%rsp), %rax
imulq %r15, %rax
incq %rax
movq %rax, 0x40(%rsp)
movq %rax, %xmm1
punpckldq 0x7fa1c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x7fa24(%rip), %xmm1    # 0xb46c0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x7fa40(%rip), %xmm0    # 0xb46f0
addsd 0x7fa58(%rip), %xmm0    # 0xb4710
mulsd 0x7fa38(%rip), %xmm0    # 0xb46f8
addsd %xmm0, %xmm0
callq 0xd4b0
movsd 0x7fa2f(%rip), %xmm1    # 0xb4700
callq 0xd470
mulsd 0x7fa2a(%rip), %xmm0    # 0xb4708
cvttsd2si %xmm0, %rsi
movq %rbx, %rdi
callq 0x5ac52
jmp 0x34c70
movabsq $0x7dbd1c5e923a8433, %r15 # imm = 0x7DBD1C5E923A8433
leaq 0x48(%rsp), %r14
movq %r14, 0x8(%rsp)
leaq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x717f5
movq $0x1, 0x10(%r14)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x337d3
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x71998
movq %rbx, %rdi
callq 0x338bf
xorl %r14d, %r14d
cmpq $0x186a0, %r14          # imm = 0x186A0
je 0x34d74
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %rax
leaq (%rax,%rax), %rcx
testq %rax, %rax
notq %rax
leaq 0x1(%rax,%rax), %rsi
cmovnsq %rcx, %rsi
movq %rbx, %rdi
callq 0x3393e
incq %r14
jmp 0x34d42
movabsq $-0x20f7792dc858395f, %rbx # imm = 0xDF0886D237A7C6A1
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x33962
leaq 0xf8(%rsp), %rbp
movq %rbp, %rdi
callq 0x34278
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x71998
movq %r14, %rdi
movq %rbp, %rsi
callq 0x33ef1
xorl %ebx, %ebx
cmpq $0x186a0, %rbx          # imm = 0x186A0
je 0x34df0
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %rax
leaq (%rax,%rax), %rcx
testq %rax, %rax
notq %rax
leaq 0x1(%rax,%rax), %rsi
cmovnsq %rcx, %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x33e9c
incq %rbx
jmp 0x34dbb
movabsq $0x93943e0ef30024c, %rbx # imm = 0x93943E0EF30024C
leaq 0x120(%rsp), %r13
movq %r13, %rdi
callq 0x346d3
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x71998
andq $0x0, 0x10(%r13)
movq %rbp, 0x8(%r13)
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
callq 0x337d3
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x71998
movq %rbp, %rdi
movq %r13, %rsi
callq 0x340ba
leaq 0x80130(%rip), %rbx     # 0xb4f83
leaq 0x80175(%rip), %r14     # 0xb4fcf
leaq 0x7f8ed(%rip), %r12     # 0xb474e
xorl %r15d, %r15d
cmpq $0x186a0, %r15          # imm = 0x186A0
je 0x34ebb
movq %rbp, %rdi
movq %r13, %rsi
callq 0x33ec6
leaq -0x1(%rax), %rcx
shrq %rcx
movq %rax, %rdx
shrq %rdx
testb $0x1, %al
notq %rcx
cmoveq %rdx, %rcx
movq 0x20(%rsp), %rax
cmpq (%rax,%r15,8), %rcx
je 0x34eb6
leaq 0x757a7(%rip), %rdi     # 0xaa647
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
movl $0xc2c, %r8d            # imm = 0xC2C
xorl %eax, %eax
callq 0x5ffac
incq %r15
jmp 0x34e64
leaq 0x8(%rsp), %rdi
callq 0x71b48
leaq 0x48(%rsp), %rdi
movq %rdi, 0x78(%rsp)
leaq 0xc8(%rsp), %rsi
callq 0x717f5
movq $0x1, 0x58(%rsp)
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x5b043
movq %rax, %rbx
movq %r14, %rdi
callq 0x5b06e
xorl %r15d, %r15d
movq %rbx, %rsi
movl %r15d, %ecx
sarq %cl, %rsi
movq %rax, %rdx
sarq %cl, %rdx
incq %r15
testq %rsi, %rsi
jg 0x34f00
cmpq $-0x1, %rdx
jl 0x34f00
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x34278
leaq 0x48(%rsp), %rdi
movabsq $-0x20f7792dc858395f, %rsi # imm = 0xDF0886D237A7C6A1
movq %r14, %rdx
callq 0x71998
xorl %ebx, %ebx
cmpq $0x186a0, %rbx          # imm = 0x186A0
je 0x34f68
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x3430d
incq %rbx
jmp 0x34f46
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x346d3
leaq 0x48(%rsp), %rdi
movabsq $0x93943e0ef30024c, %rsi # imm = 0x93943E0EF30024C
movq %rbx, %rdx
callq 0x71998
andq $0x0, 0x10(%rbx)
movq %r14, 0x8(%rbx)
leaq 0x80047(%rip), %r12     # 0xb4fe6
leaq 0x80029(%rip), %r13     # 0xb4fcf
leaq 0x7f7a1(%rip), %rbp     # 0xb474e
xorl %r14d, %r14d
cmpq $0x186a0, %r14          # imm = 0x186A0
je 0x34ff1
movq %rbx, %rdi
movq %r15, %rsi
callq 0x347ae
movq 0x20(%rsp), %rcx
cmpq (%rcx,%r14,8), %rax
je 0x34fec
leaq 0x75671(%rip), %rdi     # 0xaa647
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movl $0xc3b, %r8d            # imm = 0xC3B
xorl %eax, %eax
callq 0x5ffac
incq %r14
jmp 0x34fb0
leaq 0x78(%rsp), %rdi
callq 0x71b48
leaq 0x10(%rsp), %rdi
callq 0x71b48
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq