// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %r8, %r14
movq %rcx, %rbp
movq %rdi, %rbx
movq %rsi, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
andq $0x0, 0x18(%rsp)
movl %r9d, 0x24(%rsp)
testl %r9d, %r9d
je 0x18597
leaq 0x60(%rsp), %r15
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1d614
movq (%r15), %rsi
testq %rsi, %rsi
je 0x185a6
leaq 0x13fe7(%rip), %rdi     # 0x2c568
xorl %eax, %eax
callq 0xd8e5
movq 0x60(%rsp), %rdi
callq 0xd090
jmp 0x186cb
movq %rbp, %rdi
callq 0xd210
movq %rax, 0x28(%rsp)
jmp 0x185af
movq $0x0, 0x28(%rsp)
leaq 0xc0(%rsp), %rax
leaq 0xb0(%rsp), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
movq (%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq %rdx, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
cmpb $0x0, 0x24(%rsp)
jne 0x186a5
movq %rbx, %rdi
movq %rbp, %r12
movq %rbp, %rcx
callq 0xe5e7
testq %rax, %rax
js 0x186c1
movq %rax, %rbp
movq %rdx, %r15
movq %rax, %rdi
movq %rdx, %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0xea69
testb %al, %al
jne 0x186c1
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movzbl %r13b, %r9d
andl $0x1, %r9d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %r13
movq %r13, %r8
callq 0xf77c
movq %r14, %rdi
callq 0xd640
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %r13, %r8
pushq $0x1
popq %r9
callq 0xf5c8
movq %r14, %rdi
callq 0xe38c
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0xec3a
movq %rax, %rsi
movb $0x1, %r13b
movq %r12, %rbp
jmp 0x185e4
movq 0x18(%rsp), %r8
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0xe797
movq 0x18(%rsp), %rdi
callq 0x1d726
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq