After some trial, I found the cause of the issue: the version of clang-format installed via Homebrew.
The clang-format installed through brew:
brew install clang-format
which is located at /opt/homebrew/bin/clang-format.
For some reason, this version of clang-format has problems with formatting both .c and .h files.
To resolve this, using clang-format via LLVM instead:
brew install llvm
Then, update the clang-format path to the newly installed version: /opt/homebrew/opt/llvm/bin/clang-format
This fixed the issue.