// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_commands.c
// Function: buffer_replace_all
void buffer_replace_all(CeBuffer_t* buffer, CePoint_t cursor, const char* match, const char* replacement, CePoint_t start, CePoint_t end,
                        bool regex_search){
     bool chain_undo = false;
     int64_t match_len = 0;
#if !defined(PLATFORM_WINDOWS)
     CeRegex_t regex = NULL;
#endif

     if(regex_search){
#if defined(PLATFORM_WINDOWS)
          return;
#else
          CeRegexResult_t regex_result = ce_regex_init(match,
                                                       &regex);
          if(regex_result.error_message != NULL){
               ce_log("ce_regex_init() failed: '%s'", regex_result.error_message);
               free(regex_result.error_message);
               return;
          }
#endif
     }else{
           match_len = strlen(match);
     }

     while(true){
          CePoint_t match_point;

          // find the match
          if(regex_search){
#if defined(PLATFORM_WINDOWS)
               return;
#else
               CeRegexSearchResult_t result = ce_buffer_regex_search_forward(buffer, start, regex);
               match_point = result.point;
               match_len = result.length;
               break;
#endif
          }else{
               match_point = ce_buffer_search_forward(buffer, start, match);
          }

          if(match_point.x < 0) break;
          if(ce_point_after(match_point, end)) break;

          ce_buffer_remove_string_change(buffer, match_point, match_len, &cursor, cursor, chain_undo);
          chain_undo = true;

          ce_buffer_insert_string_change(buffer, strdup(replacement), match_point, &cursor, cursor, chain_undo);

          start = ce_buffer_advance_point(buffer, match_point, ce_utf8_strlen(replacement));
     }
#if !defined(PLATFORM_WINDOWS)
     ce_regex_free(regex);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %r9b, %al
leaq 0x20(%rbp), %r9
movq %r9, -0xb0(%rbp)
leaq 0x10(%rbp), %r9
movq %r9, -0xa8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movb $0x0, -0x2a(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
testb $0x1, -0x29(%rbp)
je 0x21371
movq -0x20(%rbp), %rsi
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x2a950
cmpq $0x0, -0x58(%rbp)
je 0x2136f
movq -0x58(%rbp), %rsi
leaq 0x23194(%rip), %rdi     # 0x444ee
movb $0x0, %al
callq 0xd8f0
movq -0x58(%rbp), %rdi
callq 0xd090
jmp 0x2151d
jmp 0x2137e
movq -0x20(%rbp), %rdi
callq 0xd200
movq %rax, -0x38(%rbp)
jmp 0x21380
testb $0x1, -0x29(%rbp)
je 0x213c2
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %r8
movq (%rax), %rdx
movq 0x8(%rax), %rcx
leaq -0x80(%rbp), %rdi
callq 0xf230
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x21514
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq (%rax), %rsi
movq 0x8(%rax), %rdx
callq 0xef30
movq %rax, -0x90(%rbp)
movq %rdx, -0x88(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x68(%rbp)
jge 0x2140d
jmp 0x21514
movq -0xb0(%rbp), %rax
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq (%rax), %rdx
movq 0x8(%rax), %rcx
callq 0xf690
testb $0x1, %al
jne 0x2142e
jmp 0x21433
jmp 0x21514
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rcx
movb -0x2a(%rbp), %al
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x10(%rbp), %r9
andb $0x1, %al
movq %r9, %r8
movq (%r9), %r10
movq %r10, (%rsp)
movq 0x8(%r9), %r9
movq %r9, 0x8(%rsp)
movzbl %al, %r9d
callq 0x110a0
movb $0x1, -0x2a(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rdi
callq 0xd620
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
movb -0x2a(%rbp), %al
movq -0x68(%rbp), %rdx
movq -0x60(%rbp), %rcx
leaq -0x10(%rbp), %r9
andb $0x1, %al
movq %r9, %r8
movq (%r9), %r10
movq %r10, (%rsp)
movq 0x8(%r9), %r9
movq %r9, 0x8(%rsp)
movzbl %al, %r9d
callq 0x10da0
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rdi
callq 0xea70
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0xfaf0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
movq -0xa0(%rbp), %rcx
movq %rcx, (%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x21380
movq -0x40(%rbp), %rdi
callq 0x2aaf0
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)