// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movq %rsi, %rdi
movq %rdx, 0x10(%rsp)
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xe425
testq %rax, %rax
je 0x244f3
leal -0x28(%r15), %eax
cmpl $0x2, %eax
jb 0x24359
cmpl $0x22, %r15d
je 0x2445a
cmpl $0x27, %r15d
je 0x2445a
cmpl $0x3c, %r15d
je 0x2434b
cmpl $0x3e, %r15d
je 0x2434b
cmpl $0x57, %r15d
je 0x2464c
cmpl $0x5b, %r15d
je 0x2433d
cmpl $0x5d, %r15d
je 0x2433d
cmpl $0x77, %r15d
je 0x24664
cmpl $0x7b, %r15d
je 0x2432f
cmpl $0x7d, %r15d
jne 0x244f3
movq %rbx, %r15
pushq $0x7b
popq %rax
movl %eax, 0xc(%rsp)
pushq $0x7d
jmp 0x24365
movq %rbx, %r15
pushq $0x5b
popq %rax
movl %eax, 0xc(%rsp)
pushq $0x5d
jmp 0x24365
movq %rbx, %r15
pushq $0x3c
popq %rax
movl %eax, 0xc(%rsp)
pushq $0x3e
jmp 0x24365
movq %rbx, %r15
pushq $0x28
popq %rax
movl %eax, 0xc(%rsp)
pushq $0x29
popq %rbx
movq %r14, %rdi
movq 0x10(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
callq 0xe45f
movl %ebx, 0x24(%rsp)
cmpl %ebx, %eax
movq %r15, 0x18(%rsp)
jne 0x2438a
pushq $-0x1
jmp 0x2439a
movl %eax, %ecx
movq %r13, %rax
movq %r15, %rdx
cmpl 0xc(%rsp), %ecx
jne 0x243ad
pushq $0x1
popq %rcx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0xec3a
movl %ebp, 0x20(%rsp)
movq %r12, 0x38(%rsp)
movslq 0xa0(%rsp), %rbx
movq %rax, 0x30(%rsp)
movq %rdx, %r13
movq %rbx, 0x28(%rsp)
movq %rax, %r15
movq %rdx, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0xe45f
movl %eax, %ebp
cmpl 0xc(%rsp), %eax
jne 0x243f6
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x246ac
testb %al, %al
je 0x24414
cmpl 0x24(%rsp), %ebp
jne 0x24420
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x246ac
xorb $0x1, %al
movzbl %al, %eax
addq %rax, %rbx
jmp 0x24420
testq %rbx, %rbx
jle 0x24516
decq %rbx
movq %r15, %rax
orq %r12, %rax
je 0x24443
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
pushq $-0x1
popq %rcx
callq 0xec3a
movq %r15, 0x30(%rsp)
movq %r12, %r13
jmp 0x243cb
pcmpeqd %xmm0, %xmm0
movq 0x38(%rsp), %rax
movdqu %xmm0, 0x10(%rax)
movdqu %xmm0, (%rax)
jmp 0x24507
movsbl %r15b, %r8d
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x2415c
movq (%r15), %rsi
movq 0x10(%r15), %rbx
testq %rsi, %rsi
setns %al
andb %al, %bpl
testq %rbx, %rbx
setns %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x2462d
movq 0x48(%rsp), %rdx
pushq $0x1
popq %rcx
movq %r14, %rdi
callq 0xec3a
movq %rax, %r15
movq %r12, %r13
movq %rdx, %r12
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x58(%rsp), %rdx
pushq $-0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xec3a
movq %rdx, %rcx
movq %rax, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %r12
movq %rax, %rdx
callq 0xea69
testb %al, %al
je 0x2462d
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x10(%r12)
movdqu %xmm0, (%r12)
movq %r12, %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 %r15, %rax
movq %rax, 0x30(%rsp)
cmoveq %r12, %r13
movq %r15, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
callq 0xedb2
testb %al, %al
je 0x24563
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xec3a
movq %rax, %r15
movq %rdx, %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
callq 0xe784
movq %rax, 0x10(%rsp)
movq 0x8(%r14), %rax
decq %rax
movq %rax, 0x60(%rsp)
movq %r15, 0x18(%rsp)
movq %rbx, %rbp
movq %r15, %rax
movq %rax, %r12
movq %rbx, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xe45f
movl %eax, %ebx
cmpl 0x24(%rsp), %eax
jne 0x245be
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x246ac
testb %al, %al
je 0x245e8
cmpl 0xc(%rsp), %ebx
jne 0x245e1
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x246ac
xorb $0x1, %al
movzbl %al, %eax
movq 0x28(%rsp), %rcx
addq %rax, %rcx
jmp 0x245f9
movq 0x28(%rsp), %rcx
jmp 0x245f9
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
jle 0x2467c
decq %rcx
cmpq 0x10(%rsp), %r12
jne 0x24607
cmpq 0x60(%rsp), %r15
je 0x24643
movq %rcx, 0x28(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
pushq $0x1
popq %rcx
callq 0xec3a
movq %rdx, %rbx
movq %r12, 0x18(%rsp)
movq %r15, %rbp
jmp 0x24590
movdqu 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%r12)
jmp 0x244fe
pushq $-0x1
popq %r15
movq %r15, %r12
jmp 0x2468b
movq %r12, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x2403c
jmp 0x24504
movq %r12, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x23f4a
jmp 0x24504
cmpb $0x0, 0x20(%rsp)
cmovneq %rbp, %r15
cmovneq 0x18(%rsp), %r12
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %rax, %r12
movq %r15, 0x18(%rax)
jmp 0x24504