// File: /workspace/github_c_makefile_star2_O1/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
movl %r9d, %r12d
movq %r8, 0x48(%rsp)
movq %rcx, %r15
movq %rdi, 0x28(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
testl %r9d, %r9d
je 0x196a5
leaq 0x60(%rsp), %r14
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1f410
movq (%r14), %rsi
testq %rsi, %rsi
je 0x196b4
leaq 0x16edc(%rip), %rdi     # 0x3056b
xorl %eax, %eax
callq 0xd954
movq 0x60(%rsp), %rdi
callq 0xd090
jmp 0x1980b
movq %r15, %rdi
callq 0xd210
movq %rax, 0x20(%rsp)
jmp 0x196bd
movq $0x0, 0x20(%rsp)
leaq 0xc0(%rsp), %rax
leaq 0xb0(%rsp), %rcx
movq (%rcx), %rbp
movq 0x8(%rcx), %r14
movq (%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x1c(%rsp)
testb %r12b, %r12b
je 0x1971d
movq 0x30(%rsp), %r8
leaq 0x60(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0xe990
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
jmp 0x197ea
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r15, %rbx
movq %r15, %rcx
callq 0xe6f1
testq %rax, %rax
js 0x19757
movq %rax, %r15
movq %rdx, %r13
movq %rax, %rdi
movq %rdx, %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0xedfb
testb %al, %al
je 0x1975e
xorl %eax, %eax
jmp 0x197e7
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
movzbl 0x1c(%rsp), %r9d
andl $0x1, %r9d
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0xfc21
movq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xd640
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r13, %rcx
leaq 0x38(%rsp), %r8
movl $0x1, %r9d
callq 0xfa43
movq %r14, %rdi
callq 0xe485
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0xeffa
movq %rax, %rbp
movq %rdx, %r14
movb $0x1, %al
movb $0x1, %cl
movl %ecx, 0x1c(%rsp)
movq %rbx, %r15
testb %al, %al
jne 0x196ed
leaq 0xb0(%rsp), %rax
movq %r14, 0x8(%rax)
movq %rbp, (%rax)
movq 0x30(%rsp), %rdi
callq 0x1f52e
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq