// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rdi
testq %rdi, %rdi
je 0xfb9c
movq %rsi, %r15
movq %rcx, 0x8(%rsp)
movq 0x8(%rbx), %r13
movq 0x10(%rbx), %rbp
notq %rbp
addq 0x18(%rbx), %rbp
subq (%rbx), %r13
leaq (%rdx,%rdx), %rax
xorl %r12d, %r12d
cmpq %rax, %rbp
cmovleq %r12, %rdx
movq %rdx, 0x20(%rsp)
leaq (%rsi,%rsi), %rax
cmpq %rax, %r13
cmovleq %r12, %r15
movq 0x20(%rbx), %r14
leaq (%r15,%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rdx
callq 0xe425
testq %rax, %rax
je 0xfb05
movq 0x40(%rbx), %rax
movq (%rax), %rax
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rdx
callq 0xeb75
movq %rax, %r12
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r8
leaq (%r8,%rdi), %rcx
movq %r12, %rax
subq 0x10(%rsp), %rax
jge 0xfb2d
addq 0x20(%rbx), %rax
xorl %r12d, %r12d
testq %rax, %rax
cmovgq %rax, %r12
jmp 0xfb3c
addq %r13, %r14
subq %r15, %r14
subq %r14, %r12
jle 0xfb40
addq 0x20(%rbx), %r12
movq %r12, 0x20(%rbx)
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
jge 0xfb62
addq %rax, %rsi
xorl %eax, %eax
testq %rsi, %rsi
cmovgq %rsi, %rax
movq %rax, 0x28(%rbx)
jmp 0xfb73
movq %rbp, %rcx
subq %rdi, %rcx
addq %r8, %rcx
subq %rcx, %rdx
jle 0xfb73
addq %rdx, %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rcx
addq %rbp, %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