// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
testq %r8, %r8
je 0x11173
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x11173
movq 0x8(%rax), %rax
testq %rax, %rax
jle 0x11173
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r15
movq %rax, %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rdx), %rax
movq 0x28(%rdx), %rcx
subq 0x10(%rdx), %rax
addq %rcx, %rax
decq %rsi
cmpq %rsi, %rcx
movq %rsi, %r12
cmovlq %rcx, %r12
xorl %edi, %edi
testq %rcx, %rcx
cmovsq %rdi, %r12
cmpq %rsi, %rax
cmovlq %rax, %rsi
testq %rax, %rax
movl $0x0, %eax
movq %rax, 0x10(%rsp)
cmovsq %rdi, %rsi
movq %rsi, 0x18(%rsp)
movq 0x10(%r8), %rdi
testq %rdi, %rdi
je 0x10f63
callq 0xd210
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %rax
testq %rax, %rax
jle 0x10f9a
movq (%rbx), %rcx
addq $0x10, %rcx
movq $0x0, (%rsp)
xorl %edx, %edx
cmpb $0x1, (%rcx)
jne 0x10f8c
cmpq 0x18(%rbx), %rdx
je 0x10fa2
incq (%rsp)
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0x10f7d
jmp 0x10fa2
movq $0x0, (%rsp)
cmpq 0x18(%rsp), %r12
jg 0x11173
movq %r15, 0x20(%rsp)
movq %rbx, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
movq %rdi, 0x28(%rsp)
movl $0x3a, %esi
callq 0xd230
movq %rax, 0x38(%rsp)
cmpq %r12, (%rsp)
movq %r12, 0x30(%rsp)
jne 0x1101f
movq %r15, %rdi
callq 0x1fb9f
movq %r13, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f940
movl %eax, %ebp
movq %r15, %rdi
callq 0x1fbb1
movq %r13, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f94c
movq %r15, %rdi
movl %ebp, %esi
movl %eax, %edx
jmp 0x1102c
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1f959
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x1115a
cmpb $0x0, (%rax)
je 0x1115a
movq 0x10(%rbx), %rsi
movq 0x28(%rsp), %rdi
callq 0xd6f0
testq %rax, %rax
je 0x1115a
movq %rax, %rbp
cmpq $0x0, 0x38(%rsp)
je 0x11079
cmpq 0x38(%rsp), %rbp
jae 0x1115a
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x10101
movq %rax, %r12
leaq -0x1(%rax), %rbx
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x1fb9f
movq %r13, %rdi
movl $0x13, %esi
movl %eax, %edx
callq 0x1f940
movl %eax, %r14d
movq %r15, %rdi
callq 0x1fbb1
movq %r13, %rdi
movl $0x13, %esi
movl %eax, %edx
callq 0x1f94c
movq %r15, %rdi
movl %r14d, %esi
movl %eax, %edx
movq %rbx, %rcx
movq 0x30(%rsp), %r14
movq %r14, %r8
callq 0x1f959
movq 0x10(%rsp), %rax
addq %rax, %r12
decq %r12
cmpq %r14, (%rsp)
jne 0x11120
movq %r13, %rdi
movl $0x12, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f940
movl %eax, %ebx
movq %r15, %rdi
callq 0x1fbb1
movq %r13, %rdi
movl $0x12, %esi
movl %eax, %edx
callq 0x1f94c
movq %r15, %rdi
movl %ebx, %esi
movl %eax, %edx
jmp 0x1112d
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rcx
movq %r14, %r8
callq 0x1f959
addq 0x10(%rsp), %rbp
movq 0x40(%rsp), %rbx
movq 0x10(%rbx), %rsi
movq %rbp, %rdi
callq 0xd6f0
movq %rax, %rbp
testq %rax, %rax
jne 0x11066
movq 0x30(%rsp), %rcx
leaq 0x1(%rcx), %r12
cmpq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r15
jne 0x10fb7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq