Program: 130664
Project: 130664
Buggy source:
@Override public void onUpdate(){
  super.onUpdate();
  this.prevAttackCounter=this.attackCounter;
  double var1=this.waypointX - this.posX;
  double var3=this.waypointY - this.posY;
  double var5=this.waypointZ - this.posZ;
  double var7=var1 * var1 + var3 * var3 + var5 * var5;
  if (var7 < 1.0D || var7 > 3600.0D) {
    this.waypointX=this.posX + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
    this.waypointY=this.posY + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
    this.waypointZ=this.posZ + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
  }
  if (this.courseChangeCooldown-- <= 0) {
    this.courseChangeCooldown+=this.rand.nextInt(5) + 2;
    var7=MathHelper.sqrt_double(var7);
    if (this.isCourseTraversable(this.waypointX,this.waypointY,this.waypointZ,var7)) {
      this.motionX+=var1 / var7 * 0.1D;
      this.motionY+=var3 / var7 * 0.1D;
      this.motionZ+=var5 / var7 * 0.1D;
    }
 else {
      this.waypointX=this.posX;
      this.waypointY=this.posY;
      this.waypointZ=this.posZ;
    }
  }
  if (this.targetedEntity != null && this.targetedEntity.isDead) {
    this.targetedEntity=null;
  }
  if (this.targetedEntity == null || this.aggroCooldown-- <= 0) {
    this.targetedEntity=this.worldObj.getClosestVulnerablePlayerToEntity(this,100.0D);
    if (this.targetedEntity != null) {
      this.aggroCooldown=20;
    }
  }
  double var9=64.0D;
  if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < var9 * var9) {
    double var11=this.targetedEntity.posX - this.posX;
    double var13=this.targetedEntity.boundingBox.minY + this.targetedEntity.height / 2.0F - (this.posY + this.height / 2.0F);
    double var15=this.targetedEntity.posZ - this.posZ;
    this.renderYawOffset=this.rotationYaw=-((float)Math.atan2(var11,var15)) * 180.0F / (float)Math.PI;
    if (this.canEntityBeSeen(this.targetedEntity)) {
      if (this.attackCounter == 10) {
        this.worldObj.playAuxSFXAtEntity((EntityPlayer)null,1007,(int)this.posX,(int)this.posY,(int)this.posZ,0);
      }
      ++this.attackCounter;
      if (this.attackCounter == 20) {
        this.worldObj.playAuxSFXAtEntity((EntityPlayer)null,1008,(int)this.posX,(int)this.posY,(int)this.posZ,0);
        EntityLargeFireball var17=new EntityLargeFireball(this.worldObj,this,var11,var13,var15);
        double var18=4.0D;
        Vec3 var20=this.getLook(1.0F);
        var17.posX=this.posX + var20.xCoord * var18;
        var17.posY=this.posY + this.height / 2.0F + 0.5D;
        var17.posZ=this.posZ + var20.zCoord * var18;
        this.worldObj.spawnEntityInWorld(var17);
        this.attackCounter=-40;
      }
    }
 else     if (this.attackCounter > 0) {
      --this.attackCounter;
    }
  }
 else {
    this.renderYawOffset=this.rotationYaw=-((float)Math.atan2(this.motionX,this.motionZ)) * 180.0F / (float)Math.PI;
    if (this.attackCounter > 0) {
      --this.attackCounter;
    }
  }
}

Fixed version (ground truth):
@Override public void onUpdate(){
  super.onUpdate();
  this.prevAttackCounter=this.attackCounter;
  double var1=this.waypointX - this.posX;
  double var3=this.waypointY - this.posY;
  double var5=this.waypointZ - this.posZ;
  double var7=var1 * var1 + var3 * var3 + var5 * var5;
  if (var7 < 1.0D || var7 > 3600.0D) {
    this.waypointX=this.posX + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
    this.waypointY=this.posY + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
    this.waypointZ=this.posZ + (this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F;
  }
  if (this.courseChangeCooldown-- <= 0) {
    this.courseChangeCooldown+=this.rand.nextInt(5) + 2;
    var7=MathHelper.sqrt_double(var7);
    if (this.isCourseTraversable(this.waypointX,this.waypointY,this.waypointZ,var7)) {
      this.motionX+=var1 / var7 * 0.1D;
      this.motionY+=var3 / var7 * 0.1D;
      this.motionZ+=var5 / var7 * 0.1D;
    }
 else {
      this.waypointX=this.posX;
      this.waypointY=this.posY;
      this.waypointZ=this.posZ;
    }
  }
  if (this.targetedEntity != null && this.targetedEntity.isDead) {
    this.targetedEntity=null;
  }
  if (this.targetedEntity == null || this.aggroCooldown-- <= 0) {
    this.targetedEntity=this.worldObj.getClosestVulnerablePlayerToEntity(this,100.0D);
    if (this.targetedEntity != null) {
      this.aggroCooldown=20;
    }
  }
  double var9=64.0D;
  if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < var9 * var9) {
    double var11=this.targetedEntity.posX - this.posX;
    double var13=this.targetedEntity.boundingBox.minY - 5 - this.posY;
    double var15=this.targetedEntity.posZ - this.posZ;
    this.renderYawOffset=this.rotationYaw=-((float)Math.atan2(var11,var15)) * 180.0F / (float)Math.PI;
    if (this.canEntityBeSeen(this.targetedEntity)) {
      if (this.attackCounter == 10) {
        this.worldObj.playAuxSFXAtEntity((EntityPlayer)null,1007,(int)this.posX,(int)this.posY,(int)this.posZ,0);
      }
      ++this.attackCounter;
      if (this.attackCounter == 20) {
        this.worldObj.playAuxSFXAtEntity((EntityPlayer)null,1008,(int)this.posX,(int)this.posY,(int)this.posZ,0);
        EntityLargeFireball var17=new EntityLargeFireball(this.worldObj,this,var11,var13,var15);
        double var18=4.0D;
        Vec3 var20=this.getLook(1.0F);
        var17.posX=this.posX + var20.xCoord * var18;
        var17.posY=this.posY + this.height / 2.0F + 0.5D;
        var17.posZ=this.posZ + var20.zCoord * var18;
        if (!this.worldObj.isRemote)         this.worldObj.spawnEntityInWorld(var17);
        this.attackCounter=-40;
      }
    }
 else     if (this.attackCounter > 0) {
      --this.attackCounter;
    }
  }
 else {
    this.renderYawOffset=this.rotationYaw=-((float)Math.atan2(this.motionX,this.motionZ)) * 180.0F / (float)Math.PI;
    if (this.attackCounter > 0) {
      --this.attackCounter;
    }
  }
}