// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce.c
// Function: ce_buffer_search_backward
CePoint_t ce_buffer_search_backward(CeBuffer_t* buffer, CePoint_t start, const char* pattern){
     CePoint_t result = (CePoint_t){-1, -1};

     if(!ce_buffer_point_is_valid(buffer, start)) return result;

     char* beginning_of_line = buffer->lines[start.y];
     char* itr = ce_utf8_iterate_to(beginning_of_line, start.x);
     bool match = false;
     size_t pattern_len = strlen(pattern);

     // try to match the pattern on each line to the end
     while(true){
          while(itr > beginning_of_line){
               if(strncmp(itr, pattern, pattern_len) == 0){
                    match = true;
                    break;
               }

               itr--;
          }
          if(match) break;
          start.y--;
          if(start.y < 0) break;
          beginning_of_line = buffer->lines[start.y];
          itr = beginning_of_line + ce_utf8_last_index(beginning_of_line);
     }

     if(match){
          // figure out index in the line
          int64_t index = 0;
          int64_t rune_len = 0;
          while(itr > beginning_of_line){
               ce_utf8_decode(beginning_of_line, &rune_len);
               beginning_of_line += rune_len;
               index++;
          }

          result.x = index;
          result.y = start.y;
     }

     return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rsi, -0x20(%rbp)
movq %rdx, -0x18(%rbp)
movq %rdi, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq 0x33769(%rip), %rax     # 0x42808
movq %rax, -0x10(%rbp)
movq 0x33766(%rip), %rax     # 0x42810
movq %rax, -0x8(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xeba0
cmpq $0x0, %rax
jne 0xf0ca
jmp 0xf1e2
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xeca0
movq %rax, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
movq -0x30(%rbp), %rdi
callq 0xd200
movq %rax, -0x50(%rbp)
jmp 0xf101
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jbe 0xf135
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0xd0d0
cmpl $0x0, %eax
jne 0xf127
movb $0x1, -0x41(%rbp)
jmp 0xf135
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xf101
testb $0x1, -0x41(%rbp)
je 0xf13d
jmp 0xf189
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jge 0xf152
jmp 0xf189
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf1f0
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0xf0ff
testb $0x1, -0x41(%rbp)
je 0xf1e0
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jbe 0xf1d0
movq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xedc0
movq -0x60(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xf19f
movq -0x58(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf1e2
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x70, %rsp
popq %rbp
retq