// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce.c
// Function: ce_view_follow_cursor
void ce_view_follow_cursor(CeView_t* view, int64_t horizontal_scroll_off, int64_t vertical_scroll_off, int64_t tab_width){
     if(!view->buffer) return;

     int64_t view_height = (view->rect.bottom - view->rect.top) - 1; // account for status bar
     int64_t view_width = (view->rect.right - view->rect.left);

     if(view_height <= (vertical_scroll_off * 2)){
         vertical_scroll_off = 0;
     }

     if(view_width <= (horizontal_scroll_off * 2)){
         horizontal_scroll_off = 0;
     }

     int64_t scroll_left = view->scroll.x + horizontal_scroll_off;
     int64_t scroll_top = view->scroll.y + vertical_scroll_off;
     int64_t scroll_right = view->scroll.x + (view->rect.right - view->rect.left) - horizontal_scroll_off;
     int64_t scroll_bottom = view->scroll.y + view_height - vertical_scroll_off;

     int64_t visible_index = 0;
     if(ce_buffer_point_is_valid(view->buffer, view->cursor)){
          visible_index = ce_util_string_index_to_visible_index(view->buffer->lines[view->cursor.y],
                                                                view->cursor.x, tab_width);
     }

     if(visible_index < scroll_left){
          view->scroll.x -= (scroll_left - visible_index);
          if(view->scroll.x < 0) view->scroll.x = 0;
     }else if(visible_index > scroll_right){
          view->scroll.x += (visible_index - scroll_right);
     }

     if(view->cursor.y < scroll_top){
          view->scroll.y -= (scroll_top - view->cursor.y);
          if(view->scroll.y < 0) view->scroll.y = 0;
     }else if(view->cursor.y > scroll_bottom){
          view->scroll.y += (view->cursor.y - scroll_bottom);
     }

     int64_t max_scroll_y = ((view->buffer->line_count - 1) + view_height);
     if(max_scroll_y < 0) max_scroll_y = 0;
     CE_CLAMP(view->scroll.y, 0, max_scroll_y);
}

// Assembly:
movq 0x40(%rdi), %r8
testq %r8, %r8
je 0xff1b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq 0x10(%rdi), %r13
notq %r13
addq 0x18(%rdi), %r13
subq (%rdi), %r12
addq %rdx, %rdx
xorl %eax, %eax
cmpq %rdx, %r13
cmovleq %rax, %r14
leaq (%rsi,%rsi), %rdx
cmpq %rdx, %r12
cmovleq %rax, %r15
movq 0x20(%rdi), %rbp
leaq (%r15,%rbp), %r9
movq 0x28(%rdi), %rdi
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
js 0xfe83
movq 0x30(%rbx), %r10
cmpq %rdx, 0x8(%r8)
setle %al
testq %r10, %r10
sets %sil
orb %al, %sil
je 0xfe31
xorl %eax, %eax
jmp 0xfe83
movq %r9, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq (%r8), %rax
movq (%rax,%rdx,8), %rdi
movq %r10, 0x20(%rsp)
callq 0xe445
cmpq 0x20(%rsp), %rax
jge 0xfe5c
xorl %eax, %eax
jmp 0xfe79
movq 0x40(%rbx), %rax
movq (%rax), %rax
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x18(%rsp), %rdx
callq 0xed91
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r9
leaq (%rdi,%r14), %rcx
movq %rax, %rdx
subq %r9, %rdx
jge 0xfe9e
addq 0x20(%rbx), %rdx
xorl %eax, %eax
testq %rdx, %rdx
cmovgq %rdx, %rax
jmp 0xfead
addq %r12, %rbp
subq %r15, %rbp
subq %rbp, %rax
jle 0xfeb1
addq 0x20(%rbx), %rax
movq %rax, 0x20(%rbx)
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
jge 0xfed3
addq %rax, %rsi
xorl %eax, %eax
testq %rsi, %rsi
cmovgq %rsi, %rax
movq %rax, 0x28(%rbx)
jmp 0xfee4
movq %r13, %rcx
subq %r14, %rcx
addq %rdi, %rcx
subq %rcx, %rdx
jle 0xfee4
addq %rdx, %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rcx
addq %r13, %rcx
decq %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovleq %rdx, %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
testq %rax, %rax
cmovsq %rdx, %rcx
movq %rcx, 0x28(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq