// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce_syntax.c
// Function: ce_syntax_highlight_python
void ce_syntax_highlight_python(CeView_t* view, CeRangeList_t* highlight_range_list, CeDrawColorList_t* draw_color_list,
                                CeSyntaxDef_t* syntax_defs, void* user_data){
     if(!view->buffer) return;
     if(view->buffer->line_count <= 0) return;
     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;
     bool in_visual = false;
     PythonDocstring_t docstring = PYTHON_DOCSTRING_NONE;
     CeRangeNode_t* range_node = highlight_range_list->head;

     check_visual_start(range_node, min, draw_color_list, syntax_defs, &in_visual);

     int prepass_min = min - SEARCH_BACK_LINES;
     if(prepass_min < 0) prepass_min = 0;

     // pre-pass to check if we are in a multiline comment
     for(int64_t y = prepass_min; y < min; y++){
          char* line = view->buffer->lines[y];
          int64_t line_len = ce_utf8_strlen(line);

          for(int64_t x = 0; x < line_len; ++x){
               char* str = ce_utf8_iterate_to(line, x);

               switch(docstring){
               default:
                    if((match_len = match_python_docstring(str, &docstring))){
                         x += match_len;
                    }
                    break;
               case PYTHON_DOCSTRING_DOUBLE_QUOTE:
                    if(strncmp(str, "\"\"\"", 3) == 0){
                         docstring = PYTHON_DOCSTRING_NONE;
                         x += 3;
                    }else if(match_len == 0){
                         docstring = PYTHON_DOCSTRING_NONE;
                    }
                    break;
               case PYTHON_DOCSTRING_SINGLE_QUOTE:
                    if(strncmp(str, "'''", 3) == 0){
                         docstring = PYTHON_DOCSTRING_NONE;
                         x += 3;
                    }else if(match_len == 0){
                         docstring = PYTHON_DOCSTRING_NONE;
                    }
                    break;
               }
          }
     }

     for(int64_t y = min; y <= max; ++y){
          char* line = view->buffer->lines[y];
          int64_t line_len = ce_utf8_strlen(line);
          int64_t current_match_len = 1;
          CePoint_t match_point = {0, y};

          if(docstring){
               change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_STRING, match_point);
          }

          ce_syntax_highlight_visual(&range_node, &in_visual, match_point, draw_color_list, syntax_defs);

          if(in_visual && line_len == 0) change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_VISUAL, match_point);

          for(int64_t x = 0; x < line_len; ++x){
               char* str = ce_utf8_iterate_to(line, x);
               match_point.x = x;

               ce_syntax_highlight_visual(&range_node, &in_visual, match_point, draw_color_list, syntax_defs);

               if(current_match_len <= 1){
                    if(docstring){
                         if(docstring == PYTHON_DOCSTRING_DOUBLE_QUOTE && strncmp(str, "\"\"\"", 3) == 0){
                              docstring = PYTHON_DOCSTRING_NONE;
                              match_len = 3;
                         }else if(docstring == PYTHON_DOCSTRING_SINGLE_QUOTE && strncmp(str, "'''", 3) == 0){
                              docstring = PYTHON_DOCSTRING_NONE;
                              match_len = 3;
                         }
                    }else{
                         if((match_len = match_c_type(str, line, false))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_TYPE, match_point);
                         }else if((match_len = match_python_keyword(str, line))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_KEYWORD, match_point);
                         }else if((match_len = match_python_control(str, line))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_CONTROL, match_point);
                         }else if((match_len = match_caps_var(str, line))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_CAPS_VAR, match_point);
                         }else if((match_len = match_python_comment(str))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_COMMENT, match_point);
                         }else if((match_len = match_python_docstring(str, &docstring))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_STRING, match_point);
                         }else if((match_len = match_python_string(str))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_STRING, match_point);
                         }else if((match_len = match_c_literal(str, line))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_NUMBER_LITERAL, match_point);
                         }else if(((view->cursor.y != y) || (x > view->cursor.x)) && (match_len = match_trailing_whitespace(str))){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_TRAILING_WHITESPACE, match_point);
                              ce_draw_color_list_insert(draw_color_list, ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_NORMAL, CE_COLOR_DEFAULT),
                                                        ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_NORMAL, CE_COLOR_DEFAULT),
                                                        (CePoint_t){0, match_point.y + 1});
                         }else if(!draw_color_list->tail || (draw_color_list->tail->fg != CE_COLOR_DEFAULT || draw_color_list->tail->bg != CE_COLOR_DEFAULT)){
                              change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_NORMAL, match_point);
                         }
                    }

                    if(match_len) current_match_len = match_len;
               }else{
                    current_match_len--;
               }

               if(in_visual) change_draw_color(draw_color_list, syntax_defs, CE_SYNTAX_COLOR_VISUAL, match_point);
          }

          check_visual_mode_end(range_node, &in_visual, match_point.y, line_len, draw_color_list);
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, 0x28(%rsp)
movq 0x40(%rdi), %rax
testq %rax, %rax
je 0x2184c
movq 0x8(%rax), %r9
testq %r9, %r9
jle 0x2184c
movq 0x28(%rsp), %r8
movq 0x18(%r8), %rax
movq 0x28(%r8), %rdi
subq 0x10(%r8), %rax
addq %rdi, %rax
decq %r9
cmpq %r9, %rdi
movq %r9, %r15
cmovlq %rdi, %r15
xorl %r12d, %r12d
testq %rdi, %rdi
cmovsq %r12, %r15
cmpq %r9, %rax
cmovlq %rax, %r9
testq %rax, %rax
cmovsq %r12, %r9
movq %r9, 0x30(%rsp)
leaq 0x3(%rsp), %r8
movb $0x0, (%r8)
movl %r12d, 0x4(%rsp)
movq (%rsi), %rdi
movq %rdi, 0x38(%rsp)
movq %r15, %rsi
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
callq 0x1fbd2
leal -0x400(%r15), %eax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
cmpq %r13, %r15
jle 0x21477
xorl %r12d, %r12d
leaq 0x4(%rsp), %rbx
movq %r15, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %r14
movq %r14, %rdi
callq 0xe445
testq %rax, %rax
jle 0x21466
movq %rax, %r15
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbp, %rsi
callq 0xe577
movl 0x4(%rsp), %ecx
cmpl $0x1, %ecx
je 0x2141c
cmpl $0x2, %ecx
jne 0x2144d
cmpb $0x22, (%rax)
jne 0x2143b
cmpb $0x22, 0x1(%rax)
jne 0x2143b
cmpb $0x22, 0x2(%rax)
je 0x2142d
jmp 0x2143b
cmpb $0x27, (%rax)
jne 0x2143b
cmpb $0x27, 0x1(%rax)
jne 0x2143b
cmpb $0x27, 0x2(%rax)
jne 0x2143b
movl $0x0, 0x4(%rsp)
addq $0x3, %rbp
jmp 0x2145e
testq %r12, %r12
jne 0x2145e
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
jmp 0x2145e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2185b
movq %rax, %r12
addq %rax, %rbp
incq %rbp
cmpq %r15, %rbp
jl 0x213f0
incq %r13
movq 0x20(%rsp), %r15
cmpq %r15, %r13
jne 0x213ce
movq 0x30(%rsp), %r13
cmpq %r13, %r15
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
jg 0x2184c
incq %r13
movq %r13, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rdi
movq %rdi, 0x8(%rsp)
callq 0xe445
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x214d2
movq %r14, %rdi
movq %rbx, %rsi
movl $0x6, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x203f4
leaq 0x38(%rsp), %rdi
leaq 0x3(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rbp
movq %r15, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x1fc6a
cmpb $0x1, 0x3(%rsp)
jne 0x2151b
cmpq $0x0, 0x20(%rsp)
jne 0x2151b
movq %r14, %rdi
movq %rbx, %rsi
movl $0xc, %edx
xorl %ecx, %ecx
movq %rbp, %r15
movq %rbp, %r8
callq 0x203f4
jmp 0x21809
cmpq $0x0, 0x20(%rsp)
movq %rbp, %r15
jle 0x21809
leaq 0x1(%r15), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %r13d
xorl %ebx, %ebx
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe577
movq %rax, %r14
leaq 0x38(%rsp), %rdi
leaq 0x3(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0x1fc6a
cmpq $0x1, %r13
jg 0x2159f
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x2160e
cmpl $0x1, %eax
je 0x215a4
cmpl $0x2, %eax
jne 0x215ce
cmpb $0x22, (%r14)
jne 0x215ce
cmpb $0x22, 0x1(%r14)
jne 0x215ce
cmpb $0x22, 0x2(%r14)
je 0x215b8
jmp 0x215ce
decq %r13
jmp 0x215d5
cmpb $0x27, (%r14)
jne 0x215ce
cmpb $0x27, 0x1(%r14)
jne 0x215ce
cmpb $0x27, 0x2(%r14)
jne 0x215ce
movl $0x0, 0x4(%rsp)
movl $0x3, %r13d
movl $0x3, %r12d
jmp 0x215d5
testq %r12, %r12
cmovneq %r12, %r13
movq 0x8(%rsp), %r15
cmpb $0x1, 0x3(%rsp)
jne 0x215fb
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0xc, %edx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x203f4
incq %rbx
cmpq %rbx, 0x20(%rsp)
jne 0x21540
jmp 0x21812
movq %r14, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0x20474
testq %rax, %rax
je 0x21639
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
jmp 0x21697
movl $0x18, %ecx
movq %r14, %rdi
movq %r15, %rsi
leaq 0x192f5(%rip), %rdx     # 0x3a940
callq 0x224e2
testq %rax, %rax
je 0x21669
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x2, %edx
jmp 0x21697
movl $0x8, %ecx
movq %r14, %rdi
movq %r15, %rsi
leaq 0x19385(%rip), %rdx     # 0x3aa00
callq 0x224e2
testq %rax, %rax
je 0x216aa
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x3, %edx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x203f4
movq %r12, %r13
jmp 0x215da
movq %r14, %rdi
movq %r15, %rsi
callq 0x20508
testq %rax, %rax
je 0x216ce
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x4, %edx
jmp 0x21726
cmpb $0x23, (%r14)
jne 0x216f5
movq %r14, %rdi
callq 0xe445
testq %rax, %rax
je 0x216f5
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x5, %edx
jmp 0x21726
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
callq 0x2185b
testq %rax, %rax
jne 0x21714
movq %r14, %rdi
callq 0x218c3
testq %rax, %rax
je 0x21739
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x6, %edx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x203f4
movq %r12, %r13
jmp 0x215d5
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x20643
testq %rax, %rax
je 0x2175f
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x8, %edx
jmp 0x21726
movq 0x28(%rsp), %rax
cmpq %rbp, 0x38(%rax)
jne 0x21775
movq 0x28(%rsp), %rax
cmpq 0x30(%rax), %rbx
jle 0x217d1
movq %r14, %rdi
callq 0x20433
testq %rax, %rax
je 0x217d1
movq %rax, %r12
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movl $0xb, %edx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x203f4
movl (%r14), %esi
cmpl $-0x2, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %eax, %esi
movl 0x4(%r14), %edx
cmpl $-0x2, %edx
cmovel %eax, %edx
movq %r13, %rdi
xorl %ecx, %ecx
movq 0x40(%rsp), %r8
callq 0x1f8e9
jmp 0x21731
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x217ea
cmpl $-0x1, (%rax)
jne 0x217ea
cmpl $-0x1, 0x4(%rax)
je 0x21801
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x203f4
xorl %r12d, %r12d
jmp 0x215d5
leaq 0x1(%r15), %rbp
movq %r15, %rdx
jmp 0x21829
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %r13
movq %rbp, %rdx
movq 0x40(%rsp), %rbp
movq 0x38(%rsp), %rdi
leaq 0x3(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq %r14, %r8
callq 0x1fdad
movq %rbp, %r15
cmpq %r13, %rbp
jne 0x21497
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq