// File: /workspace/github_cpp_makefile_star2_O3/cphinton42[P]hinton-language/src/parse.cpp
// Function: report_error(Parsing_Context*, Token*, Token*, char const*)
void report_error(Parsing_Context *ctx, Token *start_section, Token *current,const byte *error_text)
{
    byte *start_highlight = start_section->contents.data;
    byte *start = start_highlight;
    byte *start_program = ctx->program_text.data;
    while(start > start_program)
    {
        if(*start == '\n' || *start == '\r')
        {
            ++start;
            break;
        }
        else
        {
            --start;
        }
    }
    
    bool error_at_eof = (current == &ctx->tokens[ctx->tokens.count - 1]);
    byte *end_program = ctx->program_text.data + ctx->program_text.count;
    
    byte *start_error;
    byte *end_highlight;
    byte *end;
    
    if(error_at_eof)
    {
        start_error = end_program;
        end_highlight = end_program;
        end = end_program;
    }
    else
    {
        start_error = current->contents.data;
        end_highlight = start_error + current->contents.count;
        end = end_highlight;
        
        while(end < end_program)
        {
            if(*end == '\r')
            {
                ++end;
                if(end < end_program && *end == '\n')
                {
                    ++end;
                }
                break;
            }
            else if(*end == '\n')
            {
                ++end;
                break;
            }
            else
            {
                ++end;
            }
        }
    }
    
    print_err("\x1B[1;31mError\x1B[0m: %d:%d:\n    %s\n", current->line_number, current->line_offset, error_text);
    
    print_err_indented(start, start_highlight);
    
    print_err("\x1B[1;33m");
    print_err_indented(start_highlight, start_error, false);
    
    if(error_at_eof)
    {
        print_err("\x1B[1;31mEOF\x1B[0m\n");
    }
    else
    {
        print_err("\x1B[1;31m");
        print_err_indented(start_error, end_highlight, false);
        
        print_err("\x1B[0m");
        print_err_indented(end_highlight, end, false);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq 0x18(%rsi), %r15
movq 0x8(%rdi), %rbx
movq %r15, %r12
cmpq %rbx, %r15
jbe 0x9248
movq %r15, %r12
movzbl (%r12), %eax
cmpl $0xd, %eax
je 0x9245
cmpl $0xa, %eax
je 0x9245
decq %r12
cmpq %rbx, %r12
ja 0x9229
movq %rbx, %r12
jmp 0x9248
incq %r12
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rdx
shlq $0x5, %rax
leaq (%rdx,%rax), %r13
addq $-0x20, %r13
addq (%rdi), %rbx
cmpq %r14, %r13
je 0x929c
movq 0x10(%r14), %rax
movq 0x18(%r14), %rbp
leaq (%rax,%rbp), %rsi
cmpq %rbx, %rsi
movq %rsi, (%rsp)
jae 0x92a5
leaq (%rax,%rbp), %rdx
incq %rdx
movq %rdx, %rax
movzbl -0x1(%rdx), %edx
cmpl $0xa, %edx
je 0x92bc
cmpl $0xd, %edx
je 0x92aa
leaq 0x1(%rax), %rdx
cmpq %rbx, %rax
jb 0x9280
jmp 0x92bc
movq %rbx, %rbp
movq %rbx, (%rsp)
jmp 0x92bf
movq %rsi, %rbx
jmp 0x92bf
cmpq %rbx, %rax
jae 0x92bc
leaq 0x1(%rax), %rbx
cmpb $0xa, (%rax)
cmovneq %rax, %rbx
jmp 0x92bf
movq %rax, %rbx
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
leaq 0x7f84(%rip), %rdi      # 0x11252
xorl %eax, %eax
callq 0x416b
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x7305
leaq 0x7f87(%rip), %rdi      # 0x11273
xorl %eax, %eax
callq 0x416b
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x7305
cmpq %r14, %r13
je 0x934d
leaq 0x7f7f(%rip), %rdi      # 0x1128b
xorl %eax, %eax
callq 0x416b
movq %rbp, %rdi
movq (%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x7305
leaq 0x88c8(%rip), %rdi      # 0x11bf3
xorl %eax, %eax
callq 0x416b
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7305
leaq 0x7f27(%rip), %rdi      # 0x1127b
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x416b