+unsigned OptTest2 (CodeSeg* S)
+/* Search for an inc/dec operation followed by a load and a conditional
+ * branch based on the flags from the load. Remove the load if the insn
+ * isn't used later.
+ */
+{
+ unsigned Changes = 0;
+
+ /* Walk over the entries */
+ unsigned I = 0;
+ while (I < CS_GetEntryCount (S)) {
+
+ CodeEntry* L[3];
+
+ /* Get next entry */
+ L[0] = CS_GetEntry (S, I);
+
+ /* Check if it's the sequence we're searching for */
+ if ((L[0]->OPC == OP65_INC || L[0]->OPC == OP65_DEC) &&
+ CS_GetEntries (S, L+1, I+1, 2) &&
+ !CE_HasLabel (L[1]) &&
+ (L[1]->Info & OF_LOAD) != 0 &&
+ (L[2]->Info & OF_FBRA) != 0 &&
+ L[1]->AM == L[0]->AM &&
+ strcmp (L[0]->Arg, L[1]->Arg) == 0 &&
+ (GetRegInfo (S, I+2, L[1]->Chg) & L[1]->Chg) == 0) {
+
+ printf ("Deleting\n");
+
+ /* Remove the load */
+ CS_DelEntry (S, I+1);
+ ++Changes;
+ }
+
+ /* Next entry */
+ ++I;
+
+ }
+
+ /* Return the number of changes made */
+ return Changes;
+}
+
+
+