// File: /workspace/github_c_makefile_star2_O1/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, -0x58(%rbp)
movq %r8, -0x38(%rbp)
movl %ecx, %r12d
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r13
movl 0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
callq 0x100f0
movq %rax, %r14
movq %r13, %rdi
callq 0x100f8
movq %rax, -0x90(%rbp)
movq 0x20(%r13), %rax
movq 0x28(%r13), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xa8(%rbp)
addq %rax, %r14
movq %r14, -0x48(%rbp)
movq %rsp, %r14
leaq 0x10(%rbx), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %r14, %rdi
movl $0x20, %esi
movq %rbx, %rdx
callq 0xd2a0
movq %rbx, -0xa0(%rbp)
movq %r14, -0xd0(%rbp)
movb $0x0, (%rbx,%r14)
movq -0x38(%rbp), %rax
movq (%rax), %rbx
movq 0x40(%r13), %rax
movl $0x0, -0x5c(%rbp)
cmpb $0x0, 0x50(%rax)
movl %r15d, -0x60(%rbp)
jne 0x1b5c6
movq 0x8(%rax), %rsi
movq 0x10(%r13), %rdx
movq 0x18(%r13), %rcx
movl %r15d, %edi
callq 0x10815
testl %eax, %eax
je 0x1b5c6
movslq %eax, %rcx
subq %rcx, -0x48(%rbp)
decl %eax
movl %eax, -0x5c(%rbp)
movq 0x40(%r13), %rax
cmpq $0x0, 0x8(%rax)
js 0x1bb02
cmpq $0x0, -0x90(%rbp)
jle 0x1baf3
movq -0x48(%rbp), %rax
leaq -0x1(%rax), %rcx
movq %rcx, -0xc8(%rbp)
incq %rax
movq %rax, -0x88(%rbp)
movq 0x1f98d(%rip), %r15     # 0x3af90
xorl %r14d, %r14d
movl %r12d, -0x3c(%rbp)
movq $0x0, -0x78(%rbp)
movq %r15, %rax
movq 0x28(%r13), %r15
addq %r14, %r15
movq (%rax), %rdi
movl 0x10(%r13), %esi
addl %r14d, %esi
movl (%r13), %edx
callq 0xd070
cmpl $0x0, -0x60(%rbp)
movq %r14, -0x98(%rbp)
je 0x1b6f3
movq 0x40(%r13), %rax
cmpb $0x0, 0x50(%rax)
jne 0x1b6f3
testq %rbx, %rbx
je 0x1b65d
movl (%rbx), %edx
movl 0x4(%rbx), %eax
movl %eax, -0x38(%rbp)
jmp 0x1b669
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq -0x50(%rbp), %r14
movq %r14, %rdi
movl $0x14, %esi
callq 0x1f940
movl %eax, %r12d
movq %r14, %rdi
movl $0x14, %esi
movl -0x38(%rbp), %edx
callq 0x1f94c
movq -0x58(%rbp), %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x1fbe9
movq 0x1f8ee(%rip), %rcx     # 0x3af90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movl -0x60(%rbp), %eax
cmpl $0x2, %eax
movl -0x3c(%rbp), %r12d
movq -0x98(%rbp), %r14
je 0x1b6d4
leal 0x1(%r15), %edx
cmpl $0x3, %eax
jne 0x1b6e2
cmpq %r15, 0x38(%r13)
je 0x1b6e2
movl 0x38(%r13), %eax
subl %r15d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
leaq 0x14f96(%rip), %rdi     # 0x3067f
movl -0x5c(%rbp), %esi
xorl %eax, %eax
callq 0xd4d0
movq 0x1f896(%rip), %rax     # 0x3af90
movq (%rax), %rdi
xorl %esi, %esi
callq 0xd730
movq 0x40(%r13), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1b734
cmpq 0x38(%r13), %r15
jne 0x1b734
movq -0x50(%rbp), %rdi
movl $0xd, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f94c
movq -0x58(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %eax, %edx
jmp 0x1b75c
testq %rbx, %rbx
je 0x1b778
movq 0x28(%r13), %rsi
addq %r14, %rsi
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
xorl %edi, %edi
callq 0xedfb
testb %al, %al
je 0x1b778
movl (%rbx), %esi
movl 0x4(%rbx), %edx
movq -0x58(%rbp), %rdi
callq 0x1fbe9
movq 0x1f828(%rip), %rcx     # 0x3af90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq -0xc0(%rbp), %rax
addq %r14, %rax
movq 0x40(%r13), %rcx
cmpq 0x8(%rcx), %rax
jge 0x1b9de
movq (%rcx), %rcx
movq (%rcx,%rax,8), %r12
xorl %r14d, %r14d
xorl %edx, %edx
movq %rdx, -0x38(%rbp)
movq %r12, %rdi
leaq -0x78(%rbp), %rsi
callq 0xe649
movl %eax, -0x2c(%rbp)
testq %rbx, %rbx
je 0x1b820
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0xedfb
testb %al, %al
jne 0x1b820
movl 0x4(%rbx), %edx
movq 0x40(%r13), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1b7f8
cmpl $-0x1, %edx
jne 0x1b7f8
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq 0x38(%r13), %r15
jne 0x1b7f8
movq -0x50(%rbp), %rdi
movl $0xd, %esi
callq 0x1f94c
movl %eax, %edx
movl (%rbx), %esi
movq -0x58(%rbp), %rdi
callq 0x1fbe9
movq 0x1f786(%rip), %rcx     # 0x3af90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq 0x18(%rbx), %rbx
jmp 0x1b7af
movq -0x78(%rbp), %rdi
addq %r12, %rdi
movq $0x0, -0xd8(%rbp)
leaq -0xd8(%rbp), %rsi
callq 0xe649
movq -0x38(%rbp), %rdx
cmpq -0x48(%rbp), %rdx
jg 0x1b900
cmpl $0x0, -0x64(%rbp)
je 0x1b90b
movq 0x8(%r13), %rcx
cmpq -0xb0(%rbp), %rcx
jl 0x1b869
cmpq -0x48(%rbp), %rdx
je 0x1b883
cmpq -0xb0(%rbp), %rcx
jge 0x1b90b
cmpq -0xc8(%rbp), %rdx
jne 0x1b90b
testl %eax, %eax
je 0x1b90b
movq -0x50(%rbp), %rdi
movl $0x17, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f94c
movl %eax, -0x7c(%rbp)
movq -0x50(%rbp), %rdi
movl $0x17, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f940
movq -0x58(%rbp), %rdi
movl %eax, %esi
movl -0x7c(%rbp), %edx
callq 0x1fbe9
movq 0x1f6c7(%rip), %rcx     # 0x3af90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
movq 0x1f6b0(%rip), %rax     # 0x3af90
movq (%rax), %rdi
movl -0x64(%rbp), %esi
callq 0xd620
movq 0x1f69e(%rip), %rax     # 0x3af90
movq (%rax), %rdi
xorl %esi, %esi
callq 0xd730
movq -0x38(%rbp), %rdx
incq %rdx
movl -0x2c(%rbp), %esi
jmp 0x1b9c6
cmpq -0xa8(%rbp), %rdx
movl -0x2c(%rbp), %esi
jl 0x1b94f
testl %esi, %esi
jle 0x1b94f
cmpl $0x9, %esi
jne 0x1b95d
addq -0xa0(%rbp), %rdx
movq %rdx, -0x38(%rbp)
movq 0x1f65e(%rip), %rax     # 0x3af90
movq (%rax), %rdi
movq -0xd0(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd1a0
movl -0x2c(%rbp), %esi
movq -0x38(%rbp), %rdx
jmp 0x1b9c6
cmpl $0x9, %esi
jne 0x1b9c3
addq -0xa0(%rbp), %rdx
jmp 0x1b9c6
cmpl $0x80, %esi
jl 0x1b9ad
movq $0x0, -0xb8(%rbp)
movl $0x4, %edx
movl %esi, %edi
leaq -0x69(%rbp), %rsi
leaq -0xb8(%rbp), %rcx
callq 0xf298
movq -0xb8(%rbp), %rax
movb $0x0, -0x69(%rbp,%rax)
movq 0x1f5f6(%rip), %rax     # 0x3af90
movq (%rax), %rdi
leaq -0x69(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd1a0
jmp 0x1b9bc
movq 0x1f5dc(%rip), %rax     # 0x3af90
movq (%rax), %rdi
callq 0xd620
movl -0x2c(%rbp), %esi
movq -0x38(%rbp), %rdx
incq %rdx
addq -0x78(%rbp), %r12
incq %r14
testl %esi, %esi
jg 0x1b79c
decq %rdx
movl -0x3c(%rbp), %r12d
jmp 0x1b9e0
xorl %edx, %edx
movq -0xa8(%rbp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
cmpl $0x2, %r12d
je 0x1ba51
cmpl $0x1, %r12d
je 0x1ba35
testl %r12d, %r12d
movq 0x1f58c(%rip), %r15     # 0x3af90
jne 0x1bad8
cmpq -0x48(%rbp), %rdx
jg 0x1bad8
movq -0x88(%rbp), %r14
subq %rdx, %r14
movq (%r15), %rdi
movl $0x20, %esi
callq 0xd620
decq %r14
jne 0x1ba1e
jmp 0x1bad8
movq 0x1f554(%rip), %r14     # 0x3af90
movq (%r14), %rdi
movl $0x20, %esi
movq %rdx, %r12
callq 0xd620
incq %r12
jmp 0x1ba5b
movq %rdx, %r12
movq 0x1f535(%rip), %r14     # 0x3af90
movq (%r14), %rdi
xorl %esi, %esi
callq 0xd730
movq 0x40(%r13), %rax
cmpb $0x0, 0x51(%rax)
jne 0x1baaf
cmpq 0x38(%r13), %r15
jne 0x1baaf
movq -0x50(%rbp), %rdi
movl $0xd, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f94c
movq -0x58(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %eax, %edx
callq 0x1fbe9
movq 0x1f4f1(%rip), %rcx     # 0x3af90
movq (%rcx), %rdi
shll $0x8, %eax
movzwl %ax, %esi
xorl %edx, %edx
callq 0xd0f0
cmpq -0x48(%rbp), %r12
movq 0x1f4d6(%rip), %r15     # 0x3af90
jg 0x1bad8
movq -0x88(%rbp), %r14
subq %r12, %r14
movq (%r15), %rdi
movl $0x20, %esi
callq 0xd620
decq %r14
jne 0x1bac6
movq -0x98(%rbp), %r14
incq %r14
cmpq -0x90(%rbp), %r14
movl -0x3c(%rbp), %r12d
jne 0x1b60a
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1f487(%rip), %rax     # 0x3af90
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)