Optimized generation of hardware from source programs with multiplications