// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r13
cmpq $0x0, 0x10(%rdi)
jne 0xef4af
movq %r13, %rdi
callq 0xef326
movq %rbx, 0x20(%rsp)
movq 0x10(%r13), %rdi
callq 0xd0a0
movq %rax, 0x18(%rsp)
movq 0x10(%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd100
testq %r15, %r15
jle 0xef56a
movl $0x1, %ebx
movl $0x1, %r14d
movl $0x1, %r12d
movq $0x0, (%rsp)
movq %r13, %rbp
movq 0x10(%r13), %rdi
callq 0xd290
movl %eax, %r13d
cmpl $-0x1, %eax
je 0xef52b
incq %r12
xorl %eax, %eax
cmpl $0xa, %r13d
movq (%rsp), %rcx
cmoveq %rbx, %rcx
movq %rcx, (%rsp)
sete %al
movl $0x1, %ecx
cmoveq %rcx, %r12
addq %rax, %r14
jmp 0xef553
leaq -0x1(%rbx), %r9
leaq 0x6369a(%rip), %rdi     # 0x152bd0
leaq 0x63583(%rip), %rsi     # 0x152ac0
movl $0x4b8, %edx            # imm = 0x4B8
leaq 0x636b0(%rip), %rcx     # 0x152bf9
movq %r15, %r8
xorl %eax, %eax
callq 0xd684
cmpl $-0x1, %r13d
je 0xef580
leaq 0x1(%rbx), %rax
cmpq %rbx, %r15
movq %rax, %rbx
movq %rbp, %r13
jne 0xef4f1
jmp 0xef583
movq $0x0, (%rsp)
movl $0x1, %r12d
movl $0x1, %r14d
jmp 0xef583
movq %rbp, %r13
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0xef590
movq %r14, (%rax)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xef59d
movq %r12, (%rax)
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0xef62f
movq 0x10(%r13), %rdi
movq (%rsp), %rsi
xorl %edx, %edx
callq 0xd100
movl $0x80, %ebx
movq 0x10(%r13), %rdi
callq 0xd290
movl %eax, %ecx
shll $0x18, %ecx
cmpl $0xa000000, %ecx        # imm = 0xA000000
je 0xef5ed
cmpl $0x1000000, %ecx        # imm = 0x1000000
jl 0xef5ed
movsbl %al, %esi
movq %r14, %rdi
callq 0x115381
decq %rbx
jne 0xef5bf
movq %r14, %rdi
movl $0xa, %esi
callq 0x115381
cmpq $0x2, %r12
jb 0xef615
decq %r12
movq %r14, %rdi
movl $0x20, %esi
callq 0x115381
decq %r12
jne 0xef603
movq %r14, %rdi
movl $0x5e, %esi
callq 0x115381
movq %r14, %rdi
movl $0xa, %esi
callq 0x115381
movq 0x10(%r13), %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