Program: 157046
Project: 157046
Buggy source:
private boolean mergeTransmutedItemStack(EntityPlayer entityPlayer,Slot transmutationOutputSlot,ItemStack itemStack,int slotMin,int slotMax,boolean ascending){
  int numCanTransmute=MathHelper.floor(this.transmutationTablet.getAvailableEnergy().getValue() / EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue());
  int numTransmuted=0;
  ItemStack itemStack1=itemStack.copy();
  itemStack1.stackSize=Math.min(numCanTransmute,itemStack1.getMaxStackSize());
  if (numCanTransmute <= 0) {
    return false;
  }
  int currentSlotIndex=ascending ? slotMax - 1 : slotMin;
  Slot slot;
  ItemStack stackInSlot;
  while (itemStack1.stackSize > 0 && (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin)) {
    slot=(Slot)this.inventorySlots.get(currentSlotIndex);
    stackInSlot=slot.getStack();
    if (stackInSlot == null) {
      stackInSlot=itemStack1.copy();
      stackInSlot.stackSize=itemStack1.stackSize;
      slot.putStack(stackInSlot);
      numTransmuted=itemStack1.stackSize;
      itemStack1.stackSize=0;
      slot.onSlotChanged();
    }
 else     if (slot.isItemValid(itemStack1) && ItemStackUtils.equalsIgnoreStackSize(itemStack1,stackInSlot)) {
      int slotStackSizeLimit=Math.min(stackInSlot.getMaxStackSize(),slot.getSlotStackLimit());
      int combinedStackSize=stackInSlot.stackSize + itemStack1.stackSize;
      if (combinedStackSize <= slotStackSizeLimit) {
        stackInSlot.stackSize=combinedStackSize;
        numTransmuted=itemStack1.stackSize;
        itemStack1.stackSize=0;
        slot.onSlotChanged();
      }
 else       if (stackInSlot.stackSize < slotStackSizeLimit) {
        itemStack1.stackSize-=slotStackSizeLimit - stackInSlot.stackSize;
        stackInSlot.stackSize=slotStackSizeLimit;
        numTransmuted=itemStack1.stackSize;
        itemStack1.stackSize=0;
        slot.onSlotChanged();
      }
    }
    currentSlotIndex+=ascending ? -1 : 1;
  }
  ((SlotTabletOutput)transmutationOutputSlot).onShiftPickupFromSlot(entityPlayer,ItemStackUtils.clone(itemStack,numTransmuted));
  return false;
}

Fixed version (ground truth):
private boolean mergeTransmutedItemStack(EntityPlayer entityPlayer,Slot transmutationOutputSlot,ItemStack itemStack,int slotMin,int slotMax,boolean ascending){
  int numCanTransmute=MathHelper.floor(this.transmutationTablet.getAvailableEnergy().getValue() / EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue());
  int numTransmuted=0;
  ItemStack itemStack1=itemStack.copy();
  itemStack1.stackSize=Math.min(numCanTransmute,itemStack1.getMaxStackSize());
  if (numCanTransmute <= 0) {
    return false;
  }
  int currentSlotIndex=ascending ? slotMax - 1 : slotMin;
  Slot slot;
  ItemStack stackInSlot;
  while (itemStack1.stackSize > 0 && (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin)) {
    slot=(Slot)this.inventorySlots.get(currentSlotIndex);
    stackInSlot=slot.getStack();
    if (stackInSlot == null) {
      stackInSlot=itemStack1.copy();
      stackInSlot.stackSize=itemStack1.stackSize;
      slot.putStack(stackInSlot);
      numTransmuted=itemStack1.stackSize;
      itemStack1.stackSize=0;
      slot.onSlotChanged();
    }
 else     if (slot.isItemValid(itemStack1) && ItemStackUtils.equalsIgnoreStackSize(itemStack1,stackInSlot)) {
      int slotStackSizeLimit=Math.min(stackInSlot.getMaxStackSize(),slot.getSlotStackLimit());
      int combinedStackSize=stackInSlot.stackSize + itemStack1.stackSize;
      if (combinedStackSize <= slotStackSizeLimit) {
        stackInSlot.stackSize=combinedStackSize;
        numTransmuted=itemStack1.stackSize;
        itemStack1.stackSize=0;
        slot.onSlotChanged();
      }
 else       if (stackInSlot.stackSize < slotStackSizeLimit) {
        itemStack1.stackSize=slotStackSizeLimit - stackInSlot.stackSize;
        stackInSlot.stackSize=slotStackSizeLimit;
        numTransmuted=itemStack1.stackSize;
        itemStack1.stackSize=0;
        slot.onSlotChanged();
      }
    }
    currentSlotIndex+=ascending ? -1 : 1;
  }
  ((SlotTabletOutput)transmutationOutputSlot).onShiftPickupFromSlot(entityPlayer,ItemStackUtils.clone(itemStack,numTransmuted));
  return false;
}