diff --git a/src/optimize_machine.ml b/src/optimize_machine.ml
index 1570478327851b7295b164677405c8b3ca678a22..60e6137299c6cc701283186525d34932be501363 100644
--- a/src/optimize_machine.ml
+++ b/src/optimize_machine.ml
@@ -1015,20 +1015,18 @@ let add_ghost_assigns_reassigned rasg instrs =
   in
   List.rev instrs
 
-(* we build a map v -> (ns, k, ks) where
+(* we build a map v -> (ns, k, b) where
  * v is an assigned var,
  * ns the set of locations where it is written originally in SSA,
  * k the equation index where it is originally written,
- * and ks the equation indexes where it is written (rewritten) *)
+ * b if there is a rewrite *)
 let add_assigned n k v =
   VMap.update v (function
-      | Some (ns, k', ks) as b ->
-        let km = IntS.max_elt ks in
-        if k = k' then Some (IntS.add n ns, k', ks)
-        else if k > km then Some (ns, k', IntS.add k ks)
-        else b
+      | Some (ns, k', b) ->
+        if k = k' then Some (IntS.add n ns, k', b)
+        else Some (ns, k', b || k > k')
       | None ->
-        Some (IntS.singleton n, k, IntS.singleton k))
+        Some (IntS.singleton n, k, false))
 
 let silly_asg i v =
   match v.value_desc with Var w -> w.var_id = i.var_id | _ -> false
@@ -1105,7 +1103,7 @@ let step_replace_var m reuse step =
   let asg = assigned asg step_instrs in
   let rasg =
     VMap.filter_map
-      (fun _ (ns, _, ks) -> if IntS.cardinal ks > 1 then Some ns else None)
+      (fun _ (ns, _, b) -> if b then Some ns else None)
       asg
   in
   (* Format.printf "APRES %a@." (VMap.pp pp) asg; *)