generating LLVM code that meets the C ABI

I want to generate LLVM functions that meet the C ABI for function
calls/returns (preferably on multiple platforms but x86_64 would be OK
for now).
I know that LLVM doesn't handle this completely automatically (e.g.
the type {i32,i32} should be passed as a single i64 on x86_64 linux).
Is there any library that automates the generation of function
declarations meeting the ABI and emit marshalling/demarshalling code
from LLVM's types?
I would imagine that Clang needs to do this internally, where does
this code live?

Thanks for your help!