anchor.diff:  			    end, Is0),
       Kills = sort(Kills0),
       try
  -	{FrameSize,Layout} = frame_layout(Is1, Kills, St),
  -	Configs = trim_instructions(Layout),
  -	try_remap(Configs, Is1, FrameSize)
  -	of
  +        %% Find out the size and layout of the stack frame.
  +        %% Example of a layout:
  +        %%
  +        %%    [{kill,{y,0}},{dead,{y,1},{live,{y,2}},{kill,{y,3}}]
  +        %%
  +        %% That means that y0 and y3 are to be killed, that y1
  +        %% has been killed previously, and that y2 is live.
  +        {FrameSize,Layout} = frame_layout(Is1, Kills, St),
  +
  +        %% Calculate all recipes that are not worse in terms
  +        %% of estimated execution time. The recipes are ordered
  +        %% in descending order from how much they trim.
  +        Recipes = trim_recipes(Layout),
  +
  +        %% Try the recipes in order. A recipe may not work out because
  +        %% a register that was previously killed may be
  +        %% resurrected. If that happens, the next recipe, which trims
  +        %% less, will be tried.
  +        try_remap(Recipes, Is1, FrameSize)
  +    of
   	{Is,TrimInstr} ->
  +            %% One of the recipes was applied.
   	    trim(Is, St, reverse(TrimInstr)++Acc)
       catch
   	not_possible ->
  +            %% No recipe worked out. Use the original kill
  +            %% instructions.
   	    trim(Is1, St, reverse(Kills, Acc))
       end;
   trim([I|Is], St, Acc) ->
  
positive.code:        (Any) -> Any
      end.
  
  try_remap([C|Cs], Is, FrameSize) ->
      {TrimInstr,Map} = expand_config(C, FrameSize),
      try
  	{remap(Is, Map, []),TrimInstr}
      catch
  	throw:not_possible ->
  	    try_remap(Cs, Is, FrameSize)
      end;
  try_remap([], _, _) -> throw(not_possible).
  
  remap([{block,Bl0}|Is], Map, Acc) ->
      Bl = remap_block(Bl0, Map, []),
      remap(Is, Map, [{block,Bl}|Acc]);
  
negative.code: trim([], _, Acc) ->
      reverse(Acc).
  
  %% 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_recipes_1(Layout, 0, [], {Cost,[]}).
  
  trim_recipes_1([{kill,{y,Trim0}}|Ks], Trim0, Moves, Recipes0) ->
      Trim = Trim0 + 1,
      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,
      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 ->
              {_,RecipesList} = Recipes0,
              RecipesList;
  	{Dst,Ks} ->
  	    Trim = Trim0 + 1,
  	    Moves = [{move,Src,Dst}|Moves0],
              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)).
  