Program: 150091
Project: 150091
Buggy source:
public char[] format_long(long value) throws UninterruptiblePragma {
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
  }
  int i;
  for (i=0; i < MAX_LONG_LENGTH; i++) {
    l_buffer[i]=' ';
    f_buffer[i]=' ';
  }
  for (; i < MAX_LONG_FORMAT_LENGTH; i++) {
    f_buffer[i]=' ';
  }
  long l_value=value;
  int l_index=MAX_LONG_LENGTH - 1;
  while (l_value > 0) {
    int remainder=(int)(l_value - ((int)(l_value / 10)) * 10);
    l_buffer[l_index]=(char)((int)'0' + remainder);
    l_value=(int)(l_value / 10);
    l_index--;
  }
  int length=(MAX_LONG_LENGTH - 1) - l_index;
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_buffer,MAX_LONG_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_index);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
  }
  l_index=MAX_LONG_LENGTH - 1;
  int f_index=MAX_LONG_FORMAT_LENGTH - 1;
  while (length > 3 && l_index >= 2 && f_index >= 3) {
    f_buffer[f_index]=l_buffer[l_index];
    f_buffer[f_index - 1]=l_buffer[l_index - 1];
    f_buffer[f_index - 2]=l_buffer[l_index - 2];
    f_buffer[f_index - 3]=',';
    f_index-=4;
    l_index-=3;
    length-=3;
  }
  if (l_index < 2) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_index,MAX_LONG_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
    VM.sysExit(VM.EXIT_STATUS_HPM_TROUBLE);
  }
  if (f_index < 3) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(f_index,MAX_LONG_FORMAT_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
    VM.sysExit(VM.EXIT_STATUS_HPM_TROUBLE);
  }
  if (length > 0) {
    while (length > 0) {
      f_buffer[f_index]=l_buffer[l_index];
      f_index--;
      l_index--;
      length--;
    }
  }
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(f_buffer,MAX_LONG_FORMAT_LENGTH);
    VM.sysWrite("String_Node_Str");
  }
  return f_buffer;
}

Fixed version (ground truth):
public char[] format_long(long value) throws UninterruptiblePragma {
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
  }
  int i;
  for (i=0; i < MAX_LONG_LENGTH; i++) {
    l_buffer[i]=' ';
    f_buffer[i]=' ';
  }
  for (; i < MAX_LONG_FORMAT_LENGTH; i++) {
    f_buffer[i]=' ';
  }
  long l_value=value;
  int l_index=MAX_LONG_LENGTH - 1;
  while (l_value > 0) {
    int remainder=(int)(l_value - (l_value / 10) * 10);
    l_buffer[l_index]=(char)((int)'0' + remainder);
    l_value=l_value / 10;
    l_index--;
  }
  int length=(MAX_LONG_LENGTH - 1) - l_index;
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_buffer,MAX_LONG_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_index);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
  }
  l_index=MAX_LONG_LENGTH - 1;
  int f_index=MAX_LONG_FORMAT_LENGTH - 1;
  while (length > 3 && l_index >= 2 && f_index >= 3) {
    f_buffer[f_index]=l_buffer[l_index];
    f_buffer[f_index - 1]=l_buffer[l_index - 1];
    f_buffer[f_index - 2]=l_buffer[l_index - 2];
    f_buffer[f_index - 3]=',';
    f_index-=4;
    l_index-=3;
    length-=3;
  }
  if (l_index < 2) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(l_index,MAX_LONG_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
    VM.sysExit(VM.EXIT_STATUS_HPM_TROUBLE);
  }
  if (f_index < 3) {
    VM.sysWrite("String_Node_Str");
    VM.sysWriteLong(value);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(f_index,MAX_LONG_FORMAT_LENGTH);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(length);
    VM.sysWrite("String_Node_Str");
    VM.sysExit(VM.EXIT_STATUS_HPM_TROUBLE);
  }
  if (length > 0) {
    while (length > 0) {
      f_buffer[f_index]=l_buffer[l_index];
      f_index--;
      l_index--;
      length--;
    }
  }
  if (VM_HardwarePerformanceMonitors.verbose >= 10) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(f_buffer,MAX_LONG_FORMAT_LENGTH);
    VM.sysWrite("String_Node_Str");
  }
  return f_buffer;
}