// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore_sources.c
// Function: bcore_source_file_s_get_line_col_context
void bcore_source_file_s_get_line_col_context( bcore_source_file_s* o, s3_t index, uz_t* p_line, uz_t* p_col, st_s* context )
{
    if( !o->handle ) bcore_source_file_s_open( o );
    s3_t cur_index = ftell( o->handle );
    fseek( o->handle, 0, SEEK_SET );

    uz_t line = 1;
    uz_t col = 1;
    uz_t line_start = 0;

    for( s3_t i = 0; i < index; i++ )
    {
        int c = fgetc( o->handle );

        if( c == EOF )
        {
            WRN_fa( "Index: '#<s3_t>': End of file reached at position '#<s3_t>'.\n", index, i );
            break;
        }

        if( c == '\n' )
        {
            line++;
            col = 1;
            line_start = i + 1;
        }
        else
        {
            col++;
        }
    }

    if( p_line ) *p_line = line;
    if( p_col  ) *p_col  = col;

    if( context )
    {
        fseek( o->handle, line_start, SEEK_SET );
        for( uz_t i = 0; i < 128; i++ )
        {
            char c = fgetc( o->handle );
            if( c == '\n' || c <= 0) break;
            st_s_push_char( context, c );
        }
        st_s_push_char( context, '\n' );
        for( uz_t i = 1; i < col; i++ ) st_s_push_char( context, ' ' );
        st_s_push_char( context, '^' );
        st_s_push_char( context, '\n' );
    }

    fseek( o->handle, cur_index, SEEK_SET );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
jne 0xe52fb
movq %rbx, %rdi
callq 0xe5166
movq 0x10(%rbx), %rdi
callq 0xd0a0
movq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xd100
testq %r15, %r15
jle 0xe535d
xorl %r12d, %r12d
movl $0x1, %r14d
movl $0x1, %r13d
xorl %ebp, %ebp
movq 0x10(%rbx), %rdi
callq 0xd290
cmpl $-0x1, %eax
je 0xe536b
incq %r12
incq %r13
xorl %ecx, %ecx
cmpl $0xa, %eax
sete %cl
cmoveq %r12, %rbp
movl $0x1, %eax
cmoveq %rax, %r13
addq %rcx, %r14
cmpq %r12, %r15
jne 0xe532a
jmp 0xe5392
movl $0x1, %r13d
movl $0x1, %r14d
jmp 0xe5392
leaq 0x62884(%rip), %rdi     # 0x147bf6
leaq 0x6276d(%rip), %rsi     # 0x147ae6
leaq 0x6289f(%rip), %rcx     # 0x147c1f
movl $0x4b8, %edx            # imm = 0x4B8
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0xd6be
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0xe539f
movq %r14, (%rax)
movq 0x10(%rsp), %rax
testq %rax, %rax
movq 0x20(%rsp), %r15
je 0xe53b1
movq %r13, (%rax)
testq %r15, %r15
je 0xe543e
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0xd100
movl $0x80, %r14d
movq 0x10(%rbx), %rdi
callq 0xd290
movl %eax, %ecx
shll $0x18, %ecx
cmpl $0xa000000, %ecx        # imm = 0xA000000
je 0xe53fc
cmpl $0x1000000, %ecx        # imm = 0x1000000
jl 0xe53fc
movsbl %al, %esi
movq %r15, %rdi
callq 0x10a448
decq %r14
jne 0xe53ce
movq %r15, %rdi
movl $0xa, %esi
callq 0x10a448
cmpq $0x2, %r13
jb 0xe5424
decq %r13
movq %r15, %rdi
movl $0x20, %esi
callq 0x10a448
decq %r13
jne 0xe5412
movq %r15, %rdi
movl $0x5e, %esi
callq 0x10a448
movq %r15, %rdi
movl $0xa, %esi
callq 0x10a448
movq 0x10(%rbx), %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd100