Program: 181792
Project: 181792
Buggy source:
private int recommendAppInstallLocation(int installLocation,String archiveFilePath,int flags){
  boolean checkInt=false;
  boolean checkExt=false;
  boolean checkBoth=false;
  check_inner: {
    if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) {
      checkInt=true;
      break check_inner;
    }
 else     if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
      checkInt=true;
      break check_inner;
    }
 else     if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) {
      checkExt=true;
      break check_inner;
    }
    if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
      checkInt=true;
      break check_inner;
    }
 else     if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
      checkExt=true;
      checkBoth=true;
      break check_inner;
    }
 else     if (installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
      checkInt=true;
      checkBoth=true;
      break check_inner;
    }
    int installPreference=Settings.System.getInt(getApplicationContext().getContentResolver(),Settings.Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_AUTO);
    if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
      checkInt=true;
      break check_inner;
    }
 else     if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
      checkExt=true;
      break check_inner;
    }
    checkInt=true;
  }
  String status=Environment.getExternalStorageState();
  long availSDSize=-1;
  boolean mediaAvailable=false;
  if (status.equals(Environment.MEDIA_MOUNTED)) {
    StatFs sdStats=new StatFs(Environment.getExternalStorageDirectory().getPath());
    availSDSize=(long)sdStats.getAvailableBlocks() * (long)sdStats.getBlockSize();
    mediaAvailable=true;
  }
  StatFs internalStats=new StatFs(Environment.getDataDirectory().getPath());
  long totalInternalSize=(long)internalStats.getBlockCount() * (long)internalStats.getBlockSize();
  long availInternalSize=(long)internalStats.getAvailableBlocks() * (long)internalStats.getBlockSize();
  double pctNandFree=(double)availInternalSize / (double)totalInternalSize;
  File apkFile=new File(archiveFilePath);
  long pkgLen=apkFile.length();
  long reqInstallSize=pkgLen;
  long reqInternalSize=0;
  boolean intThresholdOk=(pctNandFree >= LOW_NAND_FLASH_TRESHOLD);
  boolean intAvailOk=((reqInstallSize + reqInternalSize) < availInternalSize);
  boolean fitsOnSd=false;
  if (mediaAvailable && (reqInstallSize < availSDSize)) {
    if (reqInternalSize == 0) {
      fitsOnSd=true;
    }
 else     if ((reqInternalSize < availInternalSize) && intThresholdOk) {
      fitsOnSd=true;
    }
  }
  boolean fitsOnInt=intThresholdOk && intAvailOk;
  if (checkInt) {
    if (fitsOnInt) {
      return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
    }
  }
 else   if (checkExt) {
    if (fitsOnSd) {
      return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
    }
  }
  if (checkBoth) {
    if (fitsOnInt) {
      return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
    }
    if (fitsOnSd) {
      return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
    }
  }
  if (checkExt || checkBoth && !mediaAvailable) {
    return PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE;
  }
  return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
}

Fixed version (ground truth):
private int recommendAppInstallLocation(int installLocation,String archiveFilePath,int flags){
  boolean checkInt=false;
  boolean checkExt=false;
  boolean checkBoth=false;
  check_inner: {
    if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) {
      checkInt=true;
      break check_inner;
    }
 else     if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
      checkInt=true;
      break check_inner;
    }
 else     if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) {
      checkExt=true;
      break check_inner;
    }
    if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
      checkInt=true;
      break check_inner;
    }
 else     if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
      checkExt=true;
      checkBoth=true;
      break check_inner;
    }
 else     if (installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
      checkInt=true;
      checkBoth=true;
      break check_inner;
    }
    int installPreference=Settings.System.getInt(getApplicationContext().getContentResolver(),Settings.Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_AUTO);
    if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
      checkInt=true;
      break check_inner;
    }
 else     if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
      checkExt=true;
      break check_inner;
    }
    checkInt=true;
  }
  String status=Environment.getExternalStorageState();
  long availSDSize=-1;
  boolean mediaAvailable=false;
  if (status.equals(Environment.MEDIA_MOUNTED)) {
    StatFs sdStats=new StatFs(Environment.getExternalStorageDirectory().getPath());
    availSDSize=(long)sdStats.getAvailableBlocks() * (long)sdStats.getBlockSize();
    mediaAvailable=true;
  }
  StatFs internalStats=new StatFs(Environment.getDataDirectory().getPath());
  long totalInternalSize=(long)internalStats.getBlockCount() * (long)internalStats.getBlockSize();
  long availInternalSize=(long)internalStats.getAvailableBlocks() * (long)internalStats.getBlockSize();
  double pctNandFree=(double)availInternalSize / (double)totalInternalSize;
  File apkFile=new File(archiveFilePath);
  long pkgLen=apkFile.length();
  long reqInstallSize=pkgLen;
  long reqInternalSize=0;
  boolean intThresholdOk=(pctNandFree >= LOW_NAND_FLASH_TRESHOLD);
  boolean intAvailOk=((reqInstallSize + reqInternalSize) < availInternalSize);
  boolean fitsOnSd=false;
  if (mediaAvailable && (reqInstallSize < availSDSize)) {
    if (reqInternalSize == 0) {
      fitsOnSd=true;
    }
 else     if ((reqInternalSize < availInternalSize) && intThresholdOk) {
      fitsOnSd=true;
    }
  }
  boolean fitsOnInt=intThresholdOk && intAvailOk;
  if (checkInt) {
    if (fitsOnInt) {
      return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
    }
  }
 else   if (checkExt) {
    if (fitsOnSd) {
      return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
    }
  }
  if (checkBoth) {
    if (fitsOnInt) {
      return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
    }
    if (fitsOnSd) {
      return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
    }
  }
  if ((checkExt || checkBoth) && !mediaAvailable) {
    return PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE;
  }
  return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
}