Program: 5650
Project: 5650
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];
updateCyclesMultiplicator();
if ((data & TCLR) != 0) {
counter=0;
resetCounter(cycles);
updateCaptures(-1,cycles);
}
int newMode=(data >> 4) & 3;
if (mode == STOP && newMode != STOP) {
resetCounter(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" + "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;
boolean oldCapture=captureOn[index];
captureOn[index]=(data & 0x100) > 0;
sync[index]=(data & 0x800) > 0;
inputSel[index]=(data >> 12) & 3;
int src=inputSrc[index]=srcMap[4 + index * 4 + inputSel[index]];
capMode[index]=(data >> 14) & 3;
if (!oldCapture && captureOn[index] && (src & SRC_PORT) != 0) {
int port=(src & 0xff) >> 4;
int pin=src & 0x0f;
IOPort ioPort=core.getIOPort(port);
System.out.println(getName() + "String_Node_Str" + port+ "String_Node_Str"+ pin+ "String_Node_Str");
ioPort.setTimerCapture(this,pin);
}
updateCounter(cycles);
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;
updateCounter(cycles);
if (index == 0) {
if (counter > data && (mode == UPDWN || mode == UP)) {
counter=0;
}
resetCounter(cycles);
}
tccr[index]=data;
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 + 1) - counterPassed;
if (DEBUG && counterPassed > 0) {
System.out.println(getName() + "String_Node_Str" + counterPassed+ "String_Node_Str"+ cycles+ "String_Node_Str"+ counter+ "String_Node_Str"+ index+ "String_Node_Str"+ data+ "String_Node_Str"+ diff+ "String_Node_Str"+ cyclesMultiplicator+ "String_Node_Str"+ expCaptureTime[index]);
}
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){
  if (address == TAIV || address == TBIV) {
    resetTIV(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];
updateCyclesMultiplicator();
if ((data & TCLR) != 0) {
counter=0;
resetCounter(cycles);
updateCaptures(-1,cycles);
}
int newMode=(data >> 4) & 3;
if (mode == STOP && newMode != STOP) {
resetCounter(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" + "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;
boolean oldCapture=captureOn[index];
captureOn[index]=(data & 0x100) > 0;
sync[index]=(data & 0x800) > 0;
inputSel[index]=(data >> 12) & 3;
int src=inputSrc[index]=srcMap[4 + index * 4 + inputSel[index]];
capMode[index]=(data >> 14) & 3;
if (!oldCapture && captureOn[index] && (src & SRC_PORT) != 0) {
int port=(src & 0xff) >> 4;
int pin=src & 0x0f;
IOPort ioPort=core.getIOPort(port);
System.out.println(getName() + "String_Node_Str" + port+ "String_Node_Str"+ pin+ "String_Node_Str");
ioPort.setTimerCapture(this,pin);
}
updateCounter(cycles);
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;
updateCounter(cycles);
if (index == 0) {
if (counter > data && (mode == UPDWN || mode == UP)) {
counter=0;
}
resetCounter(cycles);
}
tccr[index]=data;
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 + 1) - counterPassed;
if (DEBUG && counterPassed > 0) {
System.out.println(getName() + "String_Node_Str" + counterPassed+ "String_Node_Str"+ cycles+ "String_Node_Str"+ counter+ "String_Node_Str"+ index+ "String_Node_Str"+ data+ "String_Node_Str"+ diff+ "String_Node_Str"+ cyclesMultiplicator+ "String_Node_Str"+ expCaptureTime[index]);
}
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);
}
}