// File: /workspace/github_c_makefile_star2_O2/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 0x77361
movq %rbx, %rdi
callq 0x77159
movq 0x10(%rbx), %rdi
callq 0xd0a0
movq %rax, 0x18(%rsp)
movq %rbx, %r14
movq 0x10(%rbx), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xd100
testq %r15, %r15
movl $0x0, %ebx
movq %r15, (%rsp)
cmovgq %r15, %rbx
pushq $0x1
popq %r15
xorl %r12d, %r12d
movq %r15, %r13
cmpq %r12, %rbx
je 0x773f0
movq 0x10(%r14), %rdi
callq 0xd290
cmpl $-0x1, %eax
je 0x773c8
incq %r12
incq %r13
xorl %ecx, %ecx
cmpl $0xa, %eax
cmoveq %r12, %rbp
sete %cl
pushq $0x1
popq %rax
cmoveq %rax, %r13
addq %rcx, %r15
jmp 0x77397
leaq 0x4e6a6(%rip), %rdi     # 0xc5a75
leaq 0x4e58f(%rip), %rsi     # 0xc5965
leaq 0x4e6c1(%rip), %rcx     # 0xc5a9e
movl $0x4b8, %edx            # imm = 0x4B8
movq (%rsp), %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x5feef
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x773fd
movq %r15, (%rax)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x7740a
movq %r13, (%rax)
movq 0x20(%rsp), %r15
testq %r15, %r15
je 0x77493
movq 0x10(%r14), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0xd100
movl $0x80, %ebx
subq $0x1, %rbx
jb 0x77458
movq 0x10(%r14), %rdi
callq 0xd290
movl %eax, %ecx
shll $0x18, %ecx
cmpl $0xa000000, %ecx        # imm = 0xA000000
je 0x77458
cmpl $0x1000000, %ecx        # imm = 0x1000000
jl 0x77458
movsbl %al, %esi
movq %r15, %rdi
callq 0x8f0ee
jmp 0x77427
pushq $0xa
popq %rsi
movq %r15, %rdi
callq 0x8f0ee
pushq $0x1
popq %rbx
pushq $0x20
popq %rbp
cmpq %r13, %rbx
jae 0x7747d
movq %r15, %rdi
movl %ebp, %esi
callq 0x8f0ee
incq %rbx
jmp 0x77469
pushq $0x5e
popq %rsi
movq %r15, %rdi
callq 0x8f0ee
pushq $0xa
popq %rsi
movq %r15, %rdi
callq 0x8f0ee
movq 0x10(%r14), %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