rem: temp = create_temp_file (&tfp); mergefps (&files[i * NMERGE], nfiles % NMERGE, tfp, temp); files[t++] = temp; nfiles = t; if (nfiles == 1) break;
add: remainder = nfiles - in; cheap_slots = NMERGE - out % NMERGE;  if (cheap_slots < remainder) {  size_t nshortmerge = remainder - cheap_slots + 1; FILE *tfp; char *temp = create_temp_file (&tfp); size_t nt = MIN (ntemps, nshortmerge); ntemps -= nt; mergefps (&files[in], nt, nshortmerge, tfp, temp); files[out++] = temp; in += nshortmerge; }   memmove(&files[out], &files[in], (nfiles - in) * sizeof *files); ntemps += out; nfiles -= in - out;
context: merge (char **files, int nfiles, int max_merge, char const *output_file){  while (max_merge < nfiles)    {      FILE *tfp;      int i, t = 0;      char *temp;      for (i = 0; i < nfiles / NMERGE; ++i)	{	  temp = create_temp_file (&tfp);	  mergefps (&files[i * NMERGE], NMERGE, tfp, temp);	  files[t++] = temp;	}      temp = create_temp_file (&tfp);      mergefps (&files[i * NMERGE], nfiles % NMERGE, tfp, temp);      files[t++] = temp;      nfiles = t;      if (nfiles == 1)	break;    }  mergefps (files, nfiles, NULL, output_file);}