        -:    0:Source:patterns-pt.c
        -:    0:Graph:patterns-pt.gcno
        -:    0:Data:patterns-pt.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:#include <stdlib.h>
        -:    3:#include <string.h>
        -:    4:#include <math.h>
        -:    5:#include <unistd.h>
        -:    6:#include <sys/mman.h>
        -:    7:#include <sys/types.h>
        -:    8:#include <sys/stat.h>
        -:    9:#include <fcntl.h>
        -:   10:#include <pthread.h>
        -:   11:#include <time.h>
        -:   12:#include <sys/time.h>
        -:   13:
        -:   14:struct sort_structure{
        -:   15:	unsigned int highest;
        -:   16:	unsigned int sub_highest[256][256];
        -:   17:};
        -:   18:
        -:   19:struct translation_structure{
        -:   20:#ifdef BIG_FILE
        -:   21:	unsigned long series;
        -:   22:#else
        -:   23:	unsigned int series;
        -:   24:#endif
        -:   25:        unsigned int times;
        -:   26:};
        -:   27:
        -:   28:struct pat_length{
        -:   29:	unsigned int highest_times;
        -:   30:	unsigned int len;
        -:   31:	unsigned int search_num;
        -:   32:	//int *search_members;
        -:   33:	struct translation_structure ***member;
        -:   34:}*table;
        -:   35:
        -:   36:struct buffer_structure {
        -:   37:	unsigned int times;
        -:   38:	char *string;
        -:   39:#ifdef BIG_FILE
        -:   40:        unsigned long series;
        -:   41:#else
        -:   42:        unsigned int series;
        -:   43:#endif
        -:   44:};
        -:   45:
        -:   46:struct common_structure {
        -:   47:	unsigned int times;
        -:   48:	char *string;
        -:   49:	unsigned int sub;
        -:   50:};
        -:   51:
        -:   52:
        -:   53:#ifdef BIG_FILE
        -:   54:unsigned long file_bytes;
        -:   55:#else
        -:   56:unsigned int file_bytes;
        -:   57:#endif
        -:   58:
        -:   59:int frequency;
        -:   60:char *mem_file;
        -:   61://unsigned int **search_num;
        -:   62:unsigned int **search_members;
        -:   63:
        -:   64:static void progress_func(int max_searchs, int pat_len);
        -:   65:void *match_search(void *set);
        -:   66:
        9:   67:static void progress_func(int max_searchs, int pat_len){
        -:   68:	static float a = 0;
        -:   69:	static float b = 0;
        -:   70:	
        9:   71:	if(max_searchs == 0){
        8:   72:		b++;
        8:   73:		printf("progress: %.02lf%% %d length patterns done.\n",(double)((b/a)*100),pat_len );
        -:   74:	}else{
        1:   75:		a = max_searchs;
        1:   76:		printf("progress: %.02lf%%\n",(double)((b/a)*100));
        -:   77:	}
        9:   78:}
        -:   79:
     2048:   80:void reset_index(int member_length, char *index){
     2048:   81:	int num3=0;
     2048:   82:	int num4=0;
     2048:   83:	if(member_length>5){
   328960:   84:		for(num3=0; num3<256; num3++){
 84213760:   85:			for(num4=0; num4<256; num4++){ 
 83886080:   86:				index[num3*256+num4]=0;
 83886080:   87:				index[65536+num3*256+num4]=0;
        -:   88:			}
        -:   89:		}
        -:   90:		return;
        -:   91:	}
        -:   92:
   197376:   93:	for(num4=0; num4<256; num4++){ 
   196608:   94:		index[num3*256+num4]=0;
        -:   95:	}
        -:   96:	return;
        -:   97:}
        -:   98:
        -:   99://reset_buffer(b_members, buf_members, buf_count, buffer_open, buffer);
        -:  100://reset_common(c_members, com_count, common, common_open);
        -:  101:
        -:  102:
        -:  103:
        -:  104:
        4:  105:void *match_search(void *set){
        -:  106:        //returns 0 for match found and written
        -:  107:        //returns 1 for no matches found
        -:  108:
        -:  109:	int num7;
        -:  110:	int num1;
        -:  111:	//const int num1 = table[*(unsigned int *)set].search_num;
        -:  112:	
        -:  113:#ifdef BIG_FILE
        -:  114:	unsigned long num4;  
        -:  115:	unsigned long num2=0;
        -:  116:	register unsigned long num3;
        -:  117:	unsigned long num5=0;
        -:  118:	unsigned long num6=0;
        -:  119:	unsigned long highest_times=0;
        -:  120:	const unsigned long stop_byte = file_bytes-table[num1].len-128;
        -:  121:	unsigned long pre_int=0;
        -:  122:
        -:  123:	unsigned long repeat_found=0;
        -:  124:	unsigned long repeat_total=0;
        -:  125:
        -:  126:	unsigned long table_miss = 0; 
        -:  127:	unsigned long table_found = 0; 
        -:  128:	unsigned long cache_found = 0;   
        -:  129:	unsigned long buffer_found = 0;  
        -:  130:	unsigned long patterns_total = 0;
        -:  131:	unsigned long patterns_freed = 0;
        -:  132:	unsigned long repeat_sub=0;
        -:  133:	printf("Warning BIG_FILE is not thought out !\n");
        -:  134:	printf("Danger! don't run this !\n");
        -:  135:#else
        -:  136:        unsigned int num4;
        4:  137:        unsigned int num2=0;
        -:  138:        register unsigned int num3;
        4:  139:	unsigned int num5=0;
        4:  140:	unsigned int num6=0;
        4:  141:	unsigned int highest_times=0;
        -:  142:	unsigned int stop_byte; //= file_bytes-table[num1].len-128;
        4:  143:	unsigned int pre_int=0;
        4:  144:	unsigned int repeat_found=0;
        4:  145:	unsigned int repeat_total=0;
        4:  146:	unsigned int table_miss = 0;
        4:  147:	unsigned int table_found = 0;
        4:  148:	unsigned int cache_found = 0;
        4:  149:	unsigned int buffer_found = 0;
        4:  150:	unsigned int patterns_total = 0;
        4:  151:	unsigned int patterns_freed = 0;
        4:  152:	unsigned int repeat_sub=0;
        -:  153:#endif
        -:  154:
        -:  155:	unsigned short member_length; // = table[num1].len-1;
        4:  156:	unsigned short search_offset = 0;
        -:  157:
        4:  158:	unsigned int saved=0;
        -:  159:        int prefetch_a[128];
        -:  160:        int prefetch_b[8];
        -:  161:
        4:  162:        unsigned int pre_count=0;
        4:  163:        int pre_ret=0;
        -:  164:
        -:  165:	//size_t repeat_sub=0;
        -:  166:
        4:  167:	unsigned char first_char=0;
        4:  168:	unsigned char last_char=0;	
        4:  169:	unsigned char sec_char=0;
        4:  170:	unsigned char a_char=0;
        4:  171:	unsigned char b_char=0;
        4:  172:	unsigned char c_char=0;
        -:  173:
        4:  174:	register unsigned int id = 0;
        -:  175:
        -:  176:        char *index;
        -:  177:	unsigned int sizes[256][256];
        -:  178:	struct buffer_structure *buffer[256];
        -:  179:	struct common_structure *common[256];
        -:  180:	unsigned int buf_members[256];
        -:  181:	unsigned int buf_count[256];
        -:  182:	unsigned int com_count[256];
        -:  183:	unsigned int *unique_id[256];
        -:  184:	unsigned int *common_id[256];
        -:  185:	unsigned int *buffer_id[256];
        -:  186:	int *buffer_open[256];
        -:  187:	int *common_open[256];
        -:  188:	struct translation_structure *temp_struct_array;
        -:  189:	double cache_sizes[2];
        -:  190:	unsigned short b_members;
        -:  191:	unsigned short c_members;
        -:  192:
        4:  193:int tbl_count = 1;
        4:  194:const short unsigned int thread = table[*(unsigned int *)set].search_num;
        -:  195://int max_members = search_members[thread][0];
        -:  196:
       16:  197:while(tbl_count <= search_members[thread][0]){ 
        -:  198:	//tbl_count++ ){ 
        8:  199:	num1=search_members[thread][tbl_count];
        8:  200:        pre_int=0;     
        8:  201:        repeat_found=0;
        8:  202:        repeat_total=0;
        8:  203:        table_miss = 0;
        8:  204:        table_found = 0;
        8:  205:        cache_found = 0;
        8:  206:        buffer_found = 0;
        8:  207:        patterns_total = 0;
        8:  208:        patterns_freed = 0;
        8:  209:        repeat_sub=0;
        8:  210:	pre_ret=0;
        8:  211:	pre_count=0;
        8:  212:	saved=0;
        -:  213:
        8:  214:	member_length = table[num1].len-1;
        8:  215:	stop_byte = file_bytes-table[num1].len-128;
        -:  216:	
        8:  217:        if(member_length>5){
        5:  218:                index = malloc(sizeof(char)*65536*2);
        -:  219:        }else{
        3:  220:                index = malloc(sizeof(char)*65536);
        -:  221:        }
        -:  222:
        8:  223:	num3 = 256*(sizeof(struct buffer_structure)+member_length+1);
        -:  224:	//num4=floor(917504/num3);
        8:  225:	num4=floor(786432/num3);
        -:  226:	//num4=floor(655360/num3);
        -:  227:	//num4=floor(524288/num3);
        -:  228:	//num4=floor(393216/num3);
        -:  229:	//num4=floor(1572864/num3);
        -:  230:	//num4=floor(262144/num3);
        -:  231:	//num4=floor(131072/num3);
        -:  232:	//num4=floor(65536/num3);
        -:  233:
        8:  234:	num3 = 256*(sizeof(struct common_structure)+member_length+1);
        -:  235:	//num5=floor(1572864/num3);
        -:  236:	//num5=floor(524288/num3);
        -:  237:	//num5=floor(655360/num3);
        -:  238:	//num5=floor(393216/num3);
        8:  239:	num5=floor(262144/num3);
        -:  240:	//num5=floor(196608/num3);
        -:  241:	//num5=floor(131072/num3);
        -:  242:	//num5=floor(65536/num3);
        -:  243:
        -:  244:
        8:  245:	if(num4 < 8){
    #####:  246:		num4=8;
        -:  247:	}
       35:  248:	while(num4 % 8 != 0){
       27:  249:		num4++;
        -:  250:	}
       20:  251:	while(num5 % 4 != 0){
       12:  252:		num5++;
        -:  253:	}
        8:  254:	b_members = num4;
        8:  255:	c_members = num5;
        -:  256:
     2056:  257:	for(num3=0; num3<256; num3++){
   524288:  258:		for(num4=0; num4<256; num4++){
   522240:  259:			sizes[num3][num4]=1;
        -:  260:		}
     2048:  261:		buffer[num3] = malloc(b_members*sizeof(struct buffer_structure));
     2048:  262:		common[num3] = malloc(c_members*sizeof(struct common_structure));
     2048:  263:		buffer_id[num3] = malloc(b_members*sizeof(unsigned int));
     2048:  264:		common_id[num3] = malloc(c_members*sizeof(unsigned int));
     2048:  265:		buffer_open[num3] = malloc(b_members*sizeof(int));
     2048:  266:		common_open[num3] = malloc(c_members*sizeof(int));
        -:  267:
   208370:  268:		for(num4=0; num4<b_members; num4++){			
   206322:  269:			buffer[num3][num4].string = malloc(table[num1].len*sizeof(char));
        -:  270:		}
    71622:  271:		for(num4=0; num4<c_members; num4++){
    69574:  272:			common[num3][num4].string = malloc(table[num1].len*sizeof(char));
        -:  273:		}
        -:  274:
        -:  275:	}
        8:  276:	cache_sizes[0] = 256*b_members*( sizeof(struct buffer_structure)+sizeof(unsigned int)+sizeof(int)+(table[num1].len*sizeof(char)) );
        8:  277:	cache_sizes[1] = 256*c_members*( sizeof(struct common_structure)+sizeof(unsigned int)+sizeof(int)+(table[num1].len*sizeof(char)) );
        -:  278:	
     2056:  279:	for(num7=255; num7>-1; num7--){
     2048:  280:		num2=0;
     2048:  281:		reset_index(member_length, index);
        -:  282:		//reset_buffer(b_members, buf_members, buf_count, buffer_open, buffer);
        -:  283:		//reset_common(c_members, com_count, common, common_open);
        -:  284:
   526248:  285:		for(num3=0; num3<256; num3++){
   524200:  286:			buf_members[num3] = 0;
   524200:  287:			buf_count[num3] = 0;
   524200:  288:			com_count[num3]=0;
        -:  289:
 53364456:  290:			for(num4=0; num4<b_members; num4++){
 52840256:  291:				buffer_open[num3][num4]=1;
 52840256:  292:				buffer[num3][num4].times=0;
        -:  293:			}
 18328636:  294:			for(num4=0; num4<c_members; num4++){
 17804436:  295:				common[num3][num4].times=0;
 17804436:  296:				common[num3][num4].sub=0;
 17804436:  297:				common_open[num3][num4]=1;
        -:  298:			}
   524200:  299:			unique_id[num3]=malloc(sizeof(unsigned int)*2);
   524200:  300:			unique_id[num3][0]=0;
        -:  301:		}
    18432:  302:		for(num3=0; num3<8; num3++){
    16384:  303:			prefetch_b[num3] = num7;
        -:  304:		}
     2048:  305:		first_char = num7;
     2048:  306:		repeat_found=0;
        -:  307:
154468097:  308:		while(num2<stop_byte){
        -:  309:			//fill a page 16bytes at a time
2716243393:  310:			for(num3=0; num3<121; num3+=8){
2561779392:  311:				prefetch_a[num3] = (unsigned char)mem_file[num2+num3];
2561779392:  312:				prefetch_a[num3+1] = (unsigned char)mem_file[num2+num3+1];
2561779392:  313:				prefetch_a[num3+2] = (unsigned char)mem_file[num2+num3+2];
2561779392:  314:				prefetch_a[num3+3] = (unsigned char)mem_file[num2+num3+3];
2561779392:  315:				prefetch_a[num3+4] = (unsigned char)mem_file[num2+num3+4];
2561779392:  316:				prefetch_a[num3+5] = (unsigned char)mem_file[num2+num3+5];
2561779392:  317:				prefetch_a[num3+6] = (unsigned char)mem_file[num2+num3+6];
2561779392:  318:				prefetch_a[num3+7] = (unsigned char)mem_file[num2+num3+7];
        -:  319:			}
        -:  320:			//parse page for num7 matches
2094809665:  321:			for(num3=0; num3<121; num3+=8){
1940345664:  322:				if(prefetch_a[num3] == prefetch_b[0]){
 30537721:  323:					prefetch_a[num3]=-1;
        -:  324:				}
1940345664:  325:				if(prefetch_a[num3+1] == prefetch_b[1]){
 19269137:  326:					prefetch_a[num3+1]=-1;
        -:  327:				}
1940345664:  328:				if(prefetch_a[num3+2] == prefetch_b[2]){
 18177426:  329:					prefetch_a[num3+2]=-1;
        -:  330:				}
1940345664:  331:				if(prefetch_a[num3+3] == prefetch_b[3]){
 19036543:  332:					prefetch_a[num3+3]=-1;
        -:  333:				}
1940345664:  334:				if(prefetch_a[num3+4] == prefetch_b[4]){
 20957309:  335:					prefetch_a[num3+4]=-1;
        -:  336:				}
1940345664:  337:				if(prefetch_a[num3+5] == prefetch_b[5]){
 19046451:  338:					prefetch_a[num3+5]=-1;
        -:  339:				}
1940345664:  340:				if(prefetch_a[num3+6] == prefetch_b[6]){
 18523570:  341:					prefetch_a[num3+6]=-1;
        -:  342:				}
1940345664:  343:				if(prefetch_a[num3+7] == prefetch_b[7]){
 19853733:  344:					prefetch_a[num3+7]=-1;
        -:  345:				}
        -:  346:
        -:  347:			}
        -:  348:			//run the matches
154464001:  349:			pre_int=num2;
154464001:  350:			pre_count=0;
2183284648:  351:			while(pre_count<125){
1882616947:  352:				if(prefetch_a[pre_count] == -1){
 28328405:  353:					num2=pre_int+pre_count;
 28328405:  354:					pre_ret=1;
 28328405:  355:					goto proceed;
        -:  356:				}
        -:  357:				pre_a:
1880396766:  358:				pre_count++;
1880396766:  359:				if(prefetch_a[pre_count] == -1){
 20813666:  360:					num2=pre_int+pre_count;
 20813666:  361:					pre_ret=2;
 20813666:  362:					goto proceed;
        -:  363:				}
        -:  364:				pre_b:
1878207251:  365:				pre_count++;
1878207251:  366:				if(prefetch_a[pre_count] == -1){
 20775679:  367:					num2=pre_int+pre_count;
 20775679:  368:					pre_ret=3;
 20775679:  369:					goto proceed;
        -:  370:				}
        -:  371:				pre_c:
1876214534:  372:				pre_count++;
1876214534:  373:				if(prefetch_a[pre_count] == -1){
 20770816:  374:					num2=pre_int+pre_count;
 20770816:  375:					pre_ret=4;
 20770816:  376:					goto proceed;
        -:  377:				}
        -:  378:				pre_d:
1874356646:  379:				pre_count++;
        -:  380:			}
        -:  381:			goto found;
        -:  382:			proceed:
        -:  383:			
 90688566:  384:			sec_char = (unsigned char)mem_file[num2+1];
 90688566:  385:			last_char = (unsigned char)mem_file[num2+member_length];
        -:  386:
 90688566:  387:			if(member_length>5){
 58337567:  388:				a_char = (unsigned char)mem_file[num2+member_length-1];
 58337567:  389:				b_char = (unsigned char)mem_file[num2+member_length-2];
 58337567:  390:				search_offset = member_length-3;
 58337567:  391:				c_char = (unsigned char)mem_file[num2+search_offset];
 58337567:  392:				id = c_char*16777216 + b_char*65536 + a_char*256 + last_char;
        -:  393:
        -:  394:			}else{
 32350999:  395:				search_offset = member_length-1;
 32350999:  396:				a_char = (unsigned char)mem_file[num2+search_offset];
 32350999:  397:				id = first_char*16777216 + sec_char*65536 + a_char*256 + last_char;
        -:  398:			}
        -:  399:			goto repeat_search;
        -:  400:
        -:  401:			buffer_search:
 88101014:  402:                        num3=0;
        -:  403:                        //search cached xMB worth of most recent found patterns
4708282427:  404:                        while(num3<b_members){
4577907600:  405:                                if(!buffer_open[last_char][num3]){
4536936538:  406:					if(id != buffer_id[last_char][num3]){
        -:  407:						goto r_next;
        -:  408:					}         
280769063:  409:					for( num4=1; num4 < search_offset; num4++){
234941862:  410:						if( mem_file[num2+num4] != buffer[last_char][num3].string[num4] ){
        -:  411:							goto r_next;
        -:  412:						}
        -:  413:					}
 45827201:  414:					buffer_found++;
 45827201:  415:					buffer[last_char][num3].times++;
        -:  416:					//if(buffer[last_char][num3].times > highest_times){
        -:  417:					//	highest_times=buffer[last_char][num3].times;
        -:  418:					//}
 45827201:  419:                                        if(pre_ret == 1){
        -:  420:                                                goto pre_a;
        -:  421:                                        }
 26886101:  422:                                        if(pre_ret == 2){
        -:  423:                                                goto pre_b;
        -:  424:                                        }
 18006698:  425:                                        if(pre_ret == 3){
        -:  426:                                                goto pre_c;
        -:  427:                                        }
        -:  428:                                        //if(pre_ret == 4){   
        -:  429:                                                goto pre_d;
        -:  430:                                        //}
        -:  431:
        -:  432:				}
        -:  433:				r_next:
4532080399:  434:				num3++;
        -:  435:			}
        -:  436:
        -:  437:			//search cached xMB worth of most often found patterns
 42273813:  438:			num3=0; 
        -:  439:			
1135689489:  440:			while(num3<c_members){
1066104618:  441:				if(!common_open[last_char][num3]){
998076377:  442:					if(id != common_id[last_char][num3]){
        -:  443:						goto o_next;
        -:  444:					}
 96072560:  445:					for( num4=1; num4 < search_offset; num4++){
 81109805:  446:						if( mem_file[num2+num4] != common[last_char][num3].string[num4] ){
        -:  447:							goto o_next;						
        -:  448:						}
        -:  449:					}
 14962755:  450:					cache_found++;
 14962755:  451:					common[last_char][num3].times++;
        -:  452:					//if(common[last_char][num3].times > highest_times){
        -:  453:					//	highest_times=common[last_char][num3].times;
        -:  454:					//}
 14962755:  455:                                        if(pre_ret == 1){
        -:  456:                                                goto pre_a;
        -:  457:                                        }
 12845098:  458:                                        if(pre_ret == 2){
        -:  459:                                                goto pre_b;
        -:  460:                                        }
  8573282:  461:                                        if(pre_ret == 3){
        -:  462:                                                goto pre_c;
        -:  463:                                        }
        -:  464:                                        //if(pre_ret == 4){   
        -:  465:                                                goto pre_d;
        -:  466:                                        //}
        -:  467:
        -:  468:				}
        -:  469:				o_next:
1051141863:  470:				num3++;
        -:  471:			}
        -:  472:
 27311058:  473:			num5 = unique_id[last_char][0]+1;
        -:  474:
 27311058:  475:			num3 = 1; 
        -:  476:
        -:  477:
        -:  478:			//while(num3<=saved-4){
4778955767:  479:			while(num3+3<num5){
4744939848:  480:				saved=num3;
4744939848:  481:				if(unique_id[last_char][saved] == id){
 52559170:  482:					num6=0;
 52559170:  483:					goto id_match;
        -:  484:				}
        -:  485:				next1:
        -:  486:				;
4745621621:  487:				if(unique_id[last_char][saved+1] == id){
 53322319:  488:					num6=1;
 53322319:  489:					num3=saved+1;
 53322319:  490:					goto id_match;
        -:  491:				}
        -:  492:				next2:
        -:  493:				;
4739629891:  494:				if(unique_id[last_char][saved+2] == id){
 58733443:  495:					num6=2;
 58733443:  496:					num3=saved+2;
 58733443:  497:					goto id_match;
        -:  498:				}
        -:  499:				next3:
        -:  500:				;
4732650020:  501:				if(unique_id[last_char][saved+3] == id){
 53297462:  502:					num6=3;
 53297462:  503:					num3=saved+3;
 53297462:  504:					goto id_match;
        -:  505:				}
        -:  506:				next4:
4724333651:  507:				num3=saved+4;
        -:  508:
        -:  509:			}
        -:  510:
        -:  511:
  6704861:  512:			num6=4;
 13409722:  513:			while(num3<num5){
    #####:  514:				if(unique_id[last_char][num3] == id){
        -:  515:					//num6=4;
        -:  516:					goto id_match;
        -:  517:				}
        -:  518:				next5:
    #####:  519:				num3++;
        -:  520:			}
        -:  521:
        -:  522:
        -:  523:/*			
        -:  524:			while(num3>3){
        -:  525:				saved=num3;
        -:  526:				if(unique_id[last_char][saved] == id){
        -:  527:					num6=0;
        -:  528:					goto id_match;
        -:  529:				}
        -:  530:				next1:
        -:  531:				;
        -:  532:				if(unique_id[last_char][saved-1] == id){
        -:  533:					num6=1;
        -:  534:					num3=saved-1;
        -:  535:					goto id_match;
        -:  536:				}
        -:  537:				next2:
        -:  538:				;
        -:  539:				if(unique_id[last_char][saved-2] == id){
        -:  540:					num6=2;
        -:  541:					num3=saved-2;
        -:  542:					goto id_match;
        -:  543:				}
        -:  544:				next3:
        -:  545:				;
        -:  546:				if(unique_id[last_char][saved-3] == id){
        -:  547:					num6=3;
        -:  548:					num3=saved-3;
        -:  549:					goto id_match;
        -:  550:				}
        -:  551:				next4:
        -:  552:				num3=saved-4;
        -:  553:			}
        -:  554:
        -:  555:			num6=4;
        -:  556:			while(num3>0){
        -:  557:				if(unique_id[last_char][num3] == id){
        -:  558:					goto id_match;
        -:  559:				}
        -:  560:				next5:
        -:  561:				num3--;
        -:  562:			}
        -:  563:
        -:  564:*/
        -:  565:
        -:  566:
  6704861:  567:			table_miss++;
  6704861:  568:			goto no_search;
        -:  569:
        -:  570:			id_match:
213143686:  571:			num4=1;
652057707:  572:			while(num4<search_offset){
        -:  573:
418307824:  574:				if( mem_file[num2+num4] != mem_file[table[num1].member[first_char][last_char][num3].series+num4]){
        -:  575:
192537489:  576:					if(num6 == 4 ){
        -:  577:						goto next5;
        -:  578:					}
197306197:  579:					if(num6 == 3){
        -:  580:						goto next4;
        -:  581:					}
152325104:  582:					if(num6 == 2){
        -:  583:						goto next3;
        -:  584:					}
100571532:  585:					if(num6 == 1){
        -:  586:						goto next2;
        -:  587:					}
        -:  588:					goto next1;
        -:  589:
        -:  590://goto next5;
        -:  591:				}
225770335:  592:				num4++;
        -:  593:			}
        -:  594:/*
        -:  595:}else{
        -:  596:
        -:  597:while(num3>0){
        -:  598:	num4=1;
        -:  599:	while(num4<search_offset){
        -:  600:		if( mem_file[num2+num4] != mem_file[table[num1].member[first_char][last_char][num3].series+num4]){
        -:  601:			goto next_member;
        -:  602:		}
        -:  603:		num4++;
        -:  604:	}
        -:  605:goto member_found;
        -:  606:
        -:  607:next_member:
        -:  608:num3--;
        -:  609:}
        -:  610:table_miss++;
        -:  611:goto no_search;
        -:  612:}
        -:  613:*/
        -:  614:
 20606197:  615:			table[num1].member[first_char][last_char][num3].times++;
        -:  616:					
        -:  617:			//if(table[num1].member[first_char][last_char][num3].times > highest_times){
        -:  618:			//	highest_times=table[num1].member[first_char][last_char][num3].times;
        -:  619:			//}
        -:  620:
476498466:  621:			for(num4=com_count[last_char]; num4<c_members; num4++){
455461803:  622:				if(table[num1].member[first_char][last_char][num3].times>common[last_char][num4].times){
        -:  623:
        -:  624:					//contribute old results to table before replacing
  -430466:  625:					if(!common_open[last_char][num4]){
    69059:  626:						num6 = common[last_char][num4].sub;
    69059:  627:						table[num1].member[first_char][last_char][num6].times=common[last_char][num4].times;
        -:  628:						//if(common[last_char][num4].times > highest_times){
        -:  629:						//	highest_times=common[last_char][num4].times;
        -:  630:						//}
        -:  631:					}
        -:  632:					//write new results to common index
  -430466:  633:					common_open[last_char][num4]=0;
  -430466:  634:					common[last_char][num4].times=table[num1].member[first_char][last_char][num3].times;
  -430466:  635:					common_id[last_char][num4]=unique_id[last_char][num3];
  -430466:  636:					common[last_char][num4].sub=num3;
   166580:  637:					for(num6=0; num6<member_length+1; num6++){
   597046:  638:						common[last_char][num4].string[num6]=mem_file[table[num1].member[first_char][last_char][num3].series+num6];
        -:  639:					}
  -430466:  640:					if(com_count[last_char] == c_members-1){
  -497970:  641:						com_count[last_char] = 0;
        -:  642:					}else{
    67504:  643:						com_count[last_char]++;
        -:  644:					}
        -:  645:
        -:  646:
  -430466:  647:					table_found++;
  -430466:  648:					if(pre_ret == 1){
        -:  649:						goto pre_a;
        -:  650:					}
    50739:  651:					if(pre_ret == 2){
        -:  652:						goto pre_b;
        -:  653:					}
    34092:  654:					if(pre_ret == 3){
        -:  655:						goto pre_c;
        -:  656:					}
        -:  657:					//if(pre_ret == 4){   
        -:  658:						goto pre_d;
        -:  659:					//}
        -:  660:				}
        -:  661:			}
 21036663:  662:			table_found++;
 21036663:  663:			if(pre_ret == 1){
        -:  664:				goto pre_a;
        -:  665:			}
 15762881:  666:			if(pre_ret == 2){
        -:  667:				goto pre_b;
        -:  668:			}
 10560711:  669:			if(pre_ret == 3){
        -:  670:				goto pre_c;
        -:  671:			}
        -:  672:			//if(pre_ret == 4){
        -:  673:				goto pre_d;
        -:  674:			//}
        -:  675:		
        -:  676:			repeat_search:
        -:  677:			;
 90688566:  678:			if(first_char != (unsigned char)mem_file[num2+member_length]){
 83954121:  679:				if(member_length>5){
 53877739:  680:					if(!index[sec_char*256+last_char])
        -:  681:						goto no_search;
 53125213:  682:					if(!index[65536+a_char*256+b_char])
        -:  683:						goto no_search;
        -:  684:					goto buffer_search;
        -:  685:				}
 30076382:  686:				if(!index[sec_char*256+last_char])
        -:  687:					goto no_search;
        -:  688:				goto buffer_search;
        -:  689:			}
        -:  690:			//check if it's a repeat
 13278072:  691:			for(num3=1; num3<member_length; num3++){
 12245960:  692:				if(first_char != (unsigned char)mem_file[num2+num3]){
  5702333:  693:					if(member_length>5){
  3842127:  694:						if(!index[sec_char*256+last_char]) 
        -:  695:							goto no_search;
  3838298:  696:						if(!index[65536+a_char*256+b_char])
        -:  697:							goto no_search;
        -:  698:						goto buffer_search;
        -:  699:					}
  1860206:  700:					if(!index[sec_char*256+last_char])
        -:  701:						goto no_search;
        -:  702:					goto buffer_search;
        -:  703:				}
        -:  704:			}
  1032112:  705:			repeat_found++;
  1032112:  706:			if(repeat_found == 1)
       58:  707:				repeat_sub = num2;
  1032112:  708:                        if(pre_ret == 1){
        -:  709:                             goto pre_a;
        -:  710:                        }
   775222:  711:                        if(pre_ret == 2){
        -:  712:                            goto pre_b;
        -:  713:                        }
   521107:  714:                        if(pre_ret == 3){   
        -:  715:                            goto pre_c;
        -:  716:                        }
        -:  717:                        //if(pre_ret == 4){
        -:  718:                            goto pre_d;
        -:  719:                        //}
        -:  720:			
        -:  721:			no_search:
        -:  722:			;
  8260301:  723:			if(buf_members[last_char]<b_members){				
 65809408:  724:				for(num3=0; num3<member_length+1; num3++){
 58815366:  725:					buffer[last_char][ buf_count[last_char] ].string[num3]=mem_file[num2+num3];
        -:  726:				}
  6994042:  727:				buffer[last_char][ buf_count[last_char] ].series=num2;
  6994042:  728:				buffer_id[last_char][ buf_count[last_char] ] = id;
  6994042:  729:				buffer[last_char][ buf_count[last_char] ].times = 1;
  6994042:  730:				buffer_open[last_char][buf_count[last_char]]=0;
        -:  731:
  6994042:  732:				if(member_length>5){
  5605469:  733:					index[sec_char*256+last_char]=1;
  5605469:  734:					index[65536+a_char*256+b_char]=1;
        -:  735:				}else{
  1388573:  736:					index[sec_char*256+last_char]=1;
        -:  737:				}
  6994042:  738:				buf_count[last_char]++;
  6994042:  739:				buf_members[last_char]++;
        -:  740:			}else{
        -:  741:				//take 4 oldest out of buffer and place into table
        -:  742:				//dealing with sets of 4
  1266259:  743:				if(buf_count[last_char] == b_members){
    59302:  744:					buf_count[last_char] = 0;
        -:  745:				}
        -:  746:
  6327991:  747:				for(num3=buf_count[last_char]; num3<buf_count[last_char]+4; num3++){
        -:  748:
  5061732:  749:					num5 = table[num1].member[first_char][last_char][0].times;
  5061732:  750:					if(sizes[first_char][last_char] == num5){
  1688318:  751:						table[num1].member[first_char][last_char]=realloc(table[num1].member[first_char][last_char],sizeof(struct translation_structure) * (sizes[first_char][last_char]+1+3) );
  1688318:  752:						unique_id[last_char]=realloc(unique_id[last_char], sizeof(unsigned int)*(sizes[first_char][last_char]+1+3) );
  1688318:  753:						sizes[first_char][last_char]+=3;
        -:  754:					}
        -:  755:					
  5061732:  756:					table[num1].member[first_char][last_char][num5+1].series = buffer[last_char][num3].series;
  5061732:  757:					table[num1].member[first_char][last_char][num5+1].times = buffer[last_char][num3].times;
        -:  758:					//if(buffer[last_char][num3].times > highest_times){
        -:  759:					//	highest_times = buffer[last_char][num3].times;
        -:  760:					//}
  5061732:  761:					unique_id[last_char][ num5+1 ] = buffer_id[last_char][num3];
  5061732:  762:					table[num1].member[first_char][last_char][0].times++;
  5061732:  763:					unique_id[last_char][0]=table[num1].member[first_char][last_char][0].times;
  5061732:  764:					buffer_open[last_char][num3]=1;
        -:  765:
        -:  766:
        -:  767:					//add to common index ...
123505570:  768:					for(num4=com_count[last_char]; num4<c_members; num4++){
118443838:  769:						if(buffer[last_char][num3].times > common[last_char][num4].times){
        -:  770:
        -:  771:							//contribute old results to table before replacing
  1407827:  772:							if(!common_open[last_char][num4]){
  1004741:  773:								num6 = common[last_char][num4].sub;
  1004741:  774:								table[num1].member[first_char][last_char][num6].times=common[last_char][num4].times;
        -:  775:								//if(common[last_char][num4].times > highest_times){
        -:  776:								//	highest_times=common[last_char][num4].times;
        -:  777:								//}
        -:  778:							}
        -:  779:							//write new results to common index
  1407827:  780:							common_open[last_char][num4]=0;
  1407827:  781:							common[last_char][num4].times=buffer[last_char][num3].times;
  1407827:  782:							common_id[last_char][num4]=buffer_id[last_char][num3];
  1407827:  783:							common[last_char][num4].sub=num5+1;
 13170454:  784:							for(num6=0; num6<member_length+1; num6++){
 11762627:  785:								common[last_char][num4].string[num6]=buffer[last_char][num3].string[num6];
        -:  786:							}
  1407827:  787:							if(com_count[last_char] == c_members-1){
    41020:  788:								com_count[last_char] = 0;
        -:  789:							}else{
  1366807:  790:								com_count[last_char]++;
        -:  791:							}
        -:  792:						}
        -:  793:					}
        -:  794:
        -:  795:
        -:  796:				}
        -:  797:
        -:  798:				//put current pattern into buffer
 12429750:  799:				for(num3=0; num3<member_length+1; num3++){
 11163491:  800:					buffer[last_char][buf_count[last_char]].string[num3]=mem_file[num2+num3];
        -:  801:				}
  1266259:  802:				buffer[last_char][buf_count[last_char]].series=num2;
  1266259:  803:				buffer_id[last_char][buf_count[last_char]] = id;
  1266259:  804:				buffer[last_char][buf_count[last_char]].times = 1;
  1266259:  805:				buffer_open[last_char][buf_count[last_char]]=0;
        -:  806:
  1266259:  807:				if(member_length>5){
  1108353:  808:					index[sec_char*256+last_char]=1;
  1108353:  809:					index[65536+a_char*256+b_char]=1;
        -:  810:				}else{
   157906:  811:					index[sec_char*256+last_char]=1;
        -:  812:				}
  1266259:  813:				buf_count[last_char]++;
  1266259:  814:				buf_members[last_char]-=3;
        -:  815:			}
        -:  816:			found:
154464001:  817:			num2=pre_int+pre_count;
        -:  818:		}
        -:  819:		
     2048:  820:		if(repeat_found != 0){
       58:  821:			repeat_total += repeat_found;
       58:  822:			num5 = table[num1].member[first_char][first_char][0].times;
       58:  823:			if(sizes[first_char][first_char] == num5){
       11:  824:				table[num1].member[first_char][first_char]=realloc(table[num1].member[first_char][first_char], sizeof(struct translation_structure) * (sizes[first_char][first_char]+1+3) );
       11:  825:				sizes[first_char][first_char]+=3;
        -:  826:			}
       58:  827:			table[num1].member[first_char][first_char][0].times++;
       58:  828:			table[num1].member[first_char][first_char][num5+1].times=repeat_found;
       58:  829:			table[num1].member[first_char][first_char][num5+1].series=repeat_sub;
       58:  830:			if(repeat_found > highest_times){
        4:  831:				highest_times=repeat_found;
        -:  832:			} 
        -:  833:		}
        -:  834:
        -:  835:		//save all needed index info to tables before reset
   526270:  836:		for(num3=0; num3<256; num3++){
   524222:  837:			if(member_length>10)
    #####:  838:				free(unique_id[num3]);
        -:  839:
 53453939:  840:			for(num6=0; num6<b_members; num6++){
 52929717:  841:				if(!buffer_open[num3][num6]){
  3200095:  842:					num5 = table[num1].member[first_char][num3][0].times;
  3200095:  843:					if(sizes[first_char][num3] == num5){					
  1049040:  844:						table[num1].member[first_char][num3]=realloc(table[num1].member[first_char][num3], sizeof(struct translation_structure) * (sizes[first_char][num3]+1+3) );
  1049040:  845:						sizes[first_char][num3]+=3;
        -:  846:					}
  3200095:  847:					table[num1].member[first_char][num3][0].times++;
        -:  848:					
  3200095:  849:					table[num1].member[first_char][num3][num5+1].series=buffer[num3][num6].series;
  3200095:  850:					table[num1].member[first_char][num3][num5+1].times=buffer[num3][num6].times;
        -:  851:					//if(buffer[num3][num6].times > highest_times){
        -:  852:					//	highest_times=buffer[num3][num6].times;
        -:  853:					//}
        -:  854:				}
        -:  855:			}
        -:  856:
 18345046:  857:			for(num4=0; num4<c_members; num4++){
 17820824:  858:				if(!common_open[num3][num4]){
   403120:  859:					num6 = common[num3][num4].sub;
   403120:  860:					table[num1].member[first_char][num3][num6].times=common[num3][num4].times;
        -:  861:					//if(common[num3][num4].times > highest_times){
        -:  862:					//	highest_times=common[num3][num4].times;
        -:  863:					//}
        -:  864:				}
        -:  865:			}
        -:  866:		}
        -:  867:
        -:  868:	
        -:  869:
        -:  870:
        -:  871:		//free all strings that don't meet min frequency to save memory later
   526322:  872:		for(num3=0; num3<256; num3++){
   524274:  873:			num5=table[num1].member[first_char][num3][0].times+1;
   524274:  874:			num6=1;
   524274:  875:			temp_struct_array = malloc(sizeof(struct translation_structure)*num5 );
   524274:  876:			temp_struct_array[0].times = table[num1].member[first_char][num3][0].times;
   524274:  877:			temp_struct_array[0].series=0;
  8789868:  878:			for(num4=1; num4<num5; num4++){
  8265594:  879:				if(table[num1].member[first_char][num3][num4].times>frequency-1){
  1642403:  880:					if(table[num1].member[first_char][num3][num4].times>highest_times){
       71:  881:						highest_times = table[num1].member[first_char][num3][num4].times;
        -:  882:					}
  1642403:  883:					temp_struct_array[num6].series=table[num1].member[first_char][num3][num4].series;
  1642403:  884:					temp_struct_array[num6].times=table[num1].member[first_char][num3][num4].times;
  1642403:  885:					num6++;
        -:  886:				}else{
  6623191:  887:					temp_struct_array[0].times--;
        -:  888:				}
        -:  889:			}
   524274:  890:			patterns_freed+=sizes[first_char][num3]+1-num6;
   524274:  891:			free(table[num1].member[first_char][num3]);
   524274:  892:			table[num1].member[first_char][num3]=malloc(sizeof(struct translation_structure)*num6 );
  2690978:  893:			for(num4=0; num4<num6; num4++){
  2166704:  894:				table[num1].member[first_char][num3][num4].series=temp_struct_array[num4].series;
  2166704:  895:				table[num1].member[first_char][num3][num4].times=temp_struct_array[num4].times;
        -:  896:			}
        -:  897:		}
        -:  898:	}
        8:  899:	table[num1].highest_times=highest_times;
        8:  900:	progress_func(0, member_length+1);
        8:  901:	printf("\tbuffer/cache sizes\n");
        8:  902:	printf("\t\trecent: %u(%.02lfKB) common: %u(%.02lfKB) index: %.02lfKB\n",b_members, cache_sizes[0]/1024, c_members, cache_sizes[1]/1024, (double)sizeof(char)*256*256*2/1024); 
        -:  903:
        8:  904:	patterns_total = table_found + buffer_found + cache_found + table_miss + repeat_total;
        8:  905:	if(patterns_total == 0){
    #####:  906:		printf("WARING: Exiting to prevent floating-point exception!\n");
    #####:  907:		printf("\tNo patterns found.\n");
    #####:  908:		exit(1);
        -:  909:	}
        -:  910:
        8:  911:	printf("\ttotal patterns found: %u\n", patterns_total-table_miss);
        8:  912:	printf("\ttable_miss: %u table_found: %u recent_found: %u common_found: %u repeat_found: %u\n", table_miss, table_found, buffer_found, cache_found, repeat_total);
        8:  913:	printf("\ttable_miss: %.02lf%% table_found: %.02lf%% recent_found: %.02lf%% common_found: %.02lf%% repeat_found: %.02lf%%\n", (double)table_miss/patterns_total*100, (double)table_found/patterns_total*100, (double)buffer_found/patterns_total*100, (double)cache_found/patterns_total*100, (double)repeat_total/patterns_total*100 ); 
        -:  914:
        8:  915:	printf("\tfreed: %u (%.04lfMB) low freq pattern structures\n", patterns_freed, (double)(patterns_freed*sizeof(struct translation_structure))/1024/1024);
        -:  916:	
        8:  917:	printf("\tHighest times: %u\n", highest_times);
        -:  918:
        -:  919:
     2056:  920:for(num3=0; num3<256; num3++){
     2048:  921:	free(buffer[num3]);
     2048:  922:	free(common[num3]);
     2048:  923:	free(common_id[num3]);
     2048:  924:	free(buffer_id[num3]);
     2048:  925:	free(buffer_open[num3]);
     2048:  926:	free(common_open[num3]);
        -:  927:}
        -:  928:
        -:  929:
        8:  930:free(index);
        8:  931:tbl_count++;
        -:  932:}
        -:  933:
        -:  934:
        4:  935:	pthread_exit(0);
        -:  936:}
        -:  937:
    #####:  938:void usage(void){
    #####:  939:        printf("\tUsage: patterns <output> <input> <min pattern size (bytes)> <max pattern size (bytes)> <threads>\n");
    #####:  940:        exit(1);
        -:  941:}
        -:  942:
        -:  943:
        1:  944:int main(int argc, char **argv){
        -:  945:        FILE *output;
        -:  946:	int input;
        -:  947:        struct stat buffer;
        -:  948:        int status;
        -:  949:        int pat_size;
        -:  950:        int num1, num2, num3, num4, num5;
        -:  951:        //int progress=0;
        -:  952:	//double progress2=0;
        1:  953:        int max_searchs=0;
        -:  954:        int max_pat;
        -:  955:        int half_file;
        1:  956:        frequency=4;
        -:  957:	int thread_count;
        -:  958:	struct timeval starttime,endtime;
        -:  959:	double time1;
        -:  960:
        1:  961:        if(argc != 6){
    #####:  962:                usage();
        -:  963:        }
        -:  964:
        1:  965:	thread_count = atoi(argv[5]);
        1:  966:        pat_size = atoi(argv[3]);
        1:  967:        max_pat = atoi(argv[4]);
        1:  968:        input = open(argv[2], O_RDONLY);
        1:  969:        if(input == -1){
    #####:  970:                fprintf( stderr, "Error opening %s\n", argv[2] );
    #####:  971:                exit( 1 );
        -:  972:        }
        -:  973:	
        1:  974:        status = fstat(input, &buffer);
        1:  975:        file_bytes=buffer.st_size;
        1:  976:	if(file_bytes < max_pat+128){    
    #####:  977:		printf("Error: file is too small!\n");
    #####:  978:		exit(1);
        -:  979:	}
        -:  980:        
        -:  981:#ifndef BIG_FILE
        1:  982:	if(file_bytes > 4294967296-max_pat){
    #####:  983:		printf("Error: this file exceeds 4GB, recompile with -D BIG_FILE\n");
    #####:  984:		exit(1);
        -:  985:	}
        -:  986:#endif
        -:  987: 
        1:  988:       mem_file=(char *)mmap(0, file_bytes, PROT_READ, MAP_SHARED, input, 0);
        1:  989:        if (mem_file == MAP_FAILED) {
    #####:  990:                close(input);
    #####:  991:                perror("Error mmapping the file");
    #####:  992:                exit(EXIT_FAILURE);
        -:  993:        }
        -:  994:
        -:  995:
        1:  996:        if( ( output = fopen( argv[1], "w" ) ) == NULL ) {
    #####:  997:                fprintf( stderr, "Error opening %s\n", argv[1] );
    #####:  998:                exit( 1 );
        -:  999:        }
        -: 1000:
        1: 1001:        printf("input: %s\n", argv[2]);
        1: 1002:        printf("output: %s\n", argv[1]);
        1: 1003:        printf("pat_size: %d\n", pat_size);
        1: 1004:        printf("bytes: %d\n", file_bytes);
        1: 1005:        if(max_pat > file_bytes/2){
    #####: 1006:                max_pat = floor(file_bytes/2);
    #####: 1007:                printf("max_pat: %d (reduced to limit!)\n", max_pat);
        -: 1008:        }else{
        1: 1009:                printf("max_pat: %d\n", max_pat);
        -: 1010:        }
        -: 1011:
        -: 1012:
        -: 1013:
        1: 1014:        half_file = sizeof(unsigned char)*ceil(file_bytes/2);
        -: 1015:
        8: 1016:        for(num1=pat_size; num1<max_pat; num1++){
        7: 1017:                max_searchs++;
        -: 1018:        }
        -: 1019:
        1: 1020:	max_searchs++;
        1: 1021:        printf("max_searchs: %d\n", max_searchs);
        1: 1022:        printf("frequency: %d\n", frequency);
        -: 1023:
        1: 1024:if(thread_count > max_searchs){
    #####: 1025:	thread_count = max_searchs;
    #####: 1026:	printf("threads: %d(reduced!)\n", thread_count);
        -: 1027:}else{
        1: 1028:	printf("threads: %d\n", thread_count);
        -: 1029:}
        1: 1030:	pthread_t *threads = (pthread_t *)malloc(sizeof(pthread_t) * thread_count);
        -: 1031:
        1: 1032:	table=(struct pat_length *)malloc( sizeof(struct pat_length) * max_searchs);
        -: 1033:
        9: 1034:	for(num1=0; num1<max_searchs; num1++){
        8: 1035:		table[num1].member=malloc( 256*sizeof(void *) );
     2056: 1036:		for(num2=0; num2<256 ; num2++){
     2048: 1037:                        table[num1].member[num2]=malloc( 256*sizeof(void *) );
   526336: 1038:				for(num3=0; num3<256; num3++){
   524288: 1039:					table[num1].member[num2][num3]=malloc( 2*sizeof(struct translation_structure) );
   524288: 1040:					table[num1].member[num2][num3][0].times=0;
        -: 1041:				}			
        -: 1042:                }
        -: 1043:        }
        -: 1044:
        -: 1045:
        -: 1046:
        -: 1047:
        -: 1048://unsigned int **search_members;
        -: 1049:        
        1: 1050:	search_members = malloc(sizeof(unsigned int *) * thread_count);
        1: 1051:	num2 = ceil(max_searchs/thread_count);
        5: 1052:	for(num1=0; num1<thread_count; num1++){
        4: 1053:		search_members[num1]=malloc(sizeof(int) * num2);
        4: 1054:		search_members[num1][0] = 0;
        -: 1055:	}
        -: 1056:
        1: 1057:	num2=0;
        9: 1058:	for(num1=0; num1<max_searchs; num1++){
        8: 1059:		table[num1].len=pat_size+num1;
        8: 1060:		table[num1].search_num=num1;
        8: 1061:		table[num1].highest_times=0;
        8: 1062:		search_members[num2][0]++;
        8: 1063:		search_members[num2][ search_members[num2][0] ]=num1;
        8: 1064:		if(num2 == thread_count-1){
        2: 1065:			num2=0;
        -: 1066:		}else{
        6: 1067:			num2++;
        -: 1068:		}
        -: 1069:
        -: 1070:	}
        -: 1071:
        -: 1072:
        -: 1073://////////////////////////////////
        -: 1074:
        -: 1075:
        -: 1076:	//progress=0;
        -: 1077:	//progress2=0;
        -: 1078:
        1: 1079:	progress_func(max_searchs, 0);
        -: 1080:
        1: 1081:	gettimeofday(&starttime, NULL);
        -: 1082:
        5: 1083:	for(num1=0; num1<thread_count; num1++){
        4: 1084:		if (pthread_create(&threads[num1], NULL, match_search, &search_members[num1][1]) != 0)
    #####: 1085:			perror("pthread_create"), exit(1);
        -: 1086:	}
        5: 1087:	for(num1=0; num1<thread_count; num1++){
        4: 1088:		if (pthread_join(threads[num1], NULL) != 0)
    #####: 1089:			perror("pthread_join"),exit(1);
        -: 1090:	}
        -: 1091:
        -: 1092:
        -: 1093:/*
        -: 1094:	num2=1;
        -: 1095:	for(num1=0; num1<max_searchs; num1++){
        -: 1096:		table[num1].len=pat_size+num1;		
        -: 1097:		table[num1].search_num=num1;
        -: 1098:		table[num1].highest_times=0;
        -: 1099:
        -: 1100:               	if (pthread_create(&threads[num1], NULL, match_search, &table[num1].search_num) != 0)
        -: 1101:                       	perror("pthread_create"), exit(1);
        -: 1102:				
        -: 1103:		if(num2 % thread_count == 0 || num2 == max_searchs){
        -: 1104:			for(num3=progress; num3<num2; num3++){
        -: 1105:				if (pthread_join(threads[num3], NULL) != 0)
        -: 1106:					perror("pthread_join"),exit(1);
        -: 1107:			}
        -: 1108:			progress=num2;
        -: 1109:		}
        -: 1110:		num2++;
        -: 1111:	}
        -: 1112:*/
        -: 1113:
        1: 1114:	gettimeofday(&endtime, NULL);
        1: 1115:	time1=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
        1: 1116:	printf("time: %.02lfs\n", time1);
        1: 1117:	printf("generating output file...\n");
        -: 1118:
        1: 1119:	gettimeofday(&starttime, NULL);
        -: 1120:
        -: 1121:        //parse structures and write to output
        -: 1122:
        1: 1123:	int index1=0;
        1: 1124:	int index2=0;
        1: 1125:	int max_print=0;
        -: 1126:	int num6;
        -: 1127:        struct sort_structure *sort_index;
        1: 1128:	sort_index = malloc(max_searchs*sizeof(struct sort_structure));
        -: 1129:
        -: 1130:	//initialize sort_index to all 0's
        9: 1131:	for(num5=0; num5<max_searchs; num5++){
        8: 1132:		sort_index[num5].highest=0;
     2056: 1133:		for(num6=0; num6<256; num6++){
   526336: 1134:			for(index1=0; index1<256; index1++){
   524288: 1135:				sort_index[num5].sub_highest[num6][index1]=0;
        -: 1136:			}
        -: 1137:		}
        -: 1138:	}
        -: 1139:	
        -: 1140:	//search tables for the one containing the highest count
        1: 1141:	num2=0;
        9: 1142:	for(num1=0; num1<max_searchs; num1++){
        -: 1143:		//find highest member count
        8: 1144:		sort_index[num1].highest=table[num1].highest_times;
        8: 1145:		if(sort_index[num1].highest > num2){
        1: 1146:			num2=sort_index[num1].highest;
        -: 1147:		}
        -: 1148:	}
        -: 1149:
        -: 1150:	//search tables for highest in all sets and save to sort_index
        9: 1151:	for(num1=max_searchs-1; num1>-1; num1--){
     2056: 1152:		for(index1=0; index1<256; index1++){
   526336: 1153:			for(index2=0; index2<256; index2++){
   524288: 1154:				num5=table[num1].member[index1][index2][0].times+1;
  2166733: 1155:				for(num4=1; num4<num5; num4++){
  1642445: 1156:					if(table[num1].member[index1][index2][num4].times > sort_index[num1].sub_highest[index1][index2]){
   179025: 1157:						sort_index[num1].sub_highest[index1][index2]=table[num1].member[index1][index2][num4].times;
        -: 1158:					}
        -: 1159:				}
        -: 1160:			}
        -: 1161:		}
        -: 1162:	}
        -: 1163:
     2317: 1164:	while(num2>=frequency){
    20846: 1165:		for(num1=max_searchs-1; num1>-1; num1--){
    18530: 1166:			if(sort_index[num1].highest == num2){
     7098: 1167:				sort_index[num1].highest = 0;
  1823990: 1168:				for(index1=0; index1<256; index1++){
466941309: 1169:					for(index2=0; index2<256; index2++){
465124417: 1170:						if(sort_index[num1].sub_highest[index1][index2] == num2){
    38053: 1171:							sort_index[num1].sub_highest[index1][index2]=0;
    38053: 1172:							num5=table[num1].member[index1][index2][0].times+1;
 13853102: 1173:							for(num4=1; num4<num5; num4++){
 13815050: 1174:								if(table[num1].member[index1][index2][num4].times == num2){			
    40000: 1175:									fprintf(output, "%d %d", table[num1].len, table[num1].member[index1][index2][num4].times);
   309641: 1176:                        						for(num3=0; num3<table[num1].len; num3++){
   269641: 1177:										fprintf(output, " %d", mem_file[table[num1].member[index1][index2][num4].series+num3]);
        -: 1178:                        						}
    40000: 1179:									fprintf(output, "\n");
    40000: 1180:									max_print++;
    40000: 1181:									if(max_print == 40000){
        -: 1182:										goto complete;
        -: 1183:									}
 13775050: 1184:                        					}else if(table[num1].member[index1][index2][num4].times < num2){
 13515203: 1185:									if(table[num1].member[index1][index2][num4].times > sort_index[num1].sub_highest[index1][index2]){
   154608: 1186:										sort_index[num1].sub_highest[index1][index2] = table[num1].member[index1][index2][num4].times;
        -: 1187:									}
        -: 1188:								}
        -: 1189:							}
        -: 1190:						}
465124416: 1191:						if(sort_index[num1].sub_highest[index1][index2] > sort_index[num1].highest){
    46643: 1192:							sort_index[num1].highest=sort_index[num1].sub_highest[index1][index2];
        -: 1193:						}
        -: 1194:					}
        -: 1195:				}
        -: 1196:			}
        -: 1197:		}
        -: 1198:				
     2316: 1199:		num2=0;
    20844: 1200:		for(num6=0; num6<max_searchs; num6++){
        -: 1201:			//find highest member count
    18528: 1202:			if(sort_index[num6].highest > num2){
     3189: 1203:				num2=sort_index[num6].highest;
        -: 1204:			}
        -: 1205:		}
        -: 1206:        }
        -: 1207:
        -: 1208:	complete:
        -: 1209:	;
        -: 1210:
        1: 1211:	gettimeofday(&endtime, NULL);
        1: 1212:	time1=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
        1: 1213:	printf("time: %.02lfs\n", time1);
        -: 1214:
        1: 1215:        if (munmap(mem_file, file_bytes) == -1) {
    #####: 1216:                perror("Error un-mmapping the file");
        -: 1217:        }
        -: 1218:
        -: 1219:	//free(mem_file);
        1: 1220:        close(input);
        -: 1221:
        1: 1222:        fclose(output);
        1: 1223:	printf("done.\n");
        1: 1224:        return 0;
        -: 1225:}
        -: 1226:
