// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_vim.c
// Function: ce_vim_find_pair
CeRange_t ce_vim_find_pair(CeBuffer_t* buffer, CePoint_t start, CeRune_t rune, bool inside, int level){
     CeRange_t range = {(CePoint_t){-1, -1}, (CePoint_t){-1, -1}};
     if(!ce_buffer_point_is_valid(buffer, start)) return range;
     CeRune_t left_match;
     CeRune_t right_match;

     switch(rune){
     default:
          return range;
     case ')':
     case '(':
          left_match = '(';
          right_match = ')';
          break;
     case '{':
     case '}':
          left_match = '{';
          right_match = '}';
          break;
     case '[':
     case ']':
          left_match = '[';
          right_match = ']';
          break;
     case '<':
     case '>':
          left_match = '<';
          right_match = '>';
          break;
     case '"':
     case '\'':
     {
          CeRange_t string_range = ce_vim_find_string_boundaries(buffer, start, rune);
          if(inside && string_range.start.x >= 0 && string_range.end.x >= 0){
               string_range.start = ce_buffer_advance_point(buffer, string_range.start, 1);
               string_range.end = ce_buffer_advance_point(buffer, string_range.end, -1);
               if(ce_point_after(string_range.start, string_range.end)) return range; // empty in between
          }
          return string_range;
     }
     case 'w':
          return ce_vim_find_little_word_boundaries(buffer, start);
     case 'W':
          return ce_vim_find_big_word_boundaries(buffer, start);
     }

     int64_t match_count = level;

     // find left match
     CePoint_t itr = start;
     CeRune_t buffer_rune = ce_buffer_get_rune(buffer, itr);
     // if we start on a right match, back up the starting point
     if(buffer_rune == right_match){
          itr = ce_buffer_advance_point(buffer, start, -1);
     }else if(buffer_rune == left_match){
          itr = ce_buffer_advance_point(buffer, start, 1);
     }
     CePoint_t prev = itr;
     CePoint_t new_start = range.start;
     while(true){
          buffer_rune = ce_buffer_get_rune(buffer, itr); // NOTE: decoding would be faster
          if(buffer_rune == left_match && !point_in_string_or_comment(buffer, itr)){
               match_count--;
               if(match_count < 0){
                    new_start = inside ? prev : itr;
                    break;
               }
          }else if(buffer_rune == right_match && !point_in_string_or_comment(buffer, itr)){
               match_count++;
          }
          if(itr.x == 0 && itr.y == 0) return range;
          prev = itr;
          itr = ce_buffer_advance_point(buffer, itr, -1);
     }

     // find right match
     if(ce_points_equal(itr, start)){
          itr = ce_buffer_advance_point(buffer, start, 1);
     }else{
          itr = start;
     }

     prev = itr;
     match_count = level;
     CePoint_t new_end = range.end;
     CePoint_t end_of_buffer = {ce_utf8_last_index(buffer->lines[buffer->line_count - 1]), buffer->line_count - 1};
     while(true){
          buffer_rune = ce_buffer_get_rune(buffer, itr);
          if(buffer_rune == right_match && !point_in_string_or_comment(buffer, itr)){
               match_count--;
               if(match_count < 0){
                    new_end = inside ? prev : itr;
                    break;
               }
          }else if(buffer_rune == left_match && !point_in_string_or_comment(buffer, itr)){
               match_count++;
          }
          if(itr.x == end_of_buffer.x && itr.y == end_of_buffer.y) break;
          prev = itr;
          itr = ce_buffer_advance_point(buffer, itr, 1);
     }

     range.start = new_start;
     range.end = new_end;
     return range;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %ebp
movl %r8d, %r12d
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r13
movq %rsi, %rdi
movq %rdx, 0x10(%rsp)
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xe514
testq %rax, %rax
je 0x272fa
cmpl $0x56, %r12d
movq %rbx, 0x18(%rsp)
jg 0x271f1
cmpl $0x27, %r12d
jle 0x2724f
leal -0x28(%r12), %eax
cmpl $0x2, %eax
jb 0x27312
cmpl $0x3c, %r12d
je 0x271df
cmpl $0x3e, %r12d
jne 0x272fa
movl $0x3c, 0xc(%rsp)
movl $0x3e, %ebx
jmp 0x2731f
cmpl $0x76, %r12d
jg 0x27223
cmpl $0x57, %r12d
je 0x27560
cmpl $0x5b, %r12d
je 0x27211
cmpl $0x5d, %r12d
jne 0x272fa
movl $0x5b, 0xc(%rsp)
movl $0x5d, %ebx
jmp 0x2731f
cmpl $0x77, %r12d
je 0x27578
cmpl $0x7b, %r12d
je 0x2723d
cmpl $0x7d, %r12d
jne 0x272fa
movl $0x7b, 0xc(%rsp)
movl $0x7d, %ebx
jmp 0x2731f
cmpl $0x22, %r12d
je 0x2725f
cmpl $0x27, %r12d
jne 0x272fa
movsbl %r12b, %r8d
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x27023
movq (%r12), %rsi
movq 0x10(%r12), %rbx
testq %rsi, %rsi
setns %al
andb %al, %bpl
testq %rbx, %rbx
setns %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x2753b
movq 0x48(%rsp), %rdx
movl $0x1, %ecx
movq %r14, %rdi
callq 0xeffa
movq %rax, %r15
movq %rdx, %r12
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x58(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0xeffa
movq %rdx, %rcx
movq %rax, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xedfb
testb %al, %al
je 0x2753b
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x10(%r13)
movdqu %xmm0, (%r13)
movq %r13, %rax
jmp 0x27411
movl $0x28, 0xc(%rsp)
movl $0x29, %ebx
movl %ebp, 0x20(%rsp)
movq %r13, 0x38(%rsp)
movl 0xa0(%rsp), %ebp
movq %r14, %rdi
movq 0x10(%rsp), %r12
movq %r12, %rsi
movq 0x18(%rsp), %r15
movq %r15, %rdx
callq 0xe54e
movq $-0x1, %rcx
movl %ebx, 0x24(%rsp)
cmpl %ebx, %eax
je 0x27369
movl %eax, %esi
movl $0x1, %ecx
movq %r12, %rax
movq %r15, %rdx
cmpl 0xc(%rsp), %esi
jne 0x27377
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xeffa
movslq %ebp, %rbx
movq %rax, 0x30(%rsp)
movq %rdx, %r15
movq %rbx, 0x28(%rsp)
movq %rax, %r13
movq %rdx, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0xe54e
movl %eax, %ebp
cmpl 0xc(%rsp), %eax
jne 0x273b2
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x275c0
testb %al, %al
je 0x273d0
cmpl 0x24(%rsp), %ebp
jne 0x273d8
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x275c0
xorb $0x1, %al
movzbl %al, %eax
addq %rax, %rbx
jmp 0x273d8
testq %rbx, %rbx
jle 0x27420
decq %rbx
movq %r13, %rax
orq %r12, %rax
je 0x273ff
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq $-0x1, %rcx
callq 0xeffa
movq %r13, 0x30(%rsp)
movq %r12, %r15
jmp 0x27387
pcmpeqd %xmm0, %xmm0
movq 0x38(%rsp), %rax
movdqu %xmm0, 0x10(%rax)
movdqu %xmm0, (%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x20(%rsp)
movq 0x30(%rsp), %rax
cmoveq %r13, %rax
movq %rax, 0x30(%rsp)
cmoveq %r12, %r15
movq %r13, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %r12
movq %r12, %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
callq 0xf1d6
testb %al, %al
je 0x2746f
movl $0x1, %ecx
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0xeffa
movq %rax, %r12
movq %rdx, %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
callq 0xe97d
movq %rax, 0x10(%rsp)
movq 0x8(%r14), %rax
decq %rax
movq %rax, 0x60(%rsp)
movq %r12, 0x18(%rsp)
movq %rbx, %rbp
movq %r12, %rax
movq %rax, %r12
movq %rbx, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xe54e
movl %eax, %ebx
cmpl 0x24(%rsp), %eax
jne 0x274ca
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x275c0
testb %al, %al
je 0x274f4
cmpl 0xc(%rsp), %ebx
jne 0x274ed
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x275c0
xorb $0x1, %al
movzbl %al, %eax
movq 0x28(%rsp), %rcx
addq %rax, %rcx
jmp 0x27505
movq 0x28(%rsp), %rcx
jmp 0x27505
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
jle 0x27590
decq %rcx
cmpq 0x10(%rsp), %r12
jne 0x27513
cmpq 0x60(%rsp), %r13
je 0x27550
movq %rcx, 0x28(%rsp)
movl $0x1, %ecx
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xeffa
movq %rdx, %rbx
movq %r12, 0x18(%rsp)
movq %r13, %rbp
jmp 0x2749c
movdqu 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%r13)
jmp 0x27304
movq $-0x1, %r13
movq $-0x1, %r12
jmp 0x2759f
movq %r13, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x26ee7
jmp 0x2730a
movq %r13, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x26db0
jmp 0x2730a
cmpb $0x0, 0x20(%rsp)
cmovneq %rbp, %r13
cmovneq 0x18(%rsp), %r12
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %r13, 0x18(%rax)
movq %rax, %r13
jmp 0x2730a