How to know what global and static variables are accessed in a function? (C)

Hi,

I'd like know what global and static variables are accessed in a
function (C code only for simplicity). It seems that LLVM IR might be
a useful format to maintain all such information. Is there a way to
analyze IR to figure what global and static variables are accessed
(read/write) in a function? Thanks.