// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce.c
// Function: ce_buffer_advance_point
CePoint_t ce_buffer_advance_point(CeBuffer_t* buffer, CePoint_t point, int64_t delta){
     if(!ce_buffer_point_is_valid(buffer, point)) return (CePoint_t){-1, -1};

     if(delta < 0){
          while(delta < 0){
               int64_t destination = point.x + delta;
               if(destination < 0){
                    // if we are already at the beginning of the buffer, get out
                    int64_t new_line = point.y - 1;
                    if(new_line < 0){
                         point.x = 0;
                         break;
                    }

                    // move to the previous line, add to the delta
                    if(point.x == 0){
                         delta += 1;
                    }else{
                         delta += point.x;
                    }
                    point.y = new_line;
                    point.x = ce_utf8_strlen(buffer->lines[point.y]);
               }else{
                    point.x = destination;
                    break;
               }
          }
     }else if(delta > 0){
          while(delta > 0){
               int64_t line_len = ce_utf8_strlen(buffer->lines[point.y]);
               int64_t destination = point.x + delta;
               if(destination > line_len){
                    // if we are already at the end of the buffer, get out
                    int64_t new_line = point.y + 1;
                    if(new_line >= buffer->line_count) break;

                    // move to the next line, and subtract from the delta
                    delta -= (line_len - point.x) + 1;
                    point.x = 0;
                    point.y = new_line;
               }else{
                    point.x = destination;
                    break;
               }
          }
     }

     return point;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq $-0x1, %r15
testq %rdx, %rdx
js 0xf02e
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %rbx
cmpq %rdx, 0x8(%rdi)
setle %al
testq %rsi, %rsi
sets %cl
orb %al, %cl
je 0xf04a
movq $-0x1, %r12
movq %r15, %rax
movq %r12, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq (%rax,%rbp,8), %rdi
callq 0xe485
movq $-0x1, %r12
cmpq %r13, %rax
jl 0xf035
testq %r14, %r14
js 0xf0bc
movq %r13, %r15
movq %rbp, %r12
je 0xf035
movq (%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0xe485
leaq (%r15,%r14), %rcx
cmpq %rax, %rcx
jle 0xf0a5
leaq 0x1(%r12), %rcx
cmpq 0x8(%rbx), %rcx
jge 0xf0ac
notq %rax
addq %r14, %r15
addq %rax, %r15
movb $0x1, %al
movq %r15, %r14
xorl %r15d, %r15d
movq %rcx, %r12
jmp 0xf0ae
xorl %eax, %eax
movq %rcx, %r15
jmp 0xf0ae
xorl %eax, %eax
testb %al, %al
je 0xf035
testq %r14, %r14
jg 0xf06f
jmp 0xf035
movq %rbp, %r12
testq %r14, %r14
jns 0xf10a
movq %r13, %r15
addq %r14, %r15
js 0xf0d0
xorl %eax, %eax
jmp 0xf0f9
testq %r12, %r12
jle 0xf105
leaq -0x1(%r12), %rbp
incq %r14
testq %r13, %r13
cmovneq %r15, %r14
movq (%rbx), %rax
movq -0x8(%rax,%r12,8), %rdi
callq 0xe485
movq %rax, %r15
movb $0x1, %al
movq %rbp, %r12
movq %r15, %r13
testb %al, %al
jne 0xf0bf
jmp 0xf035
xorl %r15d, %r15d
jmp 0xf0cc
movq %r13, %r15
jmp 0xf035