// File: /workspace/github_c_makefile_star2_O1/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 0x1356fd(%rip), %rax    # 0x1a8dd0
movq (%rax), %rsi
leaq 0x108(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xe0431
movq 0x8(%rsp), %r14
movq $0x0, 0x10(%r14)
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x5ec0a
movabsq $-0x1804b258fae5f3f6, %rsi # imm = 0xE7FB4DA7051A0C0A
movq %r14, %rdi
movq %rbx, %rdx
callq 0xe06ab
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0xc191e
movabsq $0x2cabd5fd9af9a7b7, %rsi # imm = 0x2CABD5FD9AF9A7B7
movq %r14, %rdi
movq %rbx, %rdx
callq 0xe06ab
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 0xceb29(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xceb31(%rip), %xmm1    # 0x1422a0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0xceb4d(%rip), %xmm0    # 0x1422d0
addsd 0xceb65(%rip), %xmm0    # 0x1422f0
mulsd 0xceb45(%rip), %xmm0    # 0x1422d8
addsd %xmm0, %xmm0
callq 0xd4a0
movsd 0xceb3c(%rip), %xmm1    # 0x1422e0
callq 0xd460
mulsd 0xceb37(%rip), %xmm0    # 0x1422e8
cvttsd2si %xmm0, %rsi
movq %rbx, %rdi
callq 0xc1bd1
decq %r14
jne 0x73749
movabsq $0x7dbd1c5e923a8433, %r12 # imm = 0x7DBD1C5E923A8433
movq 0x8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xe0431
movq 0x10(%rsp), %r13
movq $0x1, 0x10(%r13)
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x6f024
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0xe06ab
movq %rbx, %rdi
callq 0x6f4e4
xorl %r15d, %r15d
movq 0x20(%rsp), %rax
movq (%rax,%r15,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 0x6f510
shrq $0x20, %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6f510
incq %r15
cmpq $0x186a0, %r15          # imm = 0x186A0
jne 0x7381a
movabsq $-0x20f7792dc858395f, %r15 # imm = 0xDF0886D237A7C6A1
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x6f585
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x7046a
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xe06ab
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x738a4
leaq 0x70(%rsp), %rsi
callq 0x6fe2c
xorl %ebp, %ebp
leaq 0x98(%rsp), %r14
leaq 0x70(%rsp), %rbx
movq 0x20(%rsp), %rax
movq (%rax,%rbp,8), %rax
leaq (%rax,%rax), %rcx
testq %rax, %rax
notq %rax
leaq 0x1(%rax,%rax), %r15
cmovnsq %rcx, %r15
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x6fafd
shrq $0x20, %r15
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x6fafd
incq %rbp
cmpq $0x186a0, %rbp          # imm = 0x186A0
jne 0x738b3
movabsq $0x93943e0ef30024c, %r14 # imm = 0x93943E0EF30024C
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
callq 0x714ce
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xe06ab
movq $0x0, 0x10(%rbp)
movq %rbx, 0x8(%rbp)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x6f024
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xe06ab
movq %r14, %rdi
movq %rbp, %rsi
callq 0x700ad
leaq 0xcf3db(%rip), %r15     # 0x142d37
leaq 0xceb53(%rip), %rbx     # 0x1424b6
xorl %r12d, %r12d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6fc78
movl %eax, %r13d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6fc78
shlq $0x20, %rax
leaq (%rax,%r13), %rcx
addq %r13, %rax
decq %rax
shrq %rax
shrq %rcx
testb $0x1, %r13b
notq %rax
cmoveq %rcx, %rax
movq 0x20(%rsp), %rcx
cmpq (%rcx,%r12,8), %rax
je 0x739ca
leaq 0xc4c97(%rip), %rdi     # 0x138647
leaq 0xcf334(%rip), %rsi     # 0x142ceb
movq %r15, %rdx
movq %rbx, %rcx
movl $0xc2c, %r8d            # imm = 0xC2C
xorl %eax, %eax
callq 0xc8053
incq %r12
cmpq $0x186a0, %r12          # imm = 0x186A0
jne 0x73966
leaq 0x10(%rsp), %rdi
callq 0xe0b11
movq 0x8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xe0431
movq 0x48(%rsp), %r12
movq $0x1, 0x10(%r12)
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0xc1ffb
movq %rax, %r14
movq %rbx, %rdi
callq 0xc202d
xorl %ebx, %ebx
movq %r14, %rsi
movl %ebx, %ecx
sarq %cl, %rsi
movq %rax, %rdx
sarq %cl, %rdx
incq %rbx
testq %rsi, %rsi
jg 0x73a1f
cmpq $-0x1, %rdx
jl 0x73a1f
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x7046a
movq %r12, %rdi
movabsq $-0x20f7792dc858395f, %rsi # imm = 0xDF0886D237A7C6A1
movq %r14, %rdx
callq 0xe06ab
xorl %r15d, %r15d
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %r13
xorl %ebp, %ebp
xorl %esi, %esi
btq %rbp, %r13
setb %sil
movq %r14, %rdi
callq 0x6fc25
incq %rbp
cmpq %rbp, %rbx
jne 0x73a6e
incq %r15
cmpq $0x186a0, %r15          # imm = 0x186A0
jne 0x73a63
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x714ce
movq %r12, %rdi
movabsq $0x93943e0ef30024c, %rsi # imm = 0x93943E0EF30024C
movq %r15, %rdx
callq 0xe06ab
movq $0x0, 0x10(%r15)
movq %r14, 0x8(%r15)
leaq 0xcf285(%rip), %r12     # 0x142d4e
leaq 0xcf267(%rip), %r13     # 0x142d37
leaq 0xce9df(%rip), %rbp     # 0x1424b6
xorl %r14d, %r14d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x71a04
movq 0x20(%rsp), %rcx
cmpq (%rcx,%r14,8), %rax
je 0x73b0d
leaq 0xc4b50(%rip), %rdi     # 0x138647
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movl $0xc3b, %r8d            # imm = 0xC3B
xorl %eax, %eax
callq 0xc8053
incq %r14
cmpq $0x186a0, %r14          # imm = 0x186A0
jne 0x73ada
leaq 0x48(%rsp), %rdi
callq 0xe0b11
leaq 0x8(%rsp), %rdi
callq 0xe0b11
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq