// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r14
movq %rdi, %rbx
leaq 0x90(%rsp), %r12
movq %rsi, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
testl %r9d, %r9d
je 0x190f4
leaq 0x40(%rsp), %r15
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x1f3a0
movq (%r15), %rsi
testq %rsi, %rsi
je 0x191f3
leaq 0x1648a(%rip), %rdi     # 0x2f568
xorl %eax, %eax
callq 0xd954
movq 0x40(%rsp), %rdi
callq 0xd090
jmp 0x19218
movq %r8, %r15
leaq 0xa0(%rsp), %r13
movq %r14, %rdi
callq 0xd210
movq %rax, 0x28(%rsp)
movq (%r13), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%r13), %rax
movq %rax, 0x30(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rcx
callq 0xe6aa
testq %rax, %rax
js 0x1920e
movq %rax, %r13
movq %rdx, %rbp
xorl %r12d, %r12d
movq %r13, %rdi
movq %rbp, %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xec71
testb %al, %al
jne 0x1920e
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rsp)
movzbl %r12b, %r9d
andl $0x1, %r9d
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq 0x28(%rsp), %rcx
leaq 0x18(%rsp), %r12
movq %r12, %r8
callq 0xfab0
movq %r15, %rdi
callq 0xd640
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r12, %r8
movl $0x1, %r9d
callq 0xf8ee
movq %r15, %rdi
callq 0xe445
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rax, %rcx
callq 0xee7a
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rcx
callq 0xe6aa
movq %rax, %r13
movq %rdx, %rbp
movb $0x1, %r12b
testq %rax, %rax
jns 0x19144
jmp 0x1920e
movq (%r12), %rdx
movq 0x8(%r12), %rcx
movq 0x10(%rsp), %r8
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xe8e3
movq 0x10(%rsp), %rdi
callq 0x1f4be
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq