// File: /workspace/github_c_makefile_star2_O0/johsteffens[P]beth/lib/bcore/bcore_sources.c
// Function: sources_selftest
static st_s* sources_selftest( void )
{
    //sources_selftest_stdin();


    st_s* msg = st_s_create();
    bcore_life_s* l = bcore_life_s_create();

    bcore_flect_define_parse_sc( "chain_test_aware_arr = { aware_t _; st_s [] arr; }" );
    sr_s arr = bcore_life_s_push_sr( l, bcore_inst_t_create_sr( typeof( "chain_test_aware_arr" ) ) );
    arr = sr_cp( arr, TYPEOF_bcore_array_s );
    for( uz_t i = 0; i < 20000; i++ ) bcore_array_x_push( arr, sr_asm( st_s_createf( "line of text %zu", i ) ) );

    // write object to file
    {
        bcore_sink_chain_s* chain = bcore_sink_open_file( "temp/sources_selftest01.txt" );
        bcore_translate_x( bcore_inst_t_create_sr( typeof( "bcore_txt_ml_translator_s" ) ), arr, sr_awm( chain ) );
        bcore_sink_chain_s_discard( chain );
    }

    // create object from file
    {
        bcore_source_chain_s* chain = bcore_life_s_push_aware( l, bcore_source_open_file( "temp/sources_selftest01.txt" ) );
        sr_s chain_clone = sr_awm( bcore_life_s_push_aware( l, bcore_inst_a_clone( (bcore_inst*)chain ) ) );
        sr_s sr = bcore_interpret_x( bcore_inst_t_create_sr( typeof( "bcore_txt_ml_interpreter_s" ) ), chain_clone );
        sr = bcore_life_s_push_sr( l, sr );
        if( bcore_compare_sr( sr, arr ) != 0 ) ERR( "%s", bcore_diff_sr( sr, arr )->sc );
    }

    // random access
    {
        {
            bcore_sink_chain_s* chain = bcore_sink_open_file( "temp/sources_selftest02.txt" );
            for( uz_t i = 0; i < 10000; i++ ) bcore_sink_a_push_string_d( (bcore_sink*)chain, st_s_create_fa( "line of text #<uz_t>\n", i ) );
            bcore_sink_chain_s_discard( chain );
        }

        {
            bcore_source_chain_s* chain = bcore_source_open_file( "temp/sources_selftest02.txt" );
            bcore_arr_uz_s* arr = bcore_arr_uz_s_create();
            for( uz_t i = 0; i < 10000; i++ )
            {
                bcore_arr_uz_s_push( arr, bcore_source_a_get_index( (bcore_source*)chain ) );
                uz_t v = 0;
                bcore_source_a_parse_fa( (bcore_source*)chain, "line of text #<uz_t*>\n", &v );
                ASSERT( i == v );
            }

            u2_t rv = 1234;

            for( uz_t i = 0; i < 10000; i++ )
            {
                rv = bcore_xsg1_u2( rv );
                uz_t idx = rv % arr->size;
                bcore_source_a_set_index( (bcore_source*)chain, arr->data[ idx ] );
                uz_t v = 0;
                bcore_source_a_parse_fa( (bcore_source*)chain, "line of text #<uz_t*>\n", &v );
                ASSERT( idx == v );
            }

            bcore_arr_uz_s_discard( arr );
            bcore_source_chain_s_discard( chain );
        }

        /// parse error management
        {
            bcore_source_chain_s* chain = bcore_source_open_file( "temp/sources_selftest02.txt" );

            for( uz_t i = 0; i < 100; i++ ) // read firs 100 lines correctly
            {
                uz_t v = 0;
                bcore_source_a_parse_fa( (bcore_source*)chain, "line of text #<uz_t*>\n", &v );
                ASSERT( i == v );
            }

            ASSERT( bcore_error_stack_size() == 0 );
            er_t er = bcore_source_a_parse_em_fa( (bcore_source*)chain, "Nonsense" );
            ASSERT( er == TYPEOF_parse_error );
            ASSERT( bcore_error_stack_size() == 1 );
            bcore_error_pop_to_sink( BCORE_SINK_NUL /*BCORE_STDOUT*/ );
            bcore_source_chain_s_discard( chain );
        }

    }

    bcore_life_s_discard( l );
    return msg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movb $0x0, %al
callq 0xff2e0
movq %rax, -0x8(%rbp)
movb $0x0, %al
callq 0xbfdd0
movq %rax, -0x10(%rbp)
leaq 0x83b1b(%rip), %rdi     # 0x1526d3
callq 0xa7750
movq -0x10(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq 0x83b37(%rip), %rdi     # 0x152706
callq 0xcce50
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0xcac30
movq -0x190(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xc02c0
leaq -0x58(%rbp), %rdi
leaq -0x28(%rbp), %rax
movabsq $-0x5073d588c3beb52e, %rsi # imm = 0xAF8C2A773C414AD2
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xd0c30
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x4e20, -0x60(%rbp)    # imm = 0x4E20
jae 0xcecd3
movq -0x60(%rbp), %rsi
leaq 0x83aa9(%rip), %rdi     # 0x15271b
movb $0x0, %al
callq 0xff350
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0xcb2d0
leaq -0x28(%rbp), %rcx
leaq -0x78(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0xd0c90
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xcec5d
leaq 0x83a52(%rip), %rdi     # 0x15272c
callq 0xc9550
movq %rax, -0x80(%rbp)
leaq 0x827ed(%rip), %rdi     # 0x1514d7
callq 0xcce50
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0xcac30
movq -0x80(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xd0d40
leaq -0x98(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0xb0(%rbp), %rax
movq (%rdx), %rsi
movq %rsi, (%rsp)
movq 0x8(%rdx), %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rdx), %rdx
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x20(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
callq 0xf5680
movq -0x80(%rbp), %rdi
callq 0xc8850
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq 0x8399f(%rip), %rdi     # 0x15272c
callq 0xce080
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0xc0460
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xcf5a0
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0xc0460
movq %rax, %rsi
leaq -0xd0(%rbp), %rdi
callq 0xd0d40
leaq 0x8270d(%rip), %rdi     # 0x1514f1
callq 0xcce50
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0xcac30
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rcx
leaq -0xd0(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0xef320
movq -0x10(%rbp), %rsi
leaq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xc02c0
movq -0x118(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xe8(%rbp), %rcx
leaq -0x28(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0xdf9d0
cmpl $0x0, %eax
je 0xcef4f
leaq -0xe8(%rbp), %rcx
leaq -0x28(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0xe0d20
movq 0x8(%rax), %r8
leaq 0x83813(%rip), %rdi     # 0x152748
leaq 0x82e7f(%rip), %rsi     # 0x151dbb
movl $0x6c8, %edx            # imm = 0x6C8
leaq 0x726c3(%rip), %rcx     # 0x14160b
movb $0x0, %al
callq 0x9cf40
leaq 0x83803(%rip), %rdi     # 0x152759
callq 0xc9550
movq %rax, -0x120(%rbp)
movq $0x0, -0x128(%rbp)
cmpq $0x2710, -0x128(%rbp) # imm = 0x2710
jae 0xcefc0
movq -0x120(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x128(%rbp), %rsi
leaq 0x837df(%rip), %rdi     # 0x152775
movb $0x0, %al
callq 0xff430
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0xd0db0
movq -0x128(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
jmp 0xcef6d
movq -0x120(%rbp), %rdi
callq 0xc8850
leaq 0x83786(%rip), %rdi     # 0x152759
callq 0xce080
movq %rax, -0x130(%rbp)
movb $0x0, %al
callq 0x8d8a0
movq %rax, -0x138(%rbp)
movq $0x0, -0x140(%rbp)
cmpq $0x2710, -0x140(%rbp) # imm = 0x2710
jae 0xcf0ab
movq -0x138(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x130(%rbp), %rdi
callq 0xcb660
movq -0x1b0(%rbp), %rdi
movq %rax, %rsi
callq 0x8dc30
movq $0x0, -0x148(%rbp)
movq -0x130(%rbp), %rdi
leaq 0x83740(%rip), %rsi     # 0x15278b
leaq -0x148(%rbp), %rdx
movb $0x0, %al
callq 0xf3450
movq -0x140(%rbp), %rax
cmpq -0x148(%rbp), %rax
je 0xcf092
leaq 0x6492f(%rip), %rdi     # 0x13399f
leaq 0x8372b(%rip), %rsi     # 0x1527a2
leaq 0x836ca(%rip), %rdx     # 0x152748
leaq 0x82d36(%rip), %rcx     # 0x151dbb
movl $0x6db, %r8d            # imm = 0x6DB
movb $0x0, %al
callq 0x9cea0
jmp 0xcf094
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x140(%rbp)
jmp 0xceff8
movl $0x4d2, -0x14c(%rbp)    # imm = 0x4D2
movq $0x0, -0x158(%rbp)
cmpq $0x2710, -0x158(%rbp) # imm = 0x2710
jae 0xcf197
movl -0x14c(%rbp), %edi
callq 0xd0df0
movl %eax, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
movq -0x138(%rbp), %rcx
xorl %edx, %edx
divq 0x10(%rcx)
movq %rdx, -0x160(%rbp)
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x160(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0xcb750
movq $0x0, -0x168(%rbp)
movq -0x130(%rbp), %rdi
leaq 0x83654(%rip), %rsi     # 0x15278b
leaq -0x168(%rbp), %rdx
movb $0x0, %al
callq 0xf3450
movq -0x160(%rbp), %rax
cmpq -0x168(%rbp), %rax
je 0xcf17e
leaq 0x64843(%rip), %rdi     # 0x13399f
leaq 0x83646(%rip), %rsi     # 0x1527a9
leaq 0x835de(%rip), %rdx     # 0x152748
leaq 0x82c4a(%rip), %rcx     # 0x151dbb
movl $0x6e7, %r8d            # imm = 0x6E7
movb $0x0, %al
callq 0x9cea0
jmp 0xcf180
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0xcf0c0
movq -0x138(%rbp), %rdi
callq 0x8d8d0
movq -0x130(%rbp), %rdi
callq 0xcb030
leaq 0x835a3(%rip), %rdi     # 0x152759
callq 0xce080
movq %rax, -0x170(%rbp)
movq $0x0, -0x178(%rbp)
cmpq $0x64, -0x178(%rbp)
jae 0xcf24d
movq $0x0, -0x180(%rbp)
movq -0x170(%rbp), %rdi
leaq 0x8359b(%rip), %rsi     # 0x15278b
leaq -0x180(%rbp), %rdx
movb $0x0, %al
callq 0xf3450
movq -0x178(%rbp), %rax
cmpq -0x180(%rbp), %rax
je 0xcf237
leaq 0x6478a(%rip), %rdi     # 0x13399f
leaq 0x83586(%rip), %rsi     # 0x1527a2
leaq 0x83525(%rip), %rdx     # 0x152748
leaq 0x82b91(%rip), %rcx     # 0x151dbb
movl $0x6f6, %r8d            # imm = 0x6F6
movb $0x0, %al
callq 0x9cea0
jmp 0xcf239
movq -0x178(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x178(%rbp)
jmp 0xcf1cd
callq 0x9df10
cmpq $0x0, %rax
je 0xcf281
leaq 0x64740(%rip), %rdi     # 0x13399f
leaq 0x8354c(%rip), %rsi     # 0x1527b2
leaq 0x834db(%rip), %rdx     # 0x152748
leaq 0x82b47(%rip), %rcx     # 0x151dbb
movl $0x6f9, %r8d            # imm = 0x6F9
movb $0x0, %al
callq 0x9cea0
movq -0x170(%rbp), %rdi
leaq 0x83541(%rip), %rsi     # 0x1527d0
movb $0x0, %al
callq 0xf3530
movq %rax, -0x188(%rbp)
movabsq $0x690af8765815ec4d, %rax # imm = 0x690AF8765815EC4D
cmpq %rax, -0x188(%rbp)
je 0xcf2d9
leaq 0x646e8(%rip), %rdi     # 0x13399f
leaq 0x8351b(%rip), %rsi     # 0x1527d9
leaq 0x83483(%rip), %rdx     # 0x152748
leaq 0x82aef(%rip), %rcx     # 0x151dbb
movl $0x6fb, %r8d            # imm = 0x6FB
movb $0x0, %al
callq 0x9cea0
callq 0x9df10
cmpq $0x1, %rax
je 0xcf30d
leaq 0x646b4(%rip), %rdi     # 0x13399f
leaq 0x83500(%rip), %rsi     # 0x1527f2
leaq 0x8344f(%rip), %rdx     # 0x152748
leaq 0x82abb(%rip), %rcx     # 0x151dbb
movl $0x6fc, %r8d            # imm = 0x6FC
movb $0x0, %al
callq 0x9cea0
leaq 0xe3044(%rip), %rax     # 0x1b2358
movq (%rax), %rdi
callq 0x9e510
movq -0x170(%rbp), %rdi
callq 0xcb030
movq -0x10(%rbp), %rdi
callq 0xbfe00
movq -0x8(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nop