// File: /workspace/github_c_makefile_star2_O0/stefpant[P]TCPserver/PantoulasStefanosProject2/jobExec/child.c
// Function: childExec
void childExec(fifo_info* cfifos, int sorted){
//	signal(SIGINT,SIG_IGN);
	struct sigaction sa;
	sa.sa_handler = Csighandler;
	sa.sa_flags = 0;
	sigfillset(&(sa.sa_mask));
	if(sigaction(SIGINT,&sa,NULL) < 0)
		perror("Can't handle SIGINT");
	if(sigaction(SIGQUIT,&sa,NULL) < 0)
		perror("Can't handle SIGQUIT");
	if(sigaction(SIGTERM,&sa,NULL) < 0)
		perror("Can't handle SIGTERM");
	if(sigaction(SIGUSR1,&sa,NULL) < 0)
		perror("Can't handle SIGUSR1");
	if(sigaction(SIGPIPE,&sa,NULL) < 0)
		perror("Can't handle SIGPIPE");
	char *buf = NULL;
	char *word = NULL;
	char *filepath = NULL;
	int flen;
	DIR* dirptr =NULL;
	struct dirent* direntp;

	time_t timer;
	char timebuffer[26];
	struct tm* tm_info;

	int searchwordcount = 0;//value to return when i exit

	char *log="../PantoulasStefanosProject2/jobExec/log/Worker_";//creating the logfile names for every child
	char *logbuf;
	logbuf = myitoa((int)getpid());//has in the end the '\0'
	char *logname = malloc((49 + itol((int)getpid()))*sizeof(char));
	strcpy(logname,log);
	strcat(logname,logbuf);
	free(logbuf);

	FILE* fp;//lets open the logfile now
	if((fp=fopen(logname,"w"))==NULL){
		perror("fopen");
		exit(49);
	}


	//fprintf(fp,"%d: %s\n",(int)getpid(),timebuffer);


	filemap *docmaps = malloc(sizeof(filemap));//k maps for every readed file
	//char ***docmaps = malloc(sizeof(char**));//
	//int *lines = malloc(sizeof(int));//lines for every map
	trie_info *mytrie = malloc(sizeof(trie_info));
	mytrie->trieyo=nodeConstruct('a');//random init the root
	mytrie->wc = 0;
	mytrie->bc = 0;
	mytrie->lc = 0;
	int mc = 0;//mapcounter
	int tempbc;//temp byte counter

	int n;
	int flag=0;
	int empty_process_flag = 0;

	while(1){//reading the k directories sent by parent 
		buf = malloc((BUFSIZE+1)*sizeof(char));
		guard(n = read_command(cfifos[0].fd,&buf,BUFSIZE),"child read error",12);
		if(!strcmp(buf,"_BROKEN_FIFO_")) {flagCINT = 1; flag = 1;}
		if((!strcmp(buf,"/stop") || n==0 )&& strcmp(buf,"_BROKEN_FIFO")) flag=1;
		else{//open and read directory :-)
			//printf("Im child:%d and read:%s\n",(int)getpid(),buf);
			if((dirptr = opendir(buf)) == NULL)
				printf("Cannot open directory:%s\n",buf);
			else{
				empty_process_flag = 1;//process not empty
				while((direntp = readdir(dirptr)) != NULL){
					if(direntp->d_type == DT_REG){//file to save
						//printf("Im child:%d and read:%s\n",(int)getpid(),direntp->d_name);
						docmaps = realloc(docmaps,(mc+1)*sizeof(filemap));
						//lines = realloc(lines,(mapcounter+1)*sizeof(int));
						flen = strlen(buf)+strlen(direntp->d_name)+2;
						filepath = malloc(flen*sizeof(char));
						strcpy(filepath,buf);
						strcat(filepath,"/");
						strcat(filepath,direntp->d_name);
						filepath[flen-1] = '\0';
						if((tempbc = read_doc(filepath,&(docmaps[mc].map),&(docmaps[mc].lines)))<0){
							printf("Error opening the file '%s'\n",filepath);
							free(filepath);
							continue;
						}
						mytrie->bc += tempbc;
						mytrie->lc += docmaps[mc].lines;
						//else printf("Child %d read %d lines!(%s)\n",(int)getpid(),docmaps[mapcounter].lines,direntp->d_name);
						docmaps[mc].name = filepath;
						mytrie->wc += createTrie(docmaps[mc].map,docmaps[mc].lines,docmaps[mc].name,mc,&(mytrie->trieyo),sorted);
						mc++;
					}
				}
				closedir(dirptr);
			}
		}
		free(buf);
		buf = NULL;
		//return ;
		if(flag) break;
	}

	if(write(cfifos[1].fd,"/ready\0",(size_t)7)!=7){//send msg to parent,child ready
		perror("child write error");}

	int start;
	while(1){//waiting for parent commands
		buf = malloc((BUFSIZE+1)*sizeof(char));
		if(read_command(cfifos[0].fd,&buf,BUFSIZE) < 0) flagCINT = 1;//fifo broke,something happened to parent
		if(flagCINT == 1) strcpy(buf,"bye");
		//check if parent killed, by checking if parent's id==1
		//then take that as INTERUPT and exit
		if(getppid() == 1) flagCINT = 1;
		if(!strcmp(buf,"_BROKEN_FIFO_")) flagCINT = 1;
		start = nextWord(buf,&word,0);
		if(!strcmp(word,"/exit") || flagCINT==1){//got exit command from parent or signal to terminate
			//printf("#au revoir\n");
			free(buf);
			free(word);
			break;
		}
		else if(!strcmp(word,"/wc")){
			//struct trie_info has all the needed infos :-)
			time(&timer);//save time in timebuffer
			tm_info = localtime(&timer);
			strftime(timebuffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
			free(word);
			word = NULL;
			if(empty_process_flag){//if trie not empty
				flen = itol(mytrie->bc)+itol(mytrie->wc)+itol(mytrie->lc)+3;
				word = malloc(flen*sizeof(char));
				char* tempbuf = myitoa(mytrie->bc);
				strcpy(word,tempbuf);
				strcat(word," ");
				free(tempbuf);
				tempbuf = myitoa(mytrie->wc);
				strcat(word,tempbuf);
				strcat(word," ");
				free(tempbuf);
				tempbuf = myitoa(mytrie->lc);
				strcat(word,tempbuf);
				strcat(word,"\0");
				free(tempbuf);
				if(write(cfifos[1].fd,word,flen)!=flen){//wc:results
					perror("child write error");}
				//free(word);
			}
			else{
				word = malloc(6*sizeof(char));
				strcpy(word,"0 0 0\0");
				if(write(cfifos[1].fd,"0 0 0\0",(size_t)6)!=6){//empty :'(
					perror("child write error");}
			}
			fprintf(fp,"%s : wc : [NULL] : %s\n",timebuffer,word);//write to log
			free(word);
		}
		else if(!strcmp(word,"/maxc") || !strcmp(word,"/minc")){
			int max = 1;//command = /maxc
			nc_pair *nc = NULL;
			if(!strcmp(word,"/minc")) max=0;//or /minc
			free(word);
			nextWord(buf,&word,start);
			//printf("read %s with max=%d\n",word,max);
			nc = searchWordInTrie(mytrie->trieyo,word,sorted,max);
			time(&timer);
			tm_info = localtime(&timer);
			strftime(timebuffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
			if(max)
				fprintf(fp,"%s : maxcount : %s : ",timebuffer,word);
			else
				fprintf(fp,"%s : mincount : %s : ",timebuffer,word);

			free(word);
			if(getNCname(nc) != NULL){//form to send:"PATH COUNTER"
				flen = strlen(getNCname(nc)) + itol(getNCcounter(nc)) + 2;
				word = malloc(flen*sizeof(char));
				char* tempbuf = myitoa(getNCcounter(nc));
				strcpy(word,getNCname(nc));
				strcat(word," ");
				strcat(word,tempbuf);
				strcat(word,"\0");
				free(tempbuf);
				if(write(cfifos[1].fd,word,flen)!=flen){//wc:results
					perror("child write error");}
				fprintf(fp,"%s\n",word);//append the result
				free(word);
			}
			else{//word not found trie,send "-"
				if(write(cfifos[1].fd,"-\0",(size_t)2)!=2){//empty :'(
					perror("child write error");}
				fprintf(fp,"-\n");
			}
			free(nc);
		}
		else if(!strcmp(word,"/search")){
			flagUSR1 = 0;
			//save words from search in array
			int maxsw = 8;
			query_info *qinfo = malloc(maxsw*sizeof(query_info));//start with 2^3 and increase..
			int swcounter = 0;
			while(start!=-1){//for every word save their info(word,node to PL )
				start = nextWord(buf,&(qinfo[swcounter].word),start);//save word
				swcounter++;
				if(swcounter == maxsw){
					maxsw*=2;
					qinfo = realloc(qinfo,maxsw*sizeof(query_info));
				}
			}

			searchwordcount += swcounter;

			qinfo = realloc(qinfo,swcounter*sizeof(query_info));//resize
			int **node_info = NULL;
			int **merged_node_info = NULL;
			int mnicounter = 0;//merged node info counter
			int nicounter = 0;//node info counter
			for(int i=0;i<swcounter;i++){
				if(flagUSR1 == 1) break;//stop merging results,deadline passed
				//find last node of every word
				qinfo[i].last = getWordLastNode(mytrie->trieyo,qinfo[i].word,sorted);
				//fprintf(fp,"Process %d read '%s'\n",(int)getpid(),qinfo[i].word);
				getNodeData(qinfo[i].last, &node_info, &nicounter);
				if(qinfo[i].last == NULL) continue;//word not found check next
				mergeNodeInfo(&merged_node_info,&mnicounter,node_info,nicounter);//merge results from words
				for(int u=0;u<nicounter;u++)
					free(node_info[u]);
				free(node_info);
				node_info = NULL;
			}
	//from merged_node_info get:
	//	1.file name with full path -->docmaps[merged_node_info[i][0]].name
	//	2.no of line --> merged_node_info[i][1]
	//	3.line's content --> docmaps[merged_node_info[i][0]].map[merged_node_info[i][1]]

			int wlen;
			char *tempbuf = NULL;
			char *strline = NULL;

			if(flagUSR1 == 0){//if flag not changed parent still waits for results
				for(int u=0;u<mnicounter;u++){
					wlen = strlen(docmaps[merged_node_info[u][0]].name) + itol(merged_node_info[u][1] + 1);
					wlen += strlen(docmaps[merged_node_info[u][0]].map[merged_node_info[u][1]]) + 3;//2 for spaces + '\0'
					tempbuf = malloc(wlen*sizeof(char));
					strcpy(tempbuf,docmaps[merged_node_info[u][0]].name);
					strcat(tempbuf," ");
					strline = myitoa(merged_node_info[u][1] + 1);
					strcat(tempbuf,strline);
					strcat(tempbuf," ");
					strcat(tempbuf,docmaps[merged_node_info[u][0]].map[merged_node_info[u][1]]);
					tempbuf[wlen-1] = '\0';//tempbuf ready to write in fifo
					if(write(cfifos[1].fd,tempbuf,wlen)!=wlen)
						perror("2child write error");
					free(strline);
					strline = NULL;
					free(tempbuf);
					tempbuf = NULL;
				}
				if(write(cfifos[1].fd,"_STOP_\0",7)!=7)
					perror("1child write error");
			}
			for(int u=0;u<mnicounter;u++)
				free(merged_node_info[u]);
			free(merged_node_info);

			for(int i=0;i<swcounter;i++){//write results in log
				char *spaths=NULL;
				time(&timer);
				tm_info = localtime(&timer);
				strftime(timebuffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
				fprintf(fp,"%s : search : %s",timebuffer,qinfo[i].word);
				spaths = getNamesAsString(qinfo[i].last);
				if(spaths==NULL) fprintf(fp,"\n");
				else {fprintf(fp,"%s\n",spaths);free(spaths);}
			}

			for(int i=0;i<swcounter;i++)free(qinfo[i].word);
			free(qinfo);
			free(word);
		}
		free(buf);
	}
	//free maps
	for(int i=0;i<mc;i++){
		for(int j=0;j<docmaps[i].lines;j++)
			free((docmaps[i]).map[j]);
		free((docmaps[i]).map);
		free((docmaps[i]).name);
	}
	free(docmaps);
	nodeDestruct(mytrie->trieyo);
	free(mytrie);
	free(logname);
	fclose(fp);

	if(write(cfifos[1].fd,"/exit_success\0",(size_t)14)!=14){//exit:success
		printf("Probably parent is dead :-(\n");}
	close(cfifos[0].fd);
	close(cfifos[1].fd);
	free(cfifos[0].name);
	free(cfifos[1].name);
	free(cfifos);
	exit(searchwordcount);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq -0x59(%rip), %rax       # 0x2900
movq %rax, -0xa8(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0xa8(%rbp), %rdi
addq $0x8, %rdi
callq 0x11a0
movl $0x2, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x10a0
cmpl $0x0, %eax
jge 0x299d
leaq 0x57bc(%rip), %rdi      # 0x8154
callq 0x1260
movl $0x3, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x10a0
cmpl $0x0, %eax
jge 0x29c3
leaq 0x57aa(%rip), %rdi      # 0x8168
callq 0x1260
movl $0xf, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x10a0
cmpl $0x0, %eax
jge 0x29e9
leaq 0x5799(%rip), %rdi      # 0x817d
callq 0x1260
movl $0xa, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x10a0
cmpl $0x0, %eax
jge 0x2a0f
leaq 0x5788(%rip), %rdi      # 0x8192
callq 0x1260
movl $0xd, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x10a0
cmpl $0x0, %eax
jge 0x2a35
leaq 0x5777(%rip), %rdi      # 0x81a7
callq 0x1260
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xd0(%rbp)
movl $0x0, -0x10c(%rbp)
leaq 0x574a(%rip), %rax      # 0x81bc
movq %rax, -0x118(%rbp)
callq 0x10d0
movl %eax, %edi
callq 0x4620
movq %rax, -0x120(%rbp)
callq 0x10d0
movl %eax, %edi
callq 0x45e0
addl $0x31, %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x11e0
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
movq -0x118(%rbp), %rsi
callq 0x1080
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0x1280
movq -0x120(%rbp), %rdi
callq 0x1030
movq -0x128(%rbp), %rdi
leaq 0x5568(%rip), %rsi      # 0x8056
callq 0x1250
movq %rax, -0x130(%rbp)
cmpq $0x0, %rax
jne 0x2b16
leaq 0x56e6(%rip), %rdi      # 0x81ed
callq 0x1260
movl $0x31, %edi
callq 0x12a0
movl $0x18, %edi
callq 0x11e0
movq %rax, -0x138(%rbp)
movl $0x18, %edi
callq 0x11e0
movq %rax, -0x140(%rbp)
movl $0x61, %edi
callq 0x20e0
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, (%rax)
movq -0x140(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x140(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x140(%rbp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0x144(%rbp)
movl $0x0, -0x150(%rbp)
movl $0x0, -0x154(%rbp)
movl $0x101, %edi            # imm = 0x101
callq 0x11e0
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0xb0(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x44f0
movl %eax, %edi
movl %edi, -0x14c(%rbp)
leaq 0x5624(%rip), %rsi      # 0x81f3
movl $0xc, %edx
callq 0x44b0
movq -0xb0(%rbp), %rdi
leaq 0x561d(%rip), %rsi      # 0x8204
callq 0x1160
cmpl $0x0, %eax
jne 0x2c05
movl $0x1, 0x85a1(%rip)      # 0xb19c
movl $0x1, -0x150(%rbp)
movq -0xb0(%rbp), %rdi
leaq 0x55ff(%rip), %rsi      # 0x8212
callq 0x1160
cmpl $0x0, %eax
je 0x2c26
cmpl $0x0, -0x14c(%rbp)
jne 0x2c4d
movq -0xb0(%rbp), %rdi
leaq 0x55e4(%rip), %rsi      # 0x8218
callq 0x1160
cmpl $0x0, %eax
je 0x2c4d
movl $0x1, -0x150(%rbp)
jmp 0x2ed5
movq -0xb0(%rbp), %rdi
callq 0x1100
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
jne 0x2c80
movq -0xb0(%rbp), %rsi
leaq 0x55b1(%rip), %rdi      # 0x8225
movb $0x0, %al
callq 0x1120
jmp 0x2ed3
movl $0x1, -0x154(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x11d0
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
je 0x2ec7
movq -0xd8(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x2ec2
movq -0x138(%rbp), %rdi
movl -0x144(%rbp), %eax
addl $0x1, %eax
cltq
imulq $0x18, %rax, %rsi
callq 0x1200
movq %rax, -0x138(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x1110
movq %rax, -0x1f8(%rbp)
movq -0xd8(%rbp), %rdi
addq $0x13, %rdi
callq 0x1110
movq %rax, %rcx
movq -0x1f8(%rbp), %rax
addq %rcx, %rax
addq $0x2, %rax
movl %eax, -0xc4(%rbp)
movslq -0xc4(%rbp), %rdi
shlq $0x0, %rdi
callq 0x11e0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x1080
movq -0xc0(%rbp), %rdi
leaq 0x54f0(%rip), %rsi      # 0x823f
callq 0x1280
movq -0xc0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
addq $0x13, %rsi
callq 0x1280
movq -0xc0(%rbp), %rax
movl -0xc4(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0xc0(%rbp), %rdi
movq -0x138(%rbp), %rsi
movslq -0x144(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
movq -0x138(%rbp), %rdx
movslq -0x144(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdx
addq $0x10, %rdx
callq 0x1400
movl %eax, -0x148(%rbp)
cmpl $0x0, %eax
jge 0x2ded
movq -0xc0(%rbp), %rsi
leaq 0x546c(%rip), %rdi      # 0x8241
movb $0x0, %al
callq 0x1120
movq -0xc0(%rbp), %rdi
callq 0x1030
jmp 0x2c8a
movl -0x148(%rbp), %ecx
movq -0x140(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x138(%rbp), %rax
movslq -0x144(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x140(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0xc0(%rbp), %rcx
movq -0x138(%rbp), %rax
movslq -0x144(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x138(%rbp), %rax
movslq -0x144(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x138(%rbp), %rax
movslq -0x144(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %esi
movq -0x138(%rbp), %rax
movslq -0x144(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movl -0x144(%rbp), %ecx
movq -0x140(%rbp), %r8
movl -0xc(%rbp), %r9d
callq 0x2850
movl %eax, %ecx
movq -0x140(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x2c8a
movq -0xd0(%rbp), %rdi
callq 0x1140
jmp 0x2ed5
movq -0xb0(%rbp), %rdi
callq 0x1030
movq $0x0, -0xb0(%rbp)
cmpl $0x0, -0x150(%rbp)
je 0x2ef7
jmp 0x2efc
jmp 0x2b97
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x5422(%rip), %rsi      # 0x832c
movl $0x7, %edx
callq 0x10c0
cmpq $0x7, %rax
je 0x2f26
leaq 0x53cb(%rip), %rdi      # 0x82ec
callq 0x1260
jmp 0x2f28
movl $0x101, %edi            # imm = 0x101
callq 0x11e0
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0xb0(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x44f0
cmpl $0x0, %eax
jge 0x2f60
movl $0x1, 0x823c(%rip)      # 0xb19c
movl 0x8236(%rip), %eax      # 0xb19c
cmpl $0x1, %eax
jne 0x2f7e
movq -0xb0(%rbp), %rdi
leaq 0x52e5(%rip), %rsi      # 0x825e
callq 0x1080
callq 0x1290
cmpl $0x1, %eax
jne 0x2f92
movl $0x1, 0x820a(%rip)      # 0xb19c
movq -0xb0(%rbp), %rdi
leaq 0x5264(%rip), %rsi      # 0x8204
callq 0x1160
cmpl $0x0, %eax
jne 0x2fb4
movl $0x1, 0x81e8(%rip)      # 0xb19c
movq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
xorl %edx, %edx
callq 0x2430
movl %eax, -0x158(%rbp)
movq -0xb8(%rbp), %rdi
leaq 0x5285(%rip), %rsi      # 0x8262
callq 0x1160
cmpl $0x0, %eax
je 0x2ff2
movl 0x81af(%rip), %eax      # 0xb19c
cmpl $0x1, %eax
jne 0x300f
movq -0xb0(%rbp), %rdi
callq 0x1030
movq -0xb8(%rbp), %rdi
callq 0x1030
jmp 0x3c83
movq -0xb8(%rbp), %rdi
leaq 0x524b(%rip), %rsi      # 0x8268
callq 0x1160
cmpl $0x0, %eax
jne 0x328a
leaq -0xe0(%rbp), %rdi
callq 0x11c0
leaq -0xe0(%rbp), %rdi
callq 0x1040
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rcx
movl $0x1a, %esi
leaq 0x5208(%rip), %rdx      # 0x826c
callq 0x1220
movq -0xb8(%rbp), %rdi
callq 0x1030
movq $0x0, -0xb8(%rbp)
cmpl $0x0, -0x154(%rbp)
je 0x3206
movq -0x140(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x45e0
movl %eax, -0x200(%rbp)
movq -0x140(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x45e0
movl %eax, %ecx
movl -0x200(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x1fc(%rbp)
movq -0x140(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x45e0
movl %eax, %ecx
movl -0x1fc(%rbp), %eax
addl %ecx, %eax
addl $0x3, %eax
movl %eax, -0xc4(%rbp)
movslq -0xc4(%rbp), %rdi
shlq $0x0, %rdi
callq 0x11e0
movq %rax, -0xb8(%rbp)
movq -0x140(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x4620
movq %rax, -0x160(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x1080
movq -0xb8(%rbp), %rdi
leaq 0x519a(%rip), %rsi      # 0x82cb
callq 0x1280
movq -0x160(%rbp), %rdi
callq 0x1030
movq -0x140(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x4620
movq %rax, -0x160(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x1280
movq -0xb8(%rbp), %rdi
leaq 0x5152(%rip), %rsi      # 0x82cb
callq 0x1280
movq -0x160(%rbp), %rdi
callq 0x1030
movq -0x140(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x4620
movq %rax, -0x160(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x1280
movq -0xb8(%rbp), %rdi
leaq 0x517b(%rip), %rsi      # 0x833c
callq 0x1280
movq -0x160(%rbp), %rdi
callq 0x1030
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
movq -0xb8(%rbp), %rsi
movslq -0xc4(%rbp), %rdx
callq 0x10c0
movslq -0xc4(%rbp), %rcx
cmpq %rcx, %rax
je 0x3204
leaq 0x50ed(%rip), %rdi      # 0x82ec
callq 0x1260
jmp 0x3256
movl $0x6, %edi
callq 0x11e0
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
leaq 0x5119(%rip), %rsi      # 0x833e
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x5106(%rip), %rsi      # 0x833e
movl $0x6, %edx
callq 0x10c0
cmpq $0x6, %rax
je 0x3254
leaq 0x509d(%rip), %rdi      # 0x82ec
callq 0x1260
jmp 0x3256
movq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq -0xb8(%rbp), %rcx
leaq 0x500c(%rip), %rsi      # 0x827e
movb $0x0, %al
callq 0x1180
movq -0xb8(%rbp), %rdi
callq 0x1030
jmp 0x3c70
movq -0xb8(%rbp), %rdi
leaq 0x4ffd(%rip), %rsi      # 0x8295
callq 0x1160
cmpl $0x0, %eax
je 0x32be
movq -0xb8(%rbp), %rdi
leaq 0x4feb(%rip), %rsi      # 0x829b
callq 0x1160
cmpl $0x0, %eax
jne 0x3583
movl $0x1, -0x164(%rbp)
movq $0x0, -0x170(%rbp)
movq -0xb8(%rbp), %rdi
leaq 0x4fba(%rip), %rsi      # 0x829b
callq 0x1160
cmpl $0x0, %eax
jne 0x32f5
movl $0x0, -0x164(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x1030
movq -0xb0(%rbp), %rdi
movl -0x158(%rbp), %edx
leaq -0xb8(%rbp), %rsi
callq 0x2430
movq -0x140(%rbp), %rax
movq (%rax), %rdi
movq -0xb8(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x164(%rbp), %ecx
callq 0x7150
movq %rax, -0x170(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x11c0
leaq -0xe0(%rbp), %rdi
callq 0x1040
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rcx
movl $0x1a, %esi
leaq 0x4ef3(%rip), %rdx      # 0x826c
callq 0x1220
cmpl $0x0, -0x164(%rbp)
je 0x33ac
movq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq -0xb8(%rbp), %rcx
leaq 0x4efe(%rip), %rsi      # 0x82a1
movb $0x0, %al
callq 0x1180
jmp 0x33cf
movq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq -0xb8(%rbp), %rcx
leaq 0x4eef(%rip), %rsi      # 0x82b7
movb $0x0, %al
callq 0x1180
movq -0xb8(%rbp), %rdi
callq 0x1030
movq -0x170(%rbp), %rdi
callq 0x6d40
cmpq $0x0, %rax
je 0x3533
movq -0x170(%rbp), %rdi
callq 0x6d40
movq %rax, %rdi
callq 0x1110
movq %rax, -0x210(%rbp)
movq -0x170(%rbp), %rdi
callq 0x6d60
movl %eax, %edi
callq 0x45e0
movl %eax, %ecx
movq -0x210(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
addq $0x2, %rax
movl %eax, -0xc4(%rbp)
movslq -0xc4(%rbp), %rdi
shlq $0x0, %rdi
callq 0x11e0
movq %rax, -0xb8(%rbp)
movq -0x170(%rbp), %rdi
callq 0x6d60
movl %eax, %edi
callq 0x4620
movq %rax, -0x178(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x170(%rbp), %rdi
callq 0x6d40
movq -0x208(%rbp), %rdi
movq %rax, %rsi
callq 0x1080
movq -0xb8(%rbp), %rdi
leaq 0x4e2b(%rip), %rsi      # 0x82cb
callq 0x1280
movq -0xb8(%rbp), %rdi
movq -0x178(%rbp), %rsi
callq 0x1280
movq -0xb8(%rbp), %rdi
leaq 0x4e76(%rip), %rsi      # 0x833c
callq 0x1280
movq -0x178(%rbp), %rdi
callq 0x1030
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
movq -0xb8(%rbp), %rsi
movslq -0xc4(%rbp), %rdx
callq 0x10c0
movslq -0xc4(%rbp), %rcx
cmpq %rcx, %rax
je 0x3509
leaq 0x4de8(%rip), %rdi      # 0x82ec
callq 0x1260
movq -0x130(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq 0x4d73(%rip), %rsi      # 0x8291
movb $0x0, %al
callq 0x1180
movq -0xb8(%rbp), %rdi
callq 0x1030
jmp 0x3572
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x4e04(%rip), %rsi      # 0x8345
movl $0x2, %edx
callq 0x10c0
cmpq $0x2, %rax
je 0x355d
leaq 0x4d94(%rip), %rdi      # 0x82ec
callq 0x1260
movq -0x130(%rbp), %rdi
leaq 0x4d62(%rip), %rsi      # 0x82cd
movb $0x0, %al
callq 0x1180
movq -0x170(%rbp), %rdi
callq 0x1030
jmp 0x3c6e
movq -0xb8(%rbp), %rdi
leaq 0x4d3f(%rip), %rsi      # 0x82d0
callq 0x1160
cmpl $0x0, %eax
jne 0x3c6c
movl $0x0, 0x7bf7(%rip)      # 0xb1a0
movl $0x8, -0x17c(%rbp)
movslq -0x17c(%rbp), %rdi
shlq $0x4, %rdi
callq 0x11e0
movq %rax, -0x188(%rbp)
movl $0x0, -0x18c(%rbp)
cmpl $-0x1, -0x158(%rbp)
je 0x3658
movq -0xb0(%rbp), %rdi
movq -0x188(%rbp), %rsi
movslq -0x18c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movl -0x158(%rbp), %edx
callq 0x2430
movl %eax, -0x158(%rbp)
movl -0x18c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18c(%rbp)
movl -0x18c(%rbp), %eax
cmpl -0x17c(%rbp), %eax
jne 0x3653
movl -0x17c(%rbp), %eax
shll %eax
movl %eax, -0x17c(%rbp)
movq -0x188(%rbp), %rdi
movslq -0x17c(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1200
movq %rax, -0x188(%rbp)
jmp 0x35d4
movl -0x18c(%rbp), %eax
addl -0x10c(%rbp), %eax
movl %eax, -0x10c(%rbp)
movq -0x188(%rbp), %rdi
movslq -0x18c(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1200
movq %rax, -0x188(%rbp)
movq $0x0, -0x198(%rbp)
movq $0x0, -0x1a0(%rbp)
movl $0x0, -0x1a4(%rbp)
movl $0x0, -0x1a8(%rbp)
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jge 0x37f9
movl 0x7acc(%rip), %eax      # 0xb1a0
cmpl $0x1, %eax
jne 0x36de
jmp 0x37f9
movq -0x140(%rbp), %rax
movq (%rax), %rdi
movq -0x188(%rbp), %rax
movslq -0x1ac(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl -0xc(%rbp), %edx
callq 0x72d0
movq %rax, %rcx
movq -0x188(%rbp), %rax
movslq -0x1ac(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x188(%rbp), %rax
movslq -0x1ac(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1a8(%rbp), %rdx
callq 0x23e0
movq -0x188(%rbp), %rax
movslq -0x1ac(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x376e
jmp 0x37e5
movq -0x198(%rbp), %rdx
movl -0x1a8(%rbp), %ecx
leaq -0x1a0(%rbp), %rdi
leaq -0x1a4(%rbp), %rsi
callq 0x3e10
movl $0x0, -0x1b0(%rbp)
movl -0x1b0(%rbp), %eax
cmpl -0x1a8(%rbp), %eax
jge 0x37ce
movq -0x198(%rbp), %rax
movslq -0x1b0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x3798
movq -0x198(%rbp), %rdi
callq 0x1030
movq $0x0, -0x198(%rbp)
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x36bc
movq $0x0, -0x1c0(%rbp)
movq $0x0, -0x1c8(%rbp)
movl 0x798b(%rip), %eax      # 0xb1a0
cmpl $0x0, %eax
jne 0x3aa5
movl $0x0, -0x1cc(%rbp)
movl -0x1cc(%rbp), %eax
cmpl -0x1a4(%rbp), %eax
jge 0x3a79
movq -0x138(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq (%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x1110
movq %rax, -0x218(%rbp)
movq -0x1a0(%rbp), %rax
movslq -0x1cc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
callq 0x45e0
movl %eax, %ecx
movq -0x218(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movl %eax, -0x1b4(%rbp)
movq -0x138(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq (%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1110
movq %rax, %rcx
addq $0x3, %rcx
movslq -0x1b4(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x1b4(%rbp)
movslq -0x1b4(%rbp), %rdi
shlq $0x0, %rdi
callq 0x11e0
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rdi
movq -0x138(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq (%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x1080
movq -0x1c0(%rbp), %rdi
leaq 0x4978(%rip), %rsi      # 0x82cb
callq 0x1280
movq -0x1a0(%rbp), %rax
movslq -0x1cc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
callq 0x4620
movq %rax, -0x1c8(%rbp)
movq -0x1c0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
callq 0x1280
movq -0x1c0(%rbp), %rdi
leaq 0x492e(%rip), %rsi      # 0x82cb
callq 0x1280
movq -0x1c0(%rbp), %rdi
movq -0x138(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq (%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x1a0(%rbp), %rcx
movslq -0x1cc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1280
movq -0x1c0(%rbp), %rax
movl -0x1b4(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x1c0(%rbp), %rsi
movslq -0x1b4(%rbp), %rdx
callq 0x10c0
movslq -0x1b4(%rbp), %rcx
cmpq %rcx, %rax
je 0x3a37
leaq 0x48a6(%rip), %rdi      # 0x82d8
callq 0x1260
movq -0x1c8(%rbp), %rdi
callq 0x1030
movq $0x0, -0x1c8(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x1030
movq $0x0, -0x1c0(%rbp)
movl -0x1cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x3828
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x48ad(%rip), %rsi      # 0x8334
movl $0x7, %edx
callq 0x10c0
cmpq $0x7, %rax
je 0x3aa3
leaq 0x484d(%rip), %rdi      # 0x82eb
callq 0x1260
jmp 0x3aa5
movl $0x0, -0x1d0(%rbp)
movl -0x1d0(%rbp), %eax
cmpl -0x1a4(%rbp), %eax
jge 0x3ae5
movq -0x1a0(%rbp), %rax
movslq -0x1d0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
movl -0x1d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d0(%rbp)
jmp 0x3aaf
movq -0x1a0(%rbp), %rdi
callq 0x1030
movl $0x0, -0x1d4(%rbp)
movl -0x1d4(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jge 0x3c0e
movq $0x0, -0x1e0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x11c0
leaq -0xe0(%rbp), %rdi
callq 0x1040
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rcx
movl $0x1a, %esi
leaq 0x471b(%rip), %rdx      # 0x826c
callq 0x1220
movq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq -0x188(%rbp), %rax
movslq -0x1d4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0x477b(%rip), %rsi      # 0x82fe
movb $0x0, %al
callq 0x1180
movq -0x188(%rbp), %rax
movslq -0x1d4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x2390
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x1e0(%rbp)
jne 0x3bd0
movq -0x130(%rbp), %rdi
leaq 0x489e(%rip), %rsi      # 0x8465
movb $0x0, %al
callq 0x1180
jmp 0x3bf8
movq -0x130(%rbp), %rdi
movq -0x1e0(%rbp), %rdx
leaq 0x46ac(%rip), %rsi      # 0x8291
movb $0x0, %al
callq 0x1180
movq -0x1e0(%rbp), %rdi
callq 0x1030
jmp 0x3bfa
movl -0x1d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d4(%rbp)
jmp 0x3afb
movl $0x0, -0x1e4(%rbp)
movl -0x1e4(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jge 0x3c54
movq -0x188(%rbp), %rax
movslq -0x1e4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x1030
movl -0x1e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x3c18
movq -0x188(%rbp), %rdi
callq 0x1030
movq -0xb8(%rbp), %rdi
callq 0x1030
jmp 0x3c6e
jmp 0x3c70
jmp 0x3c72
movq -0xb0(%rbp), %rdi
callq 0x1030
jmp 0x2f28
movl $0x0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
cmpl -0x144(%rbp), %eax
jge 0x3d51
movl $0x0, -0x1ec(%rbp)
movl -0x1ec(%rbp), %eax
movq -0x138(%rbp), %rcx
movslq -0x1e8(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jge 0x3d02
movq -0x138(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x1ec(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
movl -0x1ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ec(%rbp)
jmp 0x3ca9
movq -0x138(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x1030
movq -0x138(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x1030
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x3c8d
movq -0x138(%rbp), %rdi
callq 0x1030
movq -0x140(%rbp), %rax
movq (%rax), %rdi
callq 0x2140
movq -0x140(%rbp), %rdi
callq 0x1030
movq -0x128(%rbp), %rdi
callq 0x1030
movq -0x130(%rbp), %rdi
callq 0x10f0
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x45aa(%rip), %rsi      # 0x8348
movl $0xe, %edx
callq 0x10c0
cmpq $0xe, %rax
je 0x3dbc
leaq 0x455a(%rip), %rdi      # 0x830f
movb $0x0, %al
callq 0x1120
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x1130
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
callq 0x1130
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x1030
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1030
movq -0x8(%rbp), %rdi
callq 0x1030
movl -0x10c(%rbp), %edi
callq 0x12a0
nopw %cs:(%rax,%rax)