--- ~codeopt.c        Wed Jan  1 23:55:25 2003
+++ codeopt.c        Thu Jan  2 00:23:18 2003
@@ -202,138 +202,141 @@
 
 
 
     /* Not found */
     return 0;
 }
 
 
 
 static unsigned OptPtrStore1 (CodeSeg* S)
 /* Search for the sequence:
  *
  *            jsr           pushax
  *      ldy     xxx
  *      jsr     ldauidx
  *      subop
  *      ldy     yyy
  *          jsr           staspidx
  *
  * and replace it by:
  *
  *      sta     ptr1
  *      stx     ptr1+1
  *      ldy     xxx
  *      ldx     #$00
  *      lda     (ptr1),y
  *        subop
  *      ldy     yyy
  *      sta     (ptr1),y
  */
 {
     unsigned Changes = 0;
 
     /* Walk over the entries */
     unsigned I = 0;
     while (I < CS_GetEntryCount (S)) {
 
         unsigned K;
              CodeEntry* L[10];
 
               /* Get next entry */
                L[0] = CS_GetEntry (S, I);
 
              /* Check for the sequence */
                if (CE_IsCall (L[0], "pushax")              &&
                    CS_GetEntries (S, L+1, I+1, 3)                 &&
                    L[1]->OPC == OP65_LDY                          &&
                  CE_KnownImm (L[1])                      &&
                  !CE_HasLabel (L[1])                                 &&
                    CE_IsCall (L[2], "ldauidx")             &&
                  !CE_HasLabel (L[2])                     &&
                    (K = OptPtrStore1Sub (S, I+3, L+3)) > 0 &&
             CS_GetEntries (S, L+3+K, I+3+K, 2)      &&
                    L[3+K]->OPC == OP65_LDY                 &&
                  CE_KnownImm (L[3+K])                    &&
             !CE_HasLabel (L[3+K])                   &&
             CE_IsCall (L[4+K], "staspidx")          &&
             !CE_HasLabel (L[4+K])) {
 
             CodeEntry* X;
+            LineInfo* SavedLI;
 
             /* Create and insert the stores */
                    X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
             CS_InsertEntry (S, X, I+1);
 
             X = NewCodeEntry (OP65_STX, AM65_ZP, "ptr1+1", 0, L[0]->LI);
             CS_InsertEntry (S, X, I+2);
 
             /* Delete the call to pushax */
             CS_DelEntry (S, I);
 
             /* Delete the call to ldauidx */
+            SavedLI = L[2]->LI;
+            UseLineInfo (SavedLI);
             CS_DelEntry (S, I+3);
 
             /* Insert the load from ptr1 */
             X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
             CS_InsertEntry (S, X, I+3);
-            X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[2]->LI);
+            X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, SavedLI);
             CS_InsertEntry (S, X, I+4);
 
             /* Insert the store through ptr1 */
             X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "ptr1", 0, L[3]->LI);
             CS_InsertEntry (S, X, I+6+K);
 
             /* Delete the call to staspidx */
             CS_DelEntry (S, I+7+K);
 
             /* Remember, we had changes */
             ++Changes;
 
         }
 
         /* Next entry */
         ++I;
 
     }
 
     /* Return the number of changes made */
     return Changes;
 }
 
 
 
 static unsigned OptPtrStore2 (CodeSeg* S)
 /* Search for the sequence:
  *
  *            jsr           pushax
  *      lda     xxx
  *      ldy     yyy
  *          jsr           staspidx
  *
  * and replace it by:
  *
  *      sta     ptr1
  *      stx     ptr1+1
  *      lda     xxx
  *      ldy     yyy
  *      sta     (ptr1),y
  */
 {
     unsigned Changes = 0;
 
     /* Walk over the entries */
     unsigned I = 0;
     while (I < CS_GetEntryCount (S)) {
 
         CodeEntry* L[4];
 
               /* Get next entry */
                L[0] = CS_GetEntry (S, I);
 
              /* Check for the sequence */
                if (CE_IsCall (L[0], "pushax")          &&
                    CS_GetEntries (S, L+1, I+1, 3)           &&
                    L[1]->OPC == OP65_LDA                      &&
             !CE_HasLabel (L[1])                           &&
             L[2]->OPC == OP65_LDY               &&
             !CE_HasLabel (L[2])                 &&
@@ -571,131 +574,134 @@
 
 
 static unsigned OptPtrLoad3 (CodeSeg* S)
 /* Search for the sequence:
  *
  *      adc            xxx
  *      pha
  *      txa
  *      iny
  *      adc     yyy
  *      tax
  *      pla
  *      ldy
  *          jsr            ldauidx
  *
  * and replace it by:
  *
  *      adc            xxx
  *      sta     ptr1
  *      txa
  *      iny
  *      adc     yyy
  *      sta     ptr1+1
  *      ldy
  *             ldx     #$00
  *      lda     (ptr1),y
  */
 {
     unsigned Changes = 0;
 
     /* Walk over the entries */
     unsigned I = 0;
     while (I < CS_GetEntryCount (S)) {
 
         CodeEntry* L[9];
 
               /* Get next entry */
                L[0] = CS_GetEntry (S, I);
 
              /* Check for the sequence */
                if (L[0]->OPC == OP65_ADC                             &&
                    CS_GetEntries (S, L+1, I+1, 8)             &&
                    L[1]->OPC == OP65_PHA                      &&
             !CE_HasLabel (L[1])                               &&
             L[2]->OPC == OP65_TXA               &&
             !CE_HasLabel (L[2])                 &&
             L[3]->OPC == OP65_INY               &&
             !CE_HasLabel (L[3])                 &&
                    L[4]->OPC == OP65_ADC               &&
             !CE_HasLabel (L[4])                 &&
             L[5]->OPC == OP65_TAX               &&
             !CE_HasLabel (L[5])                 &&
             L[6]->OPC == OP65_PLA               &&
             !CE_HasLabel (L[6])                 &&
             L[7]->OPC == OP65_LDY               &&
             !CE_HasLabel (L[7])                 &&
                    CE_IsCall (L[8], "ldauidx")         &&
             !CE_HasLabel (L[8])) {
 
             CodeEntry* X;
+            LineInfo* SavedLI;
 
                    /* Store the low byte and remove the PHA instead */
             X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
             CS_InsertEntry (S, X, I+1);
             CS_DelEntry (S, I+2);
 
             /* Store the high byte */
             X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1+1", 0, L[4]->LI);
             CS_InsertEntry (S, X, I+5);
 
             /* Delete more transfer and PLA insns */
+            SavedLI = L[6]->LI;
+            UseLineInfo (SavedLI);
             CS_DelEntry (S, I+7);
             CS_DelEntry (S, I+6);
 
             /* Delete the call to ldauidx */
             CS_DelEntry (S, I+7);
 
             /* Load high and low byte */
             X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[6]->LI);
             CS_InsertEntry (S, X, I+7);
             X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[6]->LI);
             CS_InsertEntry (S, X, I+8);
 
             /* Remember, we had changes */
             ++Changes;
 
         }
 
         /* Next entry */
         ++I;
 
     }
 
     /* Return the number of changes made */
     return Changes;
 }
 
 
 
 static unsigned OptPtrLoad4 (CodeSeg* S)
 /* Search for the sequence:
  *
  *      lda     #<(label+0)
  *      ldx     #>(label+0)
  *      clc
  *      adc     xxx
  *      bcc     L
  *      inx
  * L:   ldy     #$00
  *      jsr     ldauidx
  *
  * and replace it by:
  *
  *      ldy     xxx
  *      ldx     #$00
  *      lda     label,y
  */
 {
     unsigned Changes = 0;
 
     /* Walk over the entries */
     unsigned I = 0;
     while (I < CS_GetEntryCount (S)) {
 
         CodeEntry* L[8];
         unsigned Len;
 
               /* Get next entry */
                L[0] = CS_GetEntry (S, I);
 
              /* Check for the sequence */