Fix LLVM analyzer warnings and bugs