Fix -O3 optimization errors

Possibly uninitialized variables.
Array subscripts above/below bounds.

Signed-off-by: Zhao Wei Liew <zhaoweiliew@gmail.com>