let rec ptr_reference x n calls = 
  let s = "[ptr_reference arg]" in 
  match calls with 
    | [] ->  
        debug "%s %a: arity %d ok" s pp_var_type x n;
        oracle "%s %a ArgPref"  s pp_var_type x;
        ArgPReference.replace x (n,[])
    | (k,(b,Prop))::m -> 
        let sb = string_addr b in 
        debug "%s (%a,%d) used builtin %d and %s" s pp_var_type x n k sb;
        if k <= n then 
          ( debug "%s builtin arity OK" s; decr_addr_taken_bool x b ;
            ptr_reference x n m)
        else 
          (debug "%s builtin arity KO" s; remove_ptr_reference_arg x)
    | (k,(b,p))::m ->
        let sb = string_addr b in 
        debug "%s (%a %d) ; used as (%a,%d) and %s"
          s pp_var_type x n  pp_var_type p k sb;
        if k > n then 
          (debug "%s %a:arity KO " s pp_var_type p;
           remove_ptr_reference_arg x) 
        else
          try (match ByPReference.find p with 
                 | (i,[]) ->
                     debug "%s %a is byPref resolved" s pp_var_type p;
                     if k <= i then 
                       ( debug "%s arity OK" s; decr_addr_taken_bool x b;
                         ptr_reference x n m) 
                     else (debug "%s arity KO" s; remove_ptr_reference_arg x) 
                 | (i,lp) -> (* can't happen *) 
                     debug "%s %a is byPref NOT resolved"s pp_var_type p;
                     if k <= i then 
                       ( debug "%s arity OK"s ;by_ptr_reference p i lp; 
                         debug "%s resolution of %a" s pp_var_type p;
                         ptr_reference x n ((k,(b,p))::m))
                     else 
                       (debug "%s arity KO" s; remove_ptr_reference_arg x )
            )
        with Not_found -> (* can't happen *) 
          debug "%s %a NOT ByPRef" s pp_var_type p;
          let i = stars_var_type_typ p in  
          add_ptr_reference_param p i;
          if not (ByPReference.mem p) || ByValue.mem p
          then remove_ptr_reference_arg x
          else ptr_reference x n ((k,(b,p))::m)