anchor.diff:  %% 
   -module(refac_inc_sim_code).
   
  --export([inc_sim_code_detection/7]).
  -
  --compile(export_all).
  +-export([inc_sim_code_detection/8]).
   
   -include("../include/wrangler.hrl").
   
  --include_lib("stdlib/include/ms_transform.hrl").
  -
   -define(DefaultSimiScore, 0.8).
   
   -define(DEFAULT_LEN, 5).
  --define(DEFAULT_TOK, 20).
  +-define(DEFAULT_TOKS, 20).
   -define(DEFAULT_FREQ, 2).
   -define(DEFAULT_SIMI_SCORE, 0.8).
  +-define(DEFAULT_NEW_VARS, 5).
   
   -define(ASTTab, list_to_atom(filename:join(?WRANGLER_DIR, "plt/ast_tab"))).
   -define(FileHashTab, list_to_atom(filename:join(?WRANGLER_DIR, "plt/file_hash_tab"))).
  
positive.code:     end.
   
  %%=============================================================================
  examine_clone_candidates([], _MinLen, _MinFreq, _SimiScore, ASTTab, _VarTab, Pid, _Num) ->
      get_final_clone_classes(Pid, ASTTab);
  examine_clone_candidates([C| Cs], MinLen, MinFreq, SimiScore, ASTTab, VarTab, Pid, Num) ->
      ?wrangler_io("\nChecking the ~pth clone candidate...", [Num]),
      case examine_a_clone_candidate(C, MinLen, MinFreq, SimiScore, ASTTab, VarTab) of
  	[] ->
  	    ok;
  	Clones ->
  	    ClonesWithAntiUnifier=[{Ranges, {Len, Freq}, get_anti_unifier(ASTTab, Info)}
  				   ||{Ranges, {Len, Freq}, Info}<-Clones],
  	    add_new_clones(Pid, ClonesWithAntiUnifier)
      end,
      examine_clone_candidates(Cs, MinLen, MinFreq, SimiScore, ASTTab, VarTab, Pid, Num + 1).
  
  examine_a_clone_candidate(C, MinLen, MinFreq, SimiScore, ASTTab, VarTab) ->
      {Ranges, {_Len, _Freq}} = C,
      examine_clone_class_members(Ranges, C, MinLen, MinFreq, SimiScore, ASTTab, VarTab, []).
    
  examine_clone_class_members([], _, _, _, _, _,_, Acc) ->
      remove_sub_clones(lists:keysort(2, Acc));
  examine_clone_class_members([Range1| Rs], _C = {Ranges, {Len, Freq}}, MinLen, MinFreq, SimiScore, ASTTab, VarTab, Acc) ->
      {Exprs1, _VarsToExport} = get_expr_list_and_vars_to_export(Range1, ASTTab, VarTab),
      %% refac_io:format("Rs:\n~p\n", [Rs]),
      Res = lists:map(fun (Range2) ->
  		       case Range2 == Range1 of
  			   true ->  [];
  			   _ ->
  			       %% refac_io:format("Range2:\n~p\n", [Range2]),
  			       {Exprs2, _VarsToExport2} = get_expr_list_and_vars_to_export(Range2, ASTTab, VarTab),
  			       do_anti_unification({Range1, Exprs1}, {Range2, Exprs2})
  		       end
  	       end, Rs),
      Length=length(Range1),
      Clones=process_au_result(Res, Length, MinLen, MinFreq, SimiScore, ASTTab, VarTab,[]),
      case Clones==[] orelse element(1, element(2, (hd(Clones))))/=Length of
  	true ->
    	    RemainedRanges=Ranges--[Range1],
  	    case length(RemainedRanges)>=MinFreq of 
  		true ->
  		    %% refac_io:format("RemainedRanges:\n~p\n",[RemainedRanges]),
  		    examine_clone_class_members(Rs, {RemainedRanges, {Len, Freq}}, MinLen,
  						MinFreq, SimiScore, ASTTab, VarTab, Clones++Acc);
  		false ->
  		    Clones++Acc
  	    end;
  	false->
  	    Rs1 = element(1, hd(Clones)),
  	    RemainedRanges=Ranges--Rs1,
  	    case length(RemainedRanges)>=MinFreq of
  		true ->
  		    %% refac_io:format("RemainedRanges1:\n~p\n",[RemainedRanges]),
  		    examine_clone_class_members(Rs -- Rs1, {RemainedRanges, {Len, Freq}}, MinLen, 
  						MinFreq, SimiScore, ASTTab, VarTab, Clones++Acc);
  		false ->
  		    Clones++Acc
  	    end			
      end.
      
  
  process_au_result(_AURes, CurLen, MinLen, _MinFreq, _SimiScore, _ASTTab, _VarTab, Acc)
    when CurLen<MinLen ->
      Res =lists:reverse(remove_sub_clones(lists:keysort(2, Acc))),
      Res;
  process_au_result(AURes, CurLen, MinLen, MinFreq, SimiScore, ASTTab, VarTab, Acc) ->
      AUSubReses=sub_list(AURes, CurLen),
      Clones=lists:append([process_a_sub_au_result(AUSubRes, MinFreq, SimiScore, ASTTab, VarTab)||AUSubRes<-AUSubReses]),
      case Clones/=[] andalso length(element(1,hd(Clones)))== length(AURes)+1 of
  	true -> 
  	    TotalLen=length(hd(AURes)),
  	    %% refac_io:format("CurLen:\n~p\n", [CurLen]),
  	    %% case TotalLen-CurLen<CurLen of
  	    %% 	true ->
  	    %% 	    process_au_result(AURes, TotalLen-CurLen,MinLen, MinFreq, SimiScore, ASTTab, VarTab, Clones++Acc);
  	    %% 	false ->
  	    process_au_result(AURes, MinLen-1,MinLen, MinFreq, SimiScore, ASTTab, VarTab, Clones++Acc);
  	    %%end;		    
  	false ->
  	    process_au_result(AURes, CurLen-1,MinLen, MinFreq, SimiScore, ASTTab, VarTab, Clones++Acc)
      end.
      
  process_a_sub_au_result(Res, MinFreq,SimiScore, ASTTab, VarTab) ->
      {Range, _, _}=lists:unzip3(hd(Res)),
      {_, VarsToExport} = get_expr_list_and_vars_to_export(Range, ASTTab, VarTab),			       
      NewRes=lists:append([process_a_sub_au_result_1(R, SimiScore, ASTTab, VarTab)||R<-Res]),
      case length(NewRes)< MinFreq-1 of
  	true->[];
  	_ ->
  	    {Ranges, ExportVars, SubSt} = lists:unzip3(NewRes),
  	    ExportVars1 = {element(1, lists:unzip(VarsToExport)), lists:usort(lists:append(ExportVars))},
  	    [{[Range| Ranges], {length(hd(Res)), length(Ranges) + 1}, {Range,SubSt, ExportVars1}}]
      end.
      
      
  process_a_sub_au_result_1(AURes, SimiScore, ASTTab, VarTab) ->
      {Range1, Range2, Subst} = lists:unzip3(AURes),
     %% refac_io:format("R1R2S:\n~p\n", [{Range1, Range2, Subst}]),
      {Exprs1, _VarsToExport1} = get_expr_list_and_vars_to_export(Range1, ASTTab, VarTab),
      {Exprs2, VarsToExport2} = get_expr_list_and_vars_to_export(Range2, ASTTab, VarTab),
      case lists:member(none, Subst) of
  	true ->
  	    %% refac_io:format("Subst:\n~p\n", [Subst]),
  	    [];
  	false ->
  	    Subst1=lists:append(Subst),
  	    {SubExprs1, SubExprs2}=lists:unzip(Subst1),
  	    %% refac_io:format("SubExprs2::\n~p\n", [SubExprs2]),
  	    %% refac_io:format("Exprs1:~p\n", [Exprs1]),
  	    Score1 = simi_score(Exprs1, SubExprs1),
  	    Score2 = simi_score(Exprs2, SubExprs2),
  	    %% refac_io:format("Score1:\n~p\n", [Score1]),
  	    %% refac_io:format("Score2:\n~p\n", [Score2]),
  	    case Score1 >= SimiScore andalso Score2 >= SimiScore of
  		true ->
  		    case anti_unification:subst_sanity_check(Exprs1, Subst1) of
  			false ->
  			    [];
  			_ ->
  			    EVs = [E1 || {E1, E2} <- Subst1, refac_syntax:type(E2) == variable,
  					 lists:member({refac_syntax:variable_name(E2), get_var_define_pos(E2)}, 
  						      VarsToExport2)],
  			    [{Range2, EVs, Subst1}]
  		    end;
  		_ -> []
  	    end
      end.
  
  do_anti_unification({Range1,Exprs1}, {Range2, Exprs2}) ->
      %% refac_io:format("Range1 Range2:\n~p\n", [{Range1, Range2}]),
      ZippedExprs1=lists:zip(Range1, Exprs1),
      ZippedExprs2=lists:zip(Range2, Exprs2),
      ZippedExprs=lists:zip(ZippedExprs1, ZippedExprs2),
      [begin
  	 %% refac_io:format("Index1, Index2:\n~p\n", [{Index1, Index2}]),
  	 %% refac_io:format("anti_unification:\n~p\n", [ anti_unification:anti_unification(E1,E2)]),
  	 {Index1, Index2,
  	  anti_unification:anti_unification(E1,E2)}
       end|| {{Index1,E1}, {Index2, E2}}<-ZippedExprs].
      
  remove_sub_clones(Cs) ->
      remove_sub_clones(lists:reverse(Cs),[]).
  remove_sub_clones([], Acc_Cs) ->
      lists:reverse(Acc_Cs);
  remove_sub_clones([C|Cs], Acc_Cs) ->
  
negative.code: 	false ->remove_sub_clones(Cs, [C|Acc_Cs])
      end.
  
  is_sub_clone({Ranges, {Len, Freq},Str,AbsRanges}, ExistingClones) ->
      case ExistingClones of 
  	[] -> false;
  	[{Ranges1, {_Len1, _Freq1}, _, _AbsRanges1}|T] ->
  	    case is_sub_ranges(Ranges, Ranges1) of 
  		true -> 
  		    true;
  		false -> is_sub_clone({Ranges, {Len, Freq},Str, AbsRanges}, T)
  	    end
  	end;
  
  is_sub_clone({Ranges, {Len, Freq},Str}, ExistingClones) ->
      case ExistingClones of 
  	[] -> false;
  	[{Ranges1, {_Len1, _Freq1}, _}|T] ->
  	    case is_sub_ranges(Ranges, Ranges1) of 
  		true -> 
  		    true;
  		false -> is_sub_clone({Ranges, {Len, Freq},Str}, T)
  	    end
      end;
  is_sub_clone({Ranges, {Len, Freq}}, ExistingClones) ->
      case ExistingClones of 
  	[] -> false;
  	[{Ranges1, {_Len1, _Freq1}}|T] ->
  	    case is_sub_ranges(Ranges, Ranges1) of 
  		true -> 
  		    true;
  		false -> is_sub_clone({Ranges, {Len, Freq}}, T)
  	    end
      end.
  
  is_sub_ranges(Ranges1, Ranges2) ->
      lists:all(fun (R1)  -> 
  		      lists:any(fun (R2) ->
  