anchor.diff:  %%  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_recipes(Layout, IsNotRecursive) ->
  +    Recipes = construct_recipes(Layout, 0, [], []),
  +    NumOrigKills = length([I || {kill,_}=I <- Layout]),
  +    IsTooExpensive = is_too_expensive_fun(IsNotRecursive),
  +    [R || R <- Recipes,
  +          not is_too_expensive(R, NumOrigKills, IsTooExpensive)].
  +
  +construct_recipes([{kill,{y,Trim0}}|Ks], Trim0, Moves, Acc) ->
       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) ->
  +    Recipe = {Ks,Trim,Moves},
  +    construct_recipes(Ks, Trim, Moves, [Recipe|Acc]);
  +construct_recipes([{dead,{y,Trim0}}|Ks], Trim0, Moves, Acc) ->
       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) ->
  +    Recipe = {Ks,Trim,Moves},
  +    construct_recipes(Ks, Trim, Moves, [Recipe|Acc]);
  +construct_recipes([{live,{y,Trim0}=Src}|Ks0], Trim0, Moves0, Acc) ->
       case take_last_dead(Ks0) of
   	none ->
  -            {_,RecipesList} = Recipes0,
  -            RecipesList;
  +            %% No more recipes are possible.
  +            Acc;
   	{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.
  +            Recipe = {Ks,Trim,Moves},
  +            construct_recipes(Ks, Trim, Moves, [Recipe|Acc])
  +    end;
  +construct_recipes([], _, _, Acc) -> Acc.
   
   take_last_dead(L) ->
       take_last_dead_1(reverse(L)).
  
positive.code:         %% 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
  
negative.code: trim([], _, Acc) ->
      reverse(Acc).
  
  %% is_not_recursive([Instruction]) -> true|false.
  %%  Test whether the next call or apply instruction may
  %%  do a recursive call. Return `true` if the call is
  %%  definitely not recursive, and `false` otherwise.
  is_not_recursive([{call_ext,_,Ext}|_]) ->
      case Ext of
          {extfunc,M,F,A} ->
              erl_bifs:is_pure(M, F, A);
          _ ->
              false
      end;
  is_not_recursive([{block,_}|Is]) -> is_not_recursive(Is);
  is_not_recursive([{line,_}|Is]) -> is_not_recursive(Is);
  is_not_recursive(_) -> false.
  
  %% trim_recipes([{kill,R}|{live,R}|{dead,R}]) -> [Recipe].
  %%      Recipe = {Kills,NumberToTrim,Moves}
  %%      Kills = [{kill,Y}]
  