Program: 5728
Project: 5728
Buggy source:
public void write(int address,int data,boolean word,long cycles){
  int iAddress=address - offset;
switch (iAddress) {
case TR:
    setCounter(data,cycles);
  break;
case TCTL:
if (DEBUG) {
  System.out.println(getName() + "String_Node_Str" + Utils.hex16(data));
}
inputDivider=1 << ((data >> 6) & 3);
clockSource=srcMap[(data >> 8) & 3];
cyclesMultiplicator=inputDivider;
if (clockSource == SRC_ACLK) {
cyclesMultiplicator=(cyclesMultiplicator * core.smclkFrq) / core.aclkFrq;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + cyclesMultiplicator);
}
}
if ((data & TCLR) != 0) {
counter=0;
counterStart=cycles;
updateCaptures(-1,cycles);
}
int newMode=(data >> 4) & 3;
if (mode == STOP && newMode != STOP) {
updateCounter(cycles);
nextTimerTrigger=(long)(cycles + cyclesMultiplicator * ((0xffff - counter) & 0xffff));
}
mode=newMode;
interruptEnable=(data & 0x02) > 0;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + name[type]+ "String_Node_Str"+ inputDivider+ "String_Node_Str"+ getSourceName(clockSource)+ "String_Node_Str"+ interruptEnable+ "String_Node_Str"+ interruptPending+ "String_Node_Str"+ mode+ ((data & TCLR) != 0 ? "String_Node_Str" : "String_Node_Str"));
}
tctl=data;
tctl&=~0x04;
if ((data & 0x01) == 0) {
interruptPending=false;
}
updateCaptures(-1,cycles);
break;
case TCCTL0:
case TCCTL1:
case TCCTL2:
case TCCTL3:
case TCCTL4:
case TCCTL5:
case TCCTL6:
int index=(iAddress - TCCTL0) / 2;
tcctl[index]=data;
outMode[index]=(data >> 5) & 7;
captureOn[index]=(data & 0x100) > 0;
sync[index]=(data & 0x800) > 0;
inputSel[index]=(data >> 12) & 3;
inputSrc[index]=srcMap[4 + index * 4 + inputSel[index]];
capMode[index]=(data >> 14) & 3;
triggerInterrupts();
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + index+ "String_Node_Str"+ Utils.hex16(data)+ "String_Node_Str"+ capNames[capMode[index]]+ "String_Node_Str"+ inputSel[index]+ "String_Node_Str"+ getSourceName(inputSrc[index])+ "String_Node_Str"+ captureOn[index]+ "String_Node_Str"+ ((data & CC_IE) != 0));
}
updateCaptures(index,cycles);
break;
case TCCR0:
case TCCR1:
case TCCR2:
case TCCR3:
case TCCR4:
case TCCR5:
case TCCR6:
index=(iAddress - TCCR0) / 2;
tccr[index]=data;
updateCounter(cycles);
int diff=data - counter;
if (diff < 0) {
diff+=0x10000;
}
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + index+ "String_Node_Str"+ Utils.hex16(data)+ "String_Node_Str"+ Utils.hex16(counter)+ "String_Node_Str"+ Utils.hex16(diff));
}
expCaptureTime[index]=cycles + (long)(cyclesMultiplicator * diff) - counterPassed;
counterPassed=0;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + cycles+ "String_Node_Str"+ index+ "String_Node_Str"+ expCaptureTime[index]+ "String_Node_Str"+ counter+ "String_Node_Str"+ data+ "String_Node_Str"+ (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + "String_Node_Str" + "String_Node_Str" + expCaptureTime[index]);
}
calculateNextEventTime(cycles);
}
}

Fixed version (ground truth):
public void write(int address,int data,boolean word,long cycles){
  int iAddress=address - offset;
switch (iAddress) {
case TR:
    setCounter(data,cycles);
  break;
case TCTL:
if (DEBUG) {
  System.out.println(getName() + "String_Node_Str" + Utils.hex16(data));
}
inputDivider=1 << ((data >> 6) & 3);
clockSource=srcMap[(data >> 8) & 3];
cyclesMultiplicator=inputDivider;
if (clockSource == SRC_ACLK) {
cyclesMultiplicator=(cyclesMultiplicator * core.smclkFrq) / core.aclkFrq;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + cyclesMultiplicator);
}
}
if ((data & TCLR) != 0) {
counter=0;
counterStart=cycles;
updateCaptures(-1,cycles);
}
int newMode=(data >> 4) & 3;
if (mode == STOP && newMode != STOP) {
initialCounter=counter;
counterStart=cycles;
nextTimerTrigger=(long)(cycles + cyclesMultiplicator * ((0xffff - counter) & 0xffff));
if (DEBUG) System.out.println(getName() + "String_Node_Str");
recalculateCompares(cycles);
}
mode=newMode;
interruptEnable=(data & 0x02) > 0;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + name[type]+ "String_Node_Str"+ inputDivider+ "String_Node_Str"+ getSourceName(clockSource)+ "String_Node_Str"+ interruptEnable+ "String_Node_Str"+ interruptPending+ "String_Node_Str"+ mode+ ((data & TCLR) != 0 ? "String_Node_Str" : "String_Node_Str"));
}
tctl=data;
tctl&=~0x04;
if ((data & 0x01) == 0) {
interruptPending=false;
}
updateCaptures(-1,cycles);
break;
case TCCTL0:
case TCCTL1:
case TCCTL2:
case TCCTL3:
case TCCTL4:
case TCCTL5:
case TCCTL6:
int index=(iAddress - TCCTL0) / 2;
tcctl[index]=data;
outMode[index]=(data >> 5) & 7;
captureOn[index]=(data & 0x100) > 0;
sync[index]=(data & 0x800) > 0;
inputSel[index]=(data >> 12) & 3;
inputSrc[index]=srcMap[4 + index * 4 + inputSel[index]];
capMode[index]=(data >> 14) & 3;
triggerInterrupts(cycles);
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + index+ "String_Node_Str"+ Utils.hex16(data)+ "String_Node_Str"+ capNames[capMode[index]]+ "String_Node_Str"+ inputSel[index]+ "String_Node_Str"+ getSourceName(inputSrc[index])+ "String_Node_Str"+ captureOn[index]+ "String_Node_Str"+ ((data & CC_IE) != 0));
}
updateCaptures(index,cycles);
break;
case TCCR0:
case TCCR1:
case TCCR2:
case TCCR3:
case TCCR4:
case TCCR5:
case TCCR6:
index=(iAddress - TCCR0) / 2;
tccr[index]=data;
updateCounter(cycles);
int diff=data - counter;
if (diff < 0) {
diff+=0x10000;
}
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + index+ "String_Node_Str"+ Utils.hex16(data)+ "String_Node_Str"+ Utils.hex16(counter)+ "String_Node_Str"+ Utils.hex16(diff));
}
expCaptureTime[index]=cycles + (long)(cyclesMultiplicator * diff) - counterPassed;
counterPassed=0;
if (DEBUG) {
System.out.println(getName() + "String_Node_Str" + cycles+ "String_Node_Str"+ index+ "String_Node_Str"+ expCaptureTime[index]+ "String_Node_Str"+ counter+ "String_Node_Str"+ data+ "String_Node_Str"+ (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + "String_Node_Str" + "String_Node_Str" + expCaptureTime[index]);
}
calculateNextEventTime(cycles);
}
}