anchor.diff:  trim([], _, Acc) ->
       reverse(Acc).
   
  -%% trim_instructions([{kill,R}|{live,R}|{dead,R}]) -> {[Instruction],MapFun}
  -%%  Figure out the sequence of moves and trim to use.
  -
  -trim_instructions(Layout) ->
  +%% trim_recipes([{kill,R}|{live,R}|{dead,R}]) -> [Recipe].
  +%%      Recipe = {Kills,NumberToTrim,Moves}
  +%%      Kills = [{kill,Y}]
  +%%      Moves = [{move,SrcY,DstY}]
  +%%
  +%%  Calculate how to best trim the stack and kill the correct
  +%%  Y registers. Return a list of possible recipes. The best
  +%%  recipe (the one that trims the most) is first in the list.
  +%%  All of the recipes are no worse in estimated execution time
  +%%  than the original sequences of kill instructions.
  +
  +trim_recipes(Layout) ->
       Cost = length([I || {kill,_}=I <- Layout]),
  -    trim_instructions_1(Layout, 0, [], {Cost,[]}).
  -
  -trim_instructions_1([{kill,{y,Trim0}}|Ks], Trim0, Moves, Config0) ->
  +    trim_recipes_1(Layout, 0, [], {Cost,[]}).
  +
  +trim_recipes_1([{kill,{y,Trim0}}|Ks], Trim0, Moves, Recipes0) ->
       Trim = Trim0 + 1,
  -    Config = save_config(Ks, Trim, Moves, Config0),
  -    trim_instructions_1(Ks, Trim, Moves, Config);
  -trim_instructions_1([{dead,{y,Trim0}}|Ks], Trim0, Moves, Config0) ->
  +    Recipes = save_recipe(Ks, Trim, Moves, Recipes0),
  +    trim_recipes_1(Ks, Trim, Moves, Recipes);
  +trim_recipes_1([{dead,{y,Trim0}}|Ks], Trim0, Moves, Recipes0) ->
       Trim = Trim0 + 1,
  -    Config = save_config(Ks, Trim, Moves, Config0),
  -    trim_instructions_1(Ks, Trim, Moves, Config);
  -trim_instructions_1([{live,{y,Trim0}=Src}|Ks0], Trim0, Moves0, Config0) ->
  +    Recipes = save_recipe(Ks, Trim, Moves, Recipes0),
  +    trim_recipes_1(Ks, Trim, Moves, Recipes);
  +trim_recipes_1([{live,{y,Trim0}=Src}|Ks0], Trim0, Moves0, Recipes0) ->
       case take_last_dead(Ks0) of
   	none ->
  -	    {_,ConfigList} = Config0,
  -	    ConfigList;
  +            {_,RecipesList} = Recipes0,
  +            RecipesList;
   	{Dst,Ks} ->
   	    Trim = Trim0 + 1,
   	    Moves = [{move,Src,Dst}|Moves0],
  -	    Config = save_config(Ks, Trim, Moves, Config0),
  -	    trim_instructions_1(Ks, Trim, Moves, Config)
  -    end;
  -trim_instructions_1([], _, _, {_,ConfigList}) ->
  -    ConfigList.
  +            Recipes = save_recipe(Ks, Trim, Moves, Recipes0),
  +            trim_recipes_1(Ks, Trim, Moves, Recipes)
  +    end;
  +trim_recipes_1([], _, _, {_,RecipesList}) ->
  +    RecipesList.
   
   take_last_dead(L) ->
       take_last_dead_1(reverse(L)).
  
positive.code:     {Reg,reverse(Is)};
  take_last_dead_1(_) -> none.
  
  save_config(Ks, Trim, Moves, {MaxCost,Acc}=Config) ->
      case config_cost(Ks, Moves) of
  	Cost when Cost =< MaxCost ->
  	    {MaxCost,[{Ks,Trim,Moves}|Acc]};
  	_Cost ->
  	    Config
      end.
  
  config_cost(Ks, Moves) ->
      %% We estimate that a {move,{y,_},{y,_}} instruction is roughly twice as
      %% expensive as a {kill,{y,_}} instruction. A {trim,_} instruction is
      %% roughly as expensive as a {kill,{y,_}} instruction.
  
      config_cost_1(Ks, 1+2*length(Moves)).
  
  config_cost_1([{kill,_}|Ks], Cost) ->
      config_cost_1(Ks, Cost+1);
  config_cost_1([_|Ks], Cost) ->
      config_cost_1(Ks, Cost);
  config_cost_1([], Cost) -> Cost.
  
  expand_config({Layout,Trim,Moves}, FrameSize) ->
      Kills = [Kill || {kill,_}=Kill <- Layout],
      {Kills++reverse(Moves, [{trim,Trim,FrameSize-Trim}]),create_map(Trim, Moves)}.
  
  
negative.code:        (Any) -> Any
      end.
  
  remap([{block,Bl0}|Is], Map, Acc) ->
      Bl = remap_block(Bl0, Map, []),
      remap(Is, Map, [{block,Bl}|Acc]);
  