static C_cell *
create_colorcell(int red, int green, int blue)
{
	register int ir, ig, ib, i;
	register C_cell *ptr;
	int mindist, next_n;
	register int tmp, dist, n;
	ir = red >> (COLOR_DEPTH-C_DEPTH);
	ig = green >> (COLOR_DEPTH-C_DEPTH);
	ib = blue >> (COLOR_DEPTH-C_DEPTH);
	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
	ptr->num_ents = 0;
	mindist = 99999999;
	for (i = 0; i < num_colors; ++i) {
		if (rm[i]>>(COLOR_DEPTH-C_DEPTH) != ir  ||
		    gm[i]>>(COLOR_DEPTH-C_DEPTH) != ig  ||
		    bm[i]>>(COLOR_DEPTH-C_DEPTH) != ib)
			continue;
		ptr->entries[ptr->num_ents][0] = i;
		ptr->entries[ptr->num_ents][1] = 0;
		++ptr->num_ents;
	        tmp = rm[i] - red;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist = tmp*tmp;
	        tmp = gm[i] - green;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist += tmp*tmp;
	        tmp = bm[i] - blue;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist += tmp*tmp;
	        if (dist < mindist)
			mindist = dist;
	}
	for (i = 0; i < num_colors; ++i) {
		if (rm[i] >> (COLOR_DEPTH-C_DEPTH) == ir  &&
		    gm[i] >> (COLOR_DEPTH-C_DEPTH) == ig  &&
		    bm[i] >> (COLOR_DEPTH-C_DEPTH) == ib)
			continue;
		dist = 0;
	        if ((tmp = red - rm[i]) > 0 ||
		    (tmp = rm[i] - (red + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if ((tmp = green - gm[i]) > 0 ||
		    (tmp = gm[i] - (green + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if ((tmp = blue - bm[i]) > 0 ||
		    (tmp = bm[i] - (blue + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if (dist < mindist) {
			ptr->entries[ptr->num_ents][0] = i;
			ptr->entries[ptr->num_ents][1] = dist;
			++ptr->num_ents;
	        }
	}
	for (n = ptr->num_ents - 1; n > 0; n = next_n) {
		next_n = 0;
		for (i = 0; i < n; ++i)
			if (ptr->entries[i][1] > ptr->entries[i+1][1]) {
				tmp = ptr->entries[i][0];
				ptr->entries[i][0] = ptr->entries[i+1][0];
				ptr->entries[i+1][0] = tmp;
				tmp = ptr->entries[i][1];
				ptr->entries[i][1] = ptr->entries[i+1][1];
				ptr->entries[i+1][1] = tmp;
				next_n = i;
		        }
	}
	return (ptr);
}
['static C_cell *\ncreate_colorcell(int red, int green, int blue)\n{\n\tregister int ir, ig, ib, i;\n\tregister C_cell *ptr;\n\tint mindist, next_n;\n\tregister int tmp, dist, n;\n\tir = red >> (COLOR_DEPTH-C_DEPTH);\n\tig = green >> (COLOR_DEPTH-C_DEPTH);\n\tib = blue >> (COLOR_DEPTH-C_DEPTH);\n\tptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));\n\t*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;\n\tptr->num_ents = 0;\n\tmindist = 99999999;\n\tfor (i = 0; i < num_colors; ++i) {\n\t\tif (rm[i]>>(COLOR_DEPTH-C_DEPTH) != ir  ||\n\t\t    gm[i]>>(COLOR_DEPTH-C_DEPTH) != ig  ||\n\t\t    bm[i]>>(COLOR_DEPTH-C_DEPTH) != ib)\n\t\t\tcontinue;\n\t\tptr->entries[ptr->num_ents][0] = i;\n\t\tptr->entries[ptr->num_ents][1] = 0;\n\t\t++ptr->num_ents;\n\t        tmp = rm[i] - red;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist = tmp*tmp;\n\t        tmp = gm[i] - green;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist += tmp*tmp;\n\t        tmp = bm[i] - blue;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist += tmp*tmp;\n\t        if (dist < mindist)\n\t\t\tmindist = dist;\n\t}\n\tfor (i = 0; i < num_colors; ++i) {\n\t\tif (rm[i] >> (COLOR_DEPTH-C_DEPTH) == ir  &&\n\t\t    gm[i] >> (COLOR_DEPTH-C_DEPTH) == ig  &&\n\t\t    bm[i] >> (COLOR_DEPTH-C_DEPTH) == ib)\n\t\t\tcontinue;\n\t\tdist = 0;\n\t        if ((tmp = red - rm[i]) > 0 ||\n\t\t    (tmp = rm[i] - (red + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if ((tmp = green - gm[i]) > 0 ||\n\t\t    (tmp = gm[i] - (green + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if ((tmp = blue - bm[i]) > 0 ||\n\t\t    (tmp = bm[i] - (blue + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if (dist < mindist) {\n\t\t\tptr->entries[ptr->num_ents][0] = i;\n\t\t\tptr->entries[ptr->num_ents][1] = dist;\n\t\t\t++ptr->num_ents;\n\t        }\n\t}\n\tfor (n = ptr->num_ents - 1; n > 0; n = next_n) {\n\t\tnext_n = 0;\n\t\tfor (i = 0; i < n; ++i)\n\t\t\tif (ptr->entries[i][1] > ptr->entries[i+1][1]) {\n\t\t\t\ttmp = ptr->entries[i][0];\n\t\t\t\tptr->entries[i][0] = ptr->entries[i+1][0];\n\t\t\t\tptr->entries[i+1][0] = tmp;\n\t\t\t\ttmp = ptr->entries[i][1];\n\t\t\t\tptr->entries[i][1] = ptr->entries[i+1][1];\n\t\t\t\tptr->entries[i+1][1] = tmp;\n\t\t\t\tnext_n = i;\n\t\t        }\n\t}\n\treturn (ptr);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n        if (s == 0)\n                return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}']