// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x148(%rbp)
movb %r9b, %al
movq %rdi, -0x140(%rbp)
movl 0x10(%rbp), %edi
movq %rdx, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movq %rsi, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq 0xea35(%rip), %rax      # 0x45710
movq %rax, -0x40(%rbp)
movq 0xea32(%rip), %rax      # 0x45718
movq %rax, -0x38(%rbp)
movq 0xea2f(%rip), %rax      # 0x45720
movq %rax, -0x30(%rbp)
movq 0xea2c(%rip), %rax      # 0x45728
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
callq 0xeba0
cmpq $0x0, %rax
jne 0x36d42
movq -0x148(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x3746c
movl -0x1c(%rbp), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, -0x150(%rbp)
subl $0x5b, %eax
ja 0x36d6d
movq -0x150(%rbp), %rax
leaq 0xe48c(%rip), %rcx      # 0x451f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x148(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x3746c
movl $0x28, -0x44(%rbp)
movl $0x29, -0x48(%rbp)
jmp 0x36f31
movl $0x7b, -0x44(%rbp)
movl $0x7d, -0x48(%rbp)
jmp 0x36f31
movl $0x5b, -0x44(%rbp)
movl $0x5d, -0x48(%rbp)
jmp 0x36f31
movl $0x3c, -0x44(%rbp)
movl $0x3e, -0x48(%rbp)
jmp 0x36f31
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rcx
leaq -0x68(%rbp), %rdi
movsbl %al, %r8d
callq 0x36ad0
testb $0x1, -0x1d(%rbp)
je 0x36ecc
cmpq $0x0, -0x68(%rbp)
jl 0x36ecc
cmpq $0x0, -0x58(%rbp)
jl 0x36ecc
movq -0x18(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl $0x1, %ecx
callq 0xfaf0
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq $-0x1, %rcx
callq 0xfaf0
movq %rax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0xf690
testb $0x1, %al
jne 0x36e9f
jmp 0x36eca
movq -0x148(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x3746c
jmp 0x36ecc
movq -0x148(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x3746c
movq -0x148(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rcx
callq 0x367a0
jmp 0x3746c
movq -0x148(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rcx
callq 0x36930
jmp 0x3746c
movslq 0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0xec20
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x48(%rbp), %eax
jne 0x36fbe
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
movq $-0x1, %rcx
callq 0xfaf0
movq %rax, -0xb8(%rbp)
movq %rdx, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x3700b
movl -0xa4(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x37009
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl $0x1, %ecx
callq 0xfaf0
movq %rax, -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x3700b
movq -0xa0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0xec20
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x370e3
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x37480
testb $0x1, %al
jne 0x370e3
movq -0x90(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jge 0x370e1
testb $0x1, -0x1d(%rbp)
je 0x370c0
movq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x370dc
movq -0xa0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x371c5
jmp 0x3711d
movl -0xa4(%rbp), %eax
cmpl -0x48(%rbp), %eax
jne 0x3711b
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x37480
testb $0x1, %al
jne 0x3711b
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x3711d
cmpq $0x0, -0xa0(%rbp)
jne 0x3715c
cmpq $0x0, -0x98(%rbp)
jne 0x3715c
movq -0x148(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x3746c
movq -0xa0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq $-0x1, %rcx
callq 0xfaf0
movq %rax, -0xf8(%rbp)
movq %rdx, -0xf0(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x3703d
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rcx
callq 0xfec0
testb $0x1, %al
jne 0x371e6
jmp 0x37228
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl $0x1, %ecx
callq 0xfaf0
movq %rax, -0x108(%rbp)
movq %rdx, -0x100(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x3723e
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd0(%rbp)
movslq 0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdi
callq 0xf1f0
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movq %rax, -0x120(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0xec20
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x48(%rbp), %eax
jne 0x37357
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x37480
testb $0x1, %al
jne 0x37357
movq -0x90(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jge 0x37355
testb $0x1, -0x1d(%rbp)
je 0x37334
movq -0xd8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x37350
movq -0xa0(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x3741a
jmp 0x37391
movl -0xa4(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x3738f
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x37480
testb $0x1, %al
jne 0x3738f
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x37391
movq -0xa0(%rbp), %rax
cmpq -0x128(%rbp), %rax
jne 0x373b3
movq -0x98(%rbp), %rax
cmpq -0x120(%rbp), %rax
jne 0x373b3
jmp 0x3741a
movq -0xa0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movl $0x1, %ecx
callq 0xfaf0
movq %rax, -0x138(%rbp)
movq %rdx, -0x130(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x372b1
movq -0x148(%rbp), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq -0xe0(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq -0x118(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movq -0x110(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x140(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax)