Fix compilation errors on Windows

Related:

02fd41079565547e08e86d731582d53270a4dec5
ef7cd7e91914f20f28e0f8611b6570e6855d59c3

Motivation:

Visual C 2008 compiler requires the local variable declarations to
always appear at the beginning.  Recent commits introduces local
variables in the middle to cause the compilation errors.

Modifications:

Move the local variable declarations to the beginning of function.

Result:

Compiles OK on Windows again.