// File: /workspace/github_c_makefile_star2_O1/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 0x1009d
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 0x10003
movq 0x30(%rbx), %r10
cmpq %rdx, 0x8(%r8)
setle %al
testq %r10, %r10
sets %sil
orb %al, %sil
je 0xffb1
xorl %eax, %eax
jmp 0x10003
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 0xe485
cmpq 0x20(%rsp), %rax
jge 0xffdc
xorl %eax, %eax
jmp 0xfff9
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 0xef1b
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r9
leaq (%rdi,%r14), %rcx
movq %rax, %rdx
subq %r9, %rdx
jge 0x1001e
addq 0x20(%rbx), %rdx
xorl %eax, %eax
testq %rdx, %rdx
cmovgq %rdx, %rax
jmp 0x1002d
addq %r12, %rbp
subq %r15, %rbp
subq %rbp, %rax
jle 0x10031
addq 0x20(%rbx), %rax
movq %rax, 0x20(%rbx)
movq 0x38(%rbx), %rax
movq %rax, %rdx
subq %rcx, %rdx
jge 0x1004c
addq 0x28(%rbx), %rdx
xorl %eax, %eax
testq %rdx, %rdx
cmovgq %rdx, %rax
jmp 0x1005e
movq %r13, %rcx
subq %r14, %rcx
addq %rdi, %rcx
subq %rcx, %rax
jle 0x10062
addq 0x28(%rbx), %rax
movq %rax, 0x28(%rbx)
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rax
addq %r13, %rax
decq %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
movq 0x28(%rbx), %rdx
cmpq %rax, %rdx
cmovlq %rdx, %rax
testq %rdx, %rdx
cmovsq %rcx, %rax
movq %rax, 0x28(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq