// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_app.c
// Function: ce_clang_format_selection
bool ce_clang_format_selection(char* clang_format_exe, CeView_t* view, CeVimMode_t vim_mode, CeVimVisualData_t* visual){
    CePoint_t highlight_start = {};
    CePoint_t highlight_end = {};
    if(!ce_vim_get_selection_range(vim_mode, visual, view, &highlight_start, &highlight_end)){
        return false;
    }
    // Pass clang-format the entire buffer, but tell it the offset and length to format.
    char* buffer_str = ce_buffer_dupe(view->buffer);
    int64_t buffer_str_len = ce_utf8_strlen(buffer_str);
    char command_buffer[MAX_PATH_LEN];
    snprintf(command_buffer, MAX_PATH_LEN, "%s --lines=%" PRId64 ":%" PRId64,
             clang_format_exe, highlight_start.y + 1, highlight_end.y + 1);
    ClangFormatResult_t result = _clang_format_string(command_buffer, buffer_str,
                                                      buffer_str_len);
    if(!result.success){
        return false;
    }
    int64_t result_len = ce_utf8_strlen(result.bytes);
    if(result_len <= 0){
        return false;
    }

    bool removed = ce_buffer_remove_string_change(view->buffer, (CePoint_t){0, 0}, buffer_str_len,
                                                  &view->cursor, view->cursor, false);
    if(!removed){
        ce_log("Failed to clear buffer %s to insert clang format results\n", view->buffer->name);
        free(result.bytes);
        return false;
    }
    bool inserted = ce_buffer_insert_string_change(view->buffer, result.bytes, (CePoint_t){0, 0}, &view->cursor,
                                                   view->cursor, true);
    if(!inserted){
        ce_log("Failed to insert clang format results into %s\n", view->buffer->name);
        free(result.bytes);
        return false;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %rbx
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x10(%rsp), %r8
movaps %xmm0, (%r8)
movl %edx, %edi
movq %rcx, %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x2a02d
testb %al, %al
je 0x14fa6
movq 0x40(%rbx), %rdi
callq 0xf9e0
movq %rax, %r13
movq %rax, %rdi
callq 0xe485
movq %rax, %r12
movq 0x28(%rsp), %r8
incq %r8
movq 0x18(%rsp), %r9
incq %r9
leaq 0x1af55(%rip), %rdx     # 0x2fe60
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbp
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0xd260
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x14c76
testb $0x1, %al
je 0x14fa9
movq %rdx, %r15
movq %rdx, %rdi
callq 0xe485
testq %rax, %rax
jle 0x14fa6
movq 0x40(%rbx), %rdi
leaq 0x30(%rbx), %r13
movups 0x30(%rbx), %xmm0
movups %xmm0, (%rsp)
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
movq %r12, %rcx
movq %r13, %r8
xorl %r9d, %r9d
callq 0xfc21
movq 0x40(%rbx), %rdi
testb %al, %al
je 0x14fbe
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
movl $0x1, %r9d
callq 0xfa43
movl %eax, %r14d
testb %al, %al
jne 0x14fa9
movq 0x40(%rbx), %rdi
leaq 0x1ae8d(%rip), %rax     # 0x2fe31
jmp 0x14fc5
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ae32(%rip), %rax     # 0x2fdf7
movq 0x10(%rdi), %rsi
movq %rax, %rdi
xorl %eax, %eax
callq 0xd954
movq %r15, %rdi
callq 0xd090
jmp 0x14fa9