// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce_app.c
// Function: ce_syntax_highlight_completions
void ce_syntax_highlight_completions(CeView_t* view, CeRangeList_t* highlight_range_list, CeDrawColorList_t* draw_color_list,
                                     CeSyntaxDef_t* syntax_defs, void* user_data){
     if(!user_data) return;
     if(!view->buffer) return;
     if(view->buffer->line_count <= 0) return;
     CeComplete_t* complete = user_data;
     int64_t min = view->scroll.y;
     int64_t max = min + (view->rect.bottom - view->rect.top);
     int64_t clamp_max = (view->buffer->line_count - 1);
     if(clamp_max < 0) clamp_max = 0;
     CE_CLAMP(min, 0, clamp_max);
     CE_CLAMP(max, 0, clamp_max);
     int64_t match_len = 0;
     if(complete->current_match) match_len = strlen(complete->current_match);

     // figure out which line to highlight
     int64_t selected = 0;
     for(int64_t i = 0; i < complete->count; i++){
          if(complete->elements[i].match){
               if(i == complete->current) break;
               selected++;
          }
     }

     for(int64_t y = min; y <= max; ++y){
          char* line = view->buffer->lines[y];
          char* end_of_match = strchr(line, ':');
          CePoint_t match_point = {0, y};

          if(selected == y){
               int fg = ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_SELECTED, ce_draw_color_list_last_fg_color(draw_color_list));
               int bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_SELECTED, ce_draw_color_list_last_bg_color(draw_color_list));
               ce_draw_color_list_insert(draw_color_list, fg, bg, match_point);
          }else{
               ce_draw_color_list_insert(draw_color_list, CE_COLOR_DEFAULT, CE_COLOR_DEFAULT, match_point);
          }

          if(complete->current_match && strlen(complete->current_match)){
               char* prev_match = line;
               char* match = NULL;
               while((match = strstr(prev_match, complete->current_match))){
                    if(end_of_match && match >= end_of_match) break;
                    match_point.x = ce_utf8_strlen_between(line, match) - 1;
                    prev_match = match + match_len;
                    int fg = ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_MATCH, ce_draw_color_list_last_fg_color(draw_color_list));
                    int bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_MATCH, ce_draw_color_list_last_bg_color(draw_color_list));
                    ce_draw_color_list_insert(draw_color_list, fg, bg, match_point);

                    match_point.x += match_len;

                    if(selected == y){
                         fg = ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_SELECTED, CE_COLOR_DEFAULT);
                         bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_COMPLETE_SELECTED, ce_draw_color_list_last_bg_color(draw_color_list));
                         ce_draw_color_list_insert(draw_color_list, fg, bg, match_point);
                    }else{
                         ce_draw_color_list_insert(draw_color_list, CE_COLOR_DEFAULT, CE_COLOR_DEFAULT, match_point);
                    }
               }
          }
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, (%rsp)
testq %r8, %r8
je 0x10fcd
movq (%rsp), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x10fcd
movq 0x8(%rax), %rax
testq %rax, %rax
jle 0x10fcd
movq %r8, %r14
movq %rcx, %r12
movq %rdx, %r15
movq %rax, %rsi
movq (%rsp), %rdx
movq 0x18(%rdx), %rax
movq 0x28(%rdx), %rcx
subq 0x10(%rdx), %rax
addq %rcx, %rax
decq %rsi
cmpq %rsi, %rcx
movq %rsi, %rbx
cmovlq %rcx, %rbx
xorl %edx, %edx
testq %rcx, %rcx
cmovsq %rdx, %rbx
cmpq %rsi, %rax
cmovlq %rax, %rsi
testq %rax, %rax
movl $0x0, %eax
movq %rax, 0x8(%rsp)
cmovsq %rdx, %rsi
movq %rsi, 0x10(%rsp)
movq 0x10(%r8), %rdi
testq %rdi, %rdi
je 0x10db6
callq 0xd210
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rax
testq %rax, %rax
jle 0x10de7
movq (%r14), %rcx
addq $0x10, %rcx
xorl %r13d, %r13d
xorl %edx, %edx
cmpb $0x1, (%rcx)
jne 0x10dd9
cmpq 0x18(%r14), %rdx
je 0x10dea
incq %r13
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0x10dcb
jmp 0x10dea
xorl %r13d, %r13d
cmpq 0x10(%rsp), %rbx
jg 0x10fcd
movq %r12, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq (%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rdi
movq %rdi, 0x30(%rsp)
movl $0x3a, %esi
callq 0xd230
movq %rax, 0x40(%rsp)
cmpq %rbx, %r13
movq %rbx, 0x38(%rsp)
movq %r15, %rdi
jne 0x10e6f
callq 0x1fb08
movq %r12, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f8d0
movl %eax, %ebx
movq %r15, %rdi
callq 0x1fb1a
movq %r12, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f8dc
movq %r15, %rdi
movl %ebx, %esi
movl %eax, %edx
xorl %ecx, %ecx
movq %r13, %r8
jmp 0x10e7e
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x1f8e9
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x10faf
cmpb $0x0, (%rsi)
je 0x10faf
movq 0x30(%rsp), %rdi
callq 0xd6f0
testq %rax, %rax
je 0x10faf
movq %rax, %r12
cmpq $0x0, 0x40(%rsp)
je 0x10ec2
cmpq 0x40(%rsp), %r12
jae 0x10faf
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xff7f
movq %rax, %rbx
leaq -0x1(%rax), %rbp
movq %r15, %rdi
callq 0x1fb08
movq 0x28(%rsp), %r13
movq %r13, %rdi
movl $0x13, %esi
movl %eax, %edx
callq 0x1f8d0
movl %eax, %r14d
movq %r15, %rdi
callq 0x1fb1a
movq %r13, %rdi
movl $0x13, %esi
movl %eax, %edx
callq 0x1f8dc
movq %r15, %rdi
movl %r14d, %esi
movl %eax, %edx
movq %rbp, %rcx
movq 0x38(%rsp), %r14
movq %r14, %r8
callq 0x1f8e9
movq 0x8(%rsp), %rax
addq %rax, %rbx
decq %rbx
movq 0x20(%rsp), %rbp
cmpq %r14, %rbp
jne 0x10f75
movq %r13, %rdi
movl $0x12, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f8d0
movl %eax, %r14d
movq %r15, %rdi
callq 0x1fb1a
movq %r13, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f8dc
movq %r15, %rdi
movl %r14d, %esi
movl %eax, %edx
movq %rbx, %rcx
movq %rbp, %r8
jmp 0x10f88
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rcx
movq %r14, %r8
callq 0x1f8e9
movq 0x18(%rsp), %r14
addq 0x8(%rsp), %r12
movq 0x10(%r14), %rsi
movq %r12, %rdi
callq 0xd6f0
movq %rax, %r12
testq %rax, %rax
jne 0x10eaf
movq 0x38(%rsp), %rcx
leaq 0x1(%rcx), %rbx
cmpq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
jne 0x10e04
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq