"Automatic differentiation and second renormalization of tensor network states"