// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, 0x28(%rsp)
movq 0x40(%rdi), %rax
testq %rax, %rax
je 0x1f8fd
movq 0x8(%rax), %r8
testq %r8, %r8
jle 0x1f8fd
movq 0x28(%rsp), %rdi
movq 0x18(%rdi), %r9
movq 0x28(%rdi), %rax
subq 0x10(%rdi), %r9
addq %rax, %r9
decq %r8
cmpq %r8, %rax
movq %r8, %r12
cmovlq %rax, %r12
xorl %r14d, %r14d
testq %rax, %rax
cmovsq %r14, %r12
cmpq %r8, %r9
movq %r9, 0x20(%rsp)
cmovlq %r9, %r8
movq %r8, 0x38(%rsp)
leaq 0xc(%rsp), %rax
movq %rax, %r13
andl $0x0, (%rax)
leaq 0xb(%rsp), %r8
movb $0x0, (%r8)
movq (%rsi), %rdi
movq %rdi, 0x40(%rsp)
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
callq 0x1dd92
leal -0x400(%r12), %ecx
testl %ecx, %ecx
cmovlel %r14d, %ecx
cmpq %r12, %rcx
jge 0x1f56f
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq %rcx, 0x30(%rsp)
movq (%rax,%rcx,8), %rbx
movq %rbx, %rdi
callq 0xe38c
movq %rax, %rbp
xorl %r15d, %r15d
cmpq %rbp, %r15
jge 0x1f562
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe4a6
movl 0xc(%rsp), %ecx
cmpl $0x1, %ecx
je 0x1f521
cmpl $0x2, %ecx
jne 0x1f54c
cmpb $0x22, (%rax)
jne 0x1f53d
cmpb $0x22, 0x1(%rax)
jne 0x1f53d
cmpb $0x22, 0x2(%rax)
je 0x1f532
jmp 0x1f53d
cmpb $0x27, (%rax)
jne 0x1f53d
cmpb $0x27, 0x1(%rax)
jne 0x1f53d
cmpb $0x27, 0x2(%rax)
jne 0x1f53d
andl $0x0, 0xc(%rsp)
addq $0x3, %r15
jmp 0x1f55d
testq %r14, %r14
jne 0x1f55d
andl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
jmp 0x1f55d
movq %rax, %rdi
movq %r13, %rsi
callq 0x1f90c
movq %rax, %r14
addq %rax, %r15
incq %r15
jmp 0x1f4f0
movq 0x30(%rsp), %rcx
incq %rcx
jmp 0x1f4c4
xorl %ecx, %ecx
cmpq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rax
cmovsq %rcx, %rax
movq 0x10(%rsp), %r15
movq %rax, 0x38(%rsp)
cmpq %rax, %r12
movq 0x18(%rsp), %rbx
jg 0x1f8fd
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rbp
movq %rbp, %rdi
callq 0xe38c
movq %rax, %r13
cmpl $0x0, 0xc(%rsp)
je 0x1f5cd
movq %r15, %rdi
movq %rbx, %rsi
pushq $0x6
popq %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1e564
movq %rbp, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0xb(%rsp), %rsi
xorl %edx, %edx
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x1de28
cmpb $0x1, 0xb(%rsp)
jne 0x1f60b
testq %r13, %r13
jne 0x1f60b
movq %r15, %rdi
movq %rbx, %rsi
pushq $0xc
popq %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1e564
leaq 0x1(%r12), %rax
movq %rax, 0x48(%rsp)
testq %r13, %r13
movq %r13, 0x50(%rsp)
movq %r13, %rbp
movl $0x0, %eax
cmovleq %rax, %rbp
pushq $0x1
popq %r13
xorl %r15d, %r15d
movq %rbp, 0x20(%rsp)
cmpq %r15, %rbp
je 0x1f8cf
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0xe4a6
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
leaq 0xb(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0x1de28
cmpq $0x1, %r13
jg 0x1f698
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x1f6ce
cmpl $0x1, %eax
je 0x1f6a0
cmpl $0x2, %eax
jne 0x1f6c2
cmpb $0x22, (%rbx)
jne 0x1f6c2
cmpb $0x22, 0x1(%rbx)
jne 0x1f6c2
cmpb $0x22, 0x2(%rbx)
je 0x1f6b1
jmp 0x1f6c2
decq %r13
jmp 0x1f77f
cmpb $0x27, (%rbx)
jne 0x1f6c2
cmpb $0x27, 0x1(%rbx)
jne 0x1f6c2
cmpb $0x27, 0x2(%rbx)
jne 0x1f6c2
andl $0x0, 0xc(%rsp)
pushq $0x3
popq %r14
movq %r14, %r13
jmp 0x1f77f
testq %r14, %r14
cmovneq %r14, %r13
jmp 0x1f77f
movq %rbx, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
xorl %edx, %edx
callq 0x1e5d5
testq %rax, %rax
je 0x1f6f6
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x1
jmp 0x1f76b
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x1a23d(%rip), %rdx     # 0x39940
pushq $0x18
popq %rcx
callq 0x204e8
testq %rax, %rax
je 0x1f721
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x2
jmp 0x1f76b
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x1a2d2(%rip), %rdx     # 0x39a00
pushq $0x8
popq %rcx
callq 0x204e8
testq %rax, %rax
je 0x1f74c
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x3
jmp 0x1f76b
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1e66a
testq %rax, %rax
je 0x1f7a6
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x4
popq %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e564
movq %r14, %r13
movq 0x20(%rsp), %rbp
cmpb $0x1, 0xb(%rsp)
jne 0x1f79e
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0xc
popq %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e564
incq %r15
jmp 0x1f635
movq %rbx, %rdi
callq 0x1f974
testq %rax, %rax
movq 0x20(%rsp), %rbp
je 0x1f7c9
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x5
jmp 0x1f7f7
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x1f90c
testq %rax, %rax
jne 0x1f7e8
movq %rbx, %rdi
callq 0x1f980
testq %rax, %rax
je 0x1f808
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x6
popq %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e564
jmp 0x1f6ba
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x1e77f
testq %rax, %rax
je 0x1f82b
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq $0x8
jmp 0x1f7f7
movq 0x28(%rsp), %rax
cmpq %r12, 0x38(%rax)
jne 0x1f841
movq 0x28(%rsp), %rax
cmpq 0x30(%rax), %r15
jle 0x1f897
movq %rbx, %rdi
callq 0x1e5a1
testq %rax, %rax
je 0x1f897
movq %rax, %r14
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
pushq $0xb
popq %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e564
movl (%rbx), %esi
cmpl $-0x2, %esi
pushq $-0x1
popq %rax
cmovel %eax, %esi
movl 0x4(%rbx), %edx
cmpl $-0x2, %edx
cmovel %eax, %edx
movq %r13, %rdi
xorl %ecx, %ecx
movq 0x48(%rsp), %r8
callq 0x1dadd
jmp 0x1f6ba
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1f8b0
cmpl $-0x1, (%rax)
jne 0x1f8b0
cmpl $-0x1, 0x4(%rax)
je 0x1f8c7
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e564
xorl %r14d, %r14d
jmp 0x1f77f
movq 0x40(%rsp), %rdi
leaq 0xb(%rsp), %rsi
movq %r12, %rdx
movq 0x50(%rsp), %rcx
movq 0x10(%rsp), %r15
movq %r15, %r8
callq 0x1df50
movq 0x48(%rsp), %r12
movq 0x38(%rsp), %rax
jmp 0x1f58a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq