// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xccc40
movq -0x8(%rbp), %rdi
callq 0xcc8f0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x40a0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4100
movq $0x1, -0x38(%rbp)
movq $0x1, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0xccd1a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x4270
movl %eax, -0x54(%rbp)
cmpl $-0x1, -0x54(%rbp)
jne 0xcccd3
movq -0x10(%rbp), %r8
movq -0x50(%rbp), %r9
leaq 0x85214(%rip), %rdi     # 0x151ecb
leaq 0x850fd(%rip), %rsi     # 0x151dbb
movl $0x4b8, %edx            # imm = 0x4B8
leaq 0x8522a(%rip), %rcx     # 0x151ef4
movb $0x0, %al
callq 0x9cda0
jmp 0xccd1a
cmpl $0xa, -0x54(%rbp)
jne 0xcccfb
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xccd07
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xccd09
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xccc84
cmpq $0x0, -0x18(%rbp)
je 0xccd2c
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0xccd3e
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0xcce05
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x4100
movq $0x0, -0x60(%rbp)
cmpq $0x80, -0x60(%rbp)
jae 0xccdad
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x4270
movb %al, -0x61(%rbp)
movsbl -0x61(%rbp), %eax
cmpl $0xa, %eax
je 0xccd90
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
jg 0xccd92
jmp 0xccdad
movq -0x28(%rbp), %rdi
movsbl -0x61(%rbp), %esi
callq 0xffba0
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xccd64
movq -0x28(%rbp), %rdi
movl $0xa, %esi
callq 0xffba0
movq $0x1, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0xccde9
movq -0x28(%rbp), %rdi
movl $0x20, %esi
callq 0xffba0
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xccdc3
movq -0x28(%rbp), %rdi
movl $0x5e, %esi
callq 0xffba0
movq -0x28(%rbp), %rdi
movl $0xa, %esi
callq 0xffba0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x4100
addq $0x70, %rsp
popq %rbp
retq
nop