// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce_draw_term.c
// Function: draw_view
static void _draw_view(CeView_t* view, int64_t tab_width, CeLineNumber_t line_number, CeVisualLineDisplayType_t visual_line_display_type,
                       CeDrawColorList_t* draw_color_list, CeColorDefs_t* color_defs, CeSyntaxDef_t* syntax_defs,
                       int64_t terminal_right, CeRune_t show_line_extends_passed_view_as){
     int64_t view_width = ce_view_width(view);
     int64_t view_height = ce_view_height(view);
     int64_t row_min = view->scroll.y;
     int64_t col_min = view->scroll.x;
     int64_t col_max = col_min + view_width;

     char tab_str[tab_width + 1];
     memset(tab_str, ' ', tab_width);
     tab_str[tab_width] = 0;

     CeDrawColorNode_t* draw_color_node = draw_color_list->head;

     // figure out how wide the line number margin needs to be
     int line_number_size = 0;
     if(!view->buffer->no_line_numbers){
          line_number_size = ce_line_number_column_width(line_number, view->buffer->line_count, view->rect.top, view->rect.bottom);
          if(line_number_size){
               col_max -= line_number_size;
               line_number_size--;
          }
     }

     if(view->buffer->line_count >= 0){
          for(int64_t y = 0; y < view_height; y++){
               int64_t index = 0;
               int64_t x = 0;
               int64_t rune_len = 0;
               int64_t line_index = y + row_min;
               CeRune_t rune = 1;
               int64_t real_y = y + view->scroll.y;

               move(view->rect.top + y, view->rect.left);

               if(!view->buffer->no_line_numbers && line_number){
                    int fg = CE_COLOR_DEFAULT;
                    int bg = CE_COLOR_DEFAULT;
                    if(draw_color_node){
                         fg = draw_color_node->fg;
                         bg = draw_color_node->bg;
                    }
                    fg = ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_LINE_NUMBER, fg);
                    bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_LINE_NUMBER, bg);
                    int change_color_pair = ce_color_def_get(color_defs, fg, bg);
                    attron(COLOR_PAIR(change_color_pair));
                    int value = real_y + 1;
                    if(line_number == CE_LINE_NUMBER_RELATIVE || (line_number == CE_LINE_NUMBER_ABSOLUTE_AND_RELATIVE && view->cursor.y != real_y)){
                         value = abs((int)(view->cursor.y - real_y));
                    }
                    printw("%*d ", line_number_size, value);
               }

               standend();
               if(!view->buffer->no_highlight_current_line && real_y == view->cursor.y){
                    int bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_CURRENT_LINE, CE_COLOR_DEFAULT);
                    int change_color_pair = ce_color_def_get(color_defs, CE_COLOR_DEFAULT, bg);
                    attron(COLOR_PAIR(change_color_pair));
               }else if(draw_color_node && ce_point_after((CePoint_t){index, y + view->scroll.y}, draw_color_node->point)){
                    int change_color_pair = ce_color_def_get(color_defs, draw_color_node->fg, draw_color_node->bg);
                    attron(COLOR_PAIR(change_color_pair));
               }

               if(line_index < view->buffer->line_count){
                    const char* line = view->buffer->lines[y + row_min];

                    while(rune > 0){
                         rune = ce_utf8_decode(line, &rune_len);

                         // check if we need to move to the next color
                         while(draw_color_node && !ce_point_after(draw_color_node->point, (CePoint_t){index, real_y})){
                              int bg = draw_color_node->bg;
                              if(!view->buffer->no_highlight_current_line && bg == CE_COLOR_DEFAULT && real_y == view->cursor.y){
                                   bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_CURRENT_LINE, bg);
                              }

                              int change_color_pair = ce_color_def_get(color_defs, draw_color_node->fg, bg);
                              attron(COLOR_PAIR(change_color_pair));
                              draw_color_node = draw_color_node->next;
                         }

                         const char* look_ahead = line + rune_len;
                         int64_t next_rune_len = 0;
                         CeRune_t next_rune = 1;

                         next_rune = ce_utf8_decode(look_ahead, &next_rune_len);

                         if(x > col_max){
                              x++;
                         }else if(show_line_extends_passed_view_as &&
                                  ((view->rect.right >= terminal_right && x == col_max) ||
                                   (view->rect.right < terminal_right && x == (col_max - 1))) &&
                                  next_rune != 0){
                              int new_bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_LINE_EXTENDS_PASSED_VIEW, CE_COLOR_DEFAULT);
                              int new_fg = ce_syntax_def_get_fg(syntax_defs, CE_SYNTAX_COLOR_LINE_EXTENDS_PASSED_VIEW, CE_COLOR_DEFAULT);
                              int change_color_pair = ce_color_def_get(color_defs, new_fg, new_bg);
                              attron(COLOR_PAIR(change_color_pair));
                              addch(show_line_extends_passed_view_as);
                              standend();
                              x++;
                         }else if(x >= col_min && rune > 0){
                              if(rune == CE_TAB){
                                   x += tab_width;
                                   addstr(tab_str);
                              }else if(rune >= 0x80){
                                   char utf8_string[CE_UTF8_SIZE + 1];
                                   int64_t bytes_written = 0;
                                   ce_utf8_encode(rune, utf8_string, CE_UTF8_SIZE, &bytes_written);
                                   utf8_string[bytes_written] = 0;
                                   addstr(utf8_string);
                                   x++;
                              }else{
                                   addch(rune);
                                   x++;
                              }
                         }else if(rune == CE_TAB){
                              x += tab_width;
                         }else{
                              x++;
                         }

                         line += rune_len;
                         index++;
                    }

                    x--;
               }

               if(x < col_min) x = col_min;
               switch(visual_line_display_type){
               default:
                    break;
               case CE_VISUAL_LINE_DISPLAY_TYPE_FULL_LINE:
                    for(; x <= col_max; x++) addch(' ');
                    break;
               case CE_VISUAL_LINE_DISPLAY_TYPE_INCLUDE_NEWLINE:
                    addch(' ');
                    x++;
               // intentional fall through
               case CE_VISUAL_LINE_DISPLAY_TYPE_EXCLUDE_NEWLINE:
                    standend();
                    if(!view->buffer->no_highlight_current_line && real_y == view->cursor.y){
                         int bg = ce_syntax_def_get_bg(syntax_defs, CE_SYNTAX_COLOR_CURRENT_LINE, CE_COLOR_DEFAULT);
                         int change_color_pair = ce_color_def_get(color_defs, CE_COLOR_DEFAULT, bg);
                         attron(COLOR_PAIR(change_color_pair));
                    }
                    for(; x <= col_max; x++) addch(' ');
                    break;
               }
          }
     }else{
          standend();
     }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, -0x48(%rbp)
movq %r8, %r14
movl %ecx, -0x5c(%rbp)
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
movl 0x20(%rbp), %eax
movl %eax, -0x60(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
callq 0xff6e
movq %rax, %r13
movq %rbx, %rdi
callq 0xff76
movq %rax, -0x98(%rbp)
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xa8(%rbp)
addq %rax, %r13
movq %r13, -0x40(%rbp)
movq %rsp, %r13
leaq 0x10(%r15), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %r13, %rdi
movl $0x20, %esi
movq %r15, %rdx
callq 0xd2a0
movq %r15, -0xa0(%rbp)
movq %r13, -0xd0(%rbp)
movb $0x0, (%r15,%r13)
movq (%r14), %r13
movq 0x40(%rbx), %rax
movl $0x0, -0x54(%rbp)
cmpb $0x0, 0x50(%rax)
movq %rbx, -0x38(%rbp)
jne 0x1b92c
movq 0x8(%rax), %rsi
movq 0x10(%rbx), %rdx
movq 0x18(%rbx), %rcx
movl %r12d, %edi
callq 0x1068a
testl %eax, %eax
je 0x1b92c
movslq %eax, %rcx
subq %rcx, -0x40(%rbp)
decl %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
cmpq $0x0, 0x8(%rax)
js 0x1be9e
cmpq $0x0, -0x98(%rbp)
jle 0x1be8f
movq -0x40(%rbp), %rax
leaq -0x1(%rax), %rcx
movq %rcx, -0xc8(%rbp)
incq %rax
movq %rax, -0x90(%rbp)
movq 0x1e623(%rip), %r15     # 0x39f90
xorl %ecx, %ecx
movl %r12d, -0x58(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, %rax
movq 0x28(%rbx), %r15
addq %rcx, %r15
movq (%rax), %rdi
movl 0x10(%rbx), %esi
movq %rcx, -0x68(%rbp)
addl %ecx, %esi
movl (%rbx), %edx
callq 0xd070
testl %r12d, %r12d
je 0x1ba60
movq 0x40(%rbx), %rax
cmpb $0x0, 0x50(%rax)
jne 0x1ba60
testq %r13, %r13
je 0x1b9c2
movl (%r13), %edx
movl 0x4(%r13), %r14d
jmp 0x1b9cd
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
movl $0x14, %esi
callq 0x1f8d0
movl %eax, %r12d
movq %rbx, %rdi
movl $0x14, %esi
movl %r14d, %edx
callq 0x1f8dc
movq -0x48(%rbp), %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x1fb52
movq 0x1e58a(%rip), %rcx     # 0x39f90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
leal 0x1(%r15), %edx
movl -0x58(%rbp), %r12d
cmpl $0x3, %r12d
je 0x1ba34
cmpl $0x2, %r12d
jne 0x1ba4b
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
jmp 0x1ba41
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
cmpq %r15, %rax
je 0x1ba4b
subl %r15d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
leaq 0x13cb9(%rip), %rdi     # 0x2f70b
movl -0x54(%rbp), %esi
xorl %eax, %eax
callq 0xd4d0
movq -0x38(%rbp), %rbx
movq 0x1e529(%rip), %rax     # 0x39f90
movq (%rax), %rdi
xorl %esi, %esi
callq 0xd730
movq 0x40(%rbx), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1baa5
movq -0x38(%rbp), %rax
cmpq 0x38(%rax), %r15
jne 0x1baa5
movq -0x50(%rbp), %rdi
movl $0xd, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f8dc
movq -0x48(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %eax, %edx
jmp 0x1bad5
testq %r13, %r13
je 0x1baf1
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rsi
addq -0x68(%rbp), %rsi
movq 0x8(%r13), %rdx
movq 0x10(%r13), %rcx
xorl %edi, %edi
callq 0xec71
testb %al, %al
je 0x1baf1
movl (%r13), %esi
movl 0x4(%r13), %edx
movq -0x48(%rbp), %rdi
callq 0x1fb52
movq 0x1e4af(%rip), %rcx     # 0x39f90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq -0xc0(%rbp), %rax
movq -0x68(%rbp), %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movq 0x40(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jge 0x1bd6a
movq (%rcx), %rcx
movq (%rcx,%rax,8), %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %rbx, -0x70(%rbp)
movq %r12, %rdi
leaq -0x78(%rbp), %rsi
callq 0xe602
movl %eax, -0x2c(%rbp)
testq %r13, %r13
je 0x1bbb3
movq %r13, %rbx
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0xec71
testb %al, %al
jne 0x1bbb8
movl 0x4(%rbx), %edx
movq -0x38(%rbp), %rcx
movq 0x40(%rcx), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1bb80
cmpl $-0x1, %edx
jne 0x1bb80
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq 0x38(%rcx), %r15
jne 0x1bb80
movq -0x50(%rbp), %rdi
movl $0xd, %esi
callq 0x1f8dc
movl %eax, %edx
movl (%rbx), %esi
movq -0x48(%rbp), %rdi
callq 0x1fb52
movq 0x1e3fe(%rip), %rcx     # 0x39f90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq 0x18(%rbx), %rbx
movl $0x0, %r13d
testq %rbx, %rbx
jne 0x1bb38
jmp 0x1bbbb
xorl %r13d, %r13d
jmp 0x1bbbb
movq %rbx, %r13
movq -0x78(%rbp), %rdi
addq %r12, %rdi
movq $0x0, -0xd8(%rbp)
leaq -0xd8(%rbp), %rsi
callq 0xe602
movq -0x70(%rbp), %rbx
cmpq -0x40(%rbp), %rbx
jg 0x1bc93
cmpl $0x0, -0x60(%rbp)
je 0x1bcad
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq -0xb0(%rbp), %rcx
jl 0x1bc08
cmpq -0x40(%rbp), %rbx
je 0x1bc22
cmpq -0xb0(%rbp), %rcx
jge 0x1bcad
cmpq -0xc8(%rbp), %rbx
jne 0x1bcad
testl %eax, %eax
je 0x1bcad
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
movl $0x17, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f8dc
movl %eax, -0x7c(%rbp)
movq %rbx, %rdi
movl $0x17, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f8d0
movq -0x48(%rbp), %rdi
movl %eax, %esi
movl -0x7c(%rbp), %edx
callq 0x1fb52
movq 0x1e326(%rip), %rbx     # 0x39f90
movq (%rbx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq (%rbx), %rdi
movl -0x60(%rbp), %esi
callq 0xd620
movq (%rbx), %rdi
movq -0x70(%rbp), %rbx
xorl %esi, %esi
callq 0xd730
incq %rbx
movl -0x2c(%rbp), %esi
addq -0x78(%rbp), %r12
incq %r14
testl %esi, %esi
jg 0x1bb1d
jmp 0x1bd71
cmpq -0xa8(%rbp), %rbx
movl -0x2c(%rbp), %esi
jl 0x1bce6
testl %esi, %esi
jle 0x1bce6
cmpl $0x9, %esi
jne 0x1bcf4
addq -0xa0(%rbp), %rbx
movq 0x1e2c0(%rip), %rax     # 0x39f90
movq (%rax), %rdi
movq -0xd0(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd1a0
jmp 0x1bc96
cmpl $0x9, %esi
jne 0x1bd62
addq -0xa0(%rbp), %rbx
jmp 0x1bc99
cmpl $0x80, %esi
jb 0x1bd50
movq $0x0, -0xb8(%rbp)
movl $0x4, %edx
movl %esi, %edi
leaq -0x81(%rbp), %rbx
movq %rbx, %rsi
leaq -0xb8(%rbp), %rcx
callq 0xf0ff
movq -0xb8(%rbp), %rax
movb $0x0, -0x81(%rbp,%rax)
movq 0x1e256(%rip), %rax     # 0x39f90
movq (%rax), %rdi
movq %rbx, %rsi
movq -0x70(%rbp), %rbx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd1a0
jmp 0x1bd5f
movq 0x1e239(%rip), %rax     # 0x39f90
movq (%rax), %rdi
callq 0xd620
movl -0x2c(%rbp), %esi
incq %rbx
jmp 0x1bc99
xorl %ebx, %ebx
movl -0x5c(%rbp), %ecx
jmp 0x1bd7b
decq %rbx
movl -0x5c(%rbp), %ecx
movl -0x58(%rbp), %r12d
movq -0xa8(%rbp), %rax
cmpq %rax, %rbx
cmovleq %rax, %rbx
cmpl $0x2, %ecx
je 0x1bdec
cmpl $0x1, %ecx
je 0x1bdd0
testl %ecx, %ecx
movq 0x1e1f4(%rip), %r15     # 0x39f90
jne 0x1be7b
cmpq -0x40(%rbp), %rbx
jg 0x1be7b
movq %rbx, %rax
movq -0x90(%rbp), %rbx
subq %rax, %rbx
movq (%r15), %rdi
movl $0x20, %esi
callq 0xd620
decq %rbx
jne 0x1bdb9
jmp 0x1be7b
movq %rbx, %r14
movq 0x1e1b6(%rip), %rbx     # 0x39f90
movq (%rbx), %rdi
movl $0x20, %esi
callq 0xd620
incq %r14
jmp 0x1bdf6
movq %rbx, %r14
movq 0x1e19a(%rip), %rbx     # 0x39f90
movq (%rbx), %rdi
xorl %esi, %esi
callq 0xd730
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1be52
movq -0x38(%rbp), %rax
cmpq 0x38(%rax), %r15
jne 0x1be52
movq -0x50(%rbp), %rdi
movl $0xd, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f8dc
movq -0x48(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %eax, %edx
callq 0x1fb52
movq 0x1e14e(%rip), %rcx     # 0x39f90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
cmpq -0x40(%rbp), %r14
movq 0x1e133(%rip), %r15     # 0x39f90
jg 0x1be7b
movq -0x90(%rbp), %rbx
subq %r14, %rbx
movq (%r15), %rdi
movl $0x20, %esi
callq 0xd620
decq %rbx
jne 0x1be69
movq -0x68(%rbp), %rcx
incq %rcx
cmpq -0x98(%rbp), %rcx
jne 0x1b973
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e0eb(%rip), %rax     # 0x39f90
movq (%rax), %rdi
xorl %esi, %esi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd730
nopl (%rax)