Most of the preparation here is involved in convolving the environment map. The following pseudocode outlines this process:
nSamples = 1000
foreach texel t in output map
n = direction towards t
rad = 0
for i = 1 to nSamples
li = uniform random direction in the
hemisphere around n in world coords
L = read from environment map at li
nDotL = dot( n, li )
rad += L * nDotL
set texel t to (2 / nSamples) * rad