// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl %esi, -0x50(%rbp)
movq %rdi, -0x40(%rbp)
leaq -0x52(%rip), %rax       # 0x3148
leaq -0x180(%rbp), %rdi
movq %rax, -0x8(%rdi)
andl $0x0, 0x80(%rdi)
callq 0x21c0
pushq $0x2
popq %rdi
leaq -0x188(%rbp), %rsi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x31d2
leaq 0x3f73(%rip), %rdi      # 0x7140
callq 0x2280
pushq $0x3
popq %rdi
leaq -0x188(%rbp), %rsi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x31f3
leaq 0x3f66(%rip), %rdi      # 0x7154
callq 0x2280
pushq $0xf
popq %rdi
leaq -0x188(%rbp), %rsi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3214
leaq 0x3f5a(%rip), %rdi      # 0x7169
callq 0x2280
pushq $0xa
popq %rdi
leaq -0x188(%rbp), %rsi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3235
leaq 0x3f4e(%rip), %rdi      # 0x717e
callq 0x2280
pushq $0xd
popq %rdi
leaq -0x188(%rbp), %rsi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3256
leaq 0x3f42(%rip), %rdi      # 0x7193
callq 0x2280
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
callq 0x20e0
movl %eax, %edi
callq 0x43e9
movq %rax, %rbx
callq 0x20e0
movl %eax, %edi
callq 0x43c3
addl $0x31, %eax
movslq %eax, %rdi
callq 0x2200
movq %rax, %r14
movups 0x3f18(%rip), %xmm0     # 0x71a8
movups %xmm0, (%rax)
movups 0x3f1e(%rip), %xmm0     # 0x71b8
movups %xmm0, 0x10(%rax)
movups 0x3f23(%rip), %xmm0     # 0x71c8
movups %xmm0, 0x20(%rax)
movb $0x0, 0x30(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x22a0
movq %rbx, %rdi
callq 0x2030
leaq 0x40a2(%rip), %rsi      # 0x7369
movq %r14, -0xc0(%rbp)
movq %r14, %rdi
callq 0x2270
testq %rax, %rax
jne 0x32ef
leaq 0x3ef7(%rip), %rdi      # 0x71d9
callq 0x2280
pushq $0x31
popq %rdi
callq 0x22c0
movq %rax, -0x60(%rbp)
pushq $0x18
popq %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, %r13
movq %rbx, %rdi
callq 0x2200
movq %rax, %rbx
pushq $0x61
popq %rdi
callq 0x2ca8
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rbx, -0x80(%rbp)
andl $0x0, 0x10(%rbx)
movq $0x0, -0x98(%rbp)
xorl %r15d, %r15d
movl $0x101, %edi            # imm = 0x101
callq 0x2200
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x431e
movl %eax, %r14d
movl %eax, %edi
leaq 0x3e7e(%rip), %rsi      # 0x71df
pushq $0xc
popq %rdx
callq 0x4300
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3e79(%rip), %rsi      # 0x71f0
callq 0x2180
movl $0x0, -0x70(%rbp)
testl %eax, %eax
jne 0x3397
movl $0x1, 0x6e23(%rip)      # 0xa1b4
pushq $0x1
popq %rax
movl %eax, -0x70(%rbp)
movq %rbx, %rdi
leaq 0x3e5d(%rip), %rsi      # 0x71fe
callq 0x2180
testl %r14d, %r14d
je 0x33af
testl %eax, %eax
jne 0x33ca
movq %rbx, %rdi
leaq 0x3e4b(%rip), %rsi      # 0x7204
callq 0x2180
testl %eax, %eax
je 0x33ca
pushq $0x1
popq %rbx
jmp 0x3552
movq %rbx, %rdi
callq 0x2110
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x353d
movq -0x98(%rbp), %rcx
leal 0x1(%rcx), %eax
movl %eax, -0x68(%rbp)
cltq
imulq $0x18, %rax, %rax
movq %rax, -0x88(%rbp)
movq %rcx, -0x98(%rbp)
movslq %ecx, %rax
imulq $0x18, %rax, %rax
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdi
callq 0x21f0
testq %rax, %rax
je 0x352e
movq %rax, %r14
cmpb $0x8, 0x12(%rax)
jne 0x340b
movq %r13, %rdi
movq -0x88(%rbp), %rsi
callq 0x2220
movq %rax, %r12
movq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x2120
movq %rax, %rbx
addq $0x13, %r14
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
addl %ebx, %r15d
shlq $0x20, %r15
movabsq $0x200000000, %rax      # imm = 0x200000000
leaq (%r15,%rax), %rdi
sarq $0x20, %rdi
callq 0x2200
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %r13
callq 0x2080
movq %rbx, %rdi
callq 0x2120
movw $0x2f, (%rbx,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
sarq $0x20, %r15
movb $0x0, (%rbx,%r15)
movq -0x78(%rbp), %rax
leaq (%r12,%rax), %rdx
addq $0x10, %rdx
movq %r12, %r14
addq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x242c
testl %eax, %eax
jns 0x34f3
leaq 0x3d4f(%rip), %rdi      # 0x722b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2130
movq %rbx, %rdi
callq 0x2030
jmp 0x340b
movq -0x80(%rbp), %r15
addl %eax, 0xc(%r15)
movl 0x10(%r14), %esi
addl %esi, 0x10(%r15)
movq %rbx, 0x8(%r14)
movq (%r14), %rdi
movq %rbx, %rdx
movq -0x98(%rbp), %rcx
movq %r15, %r8
movl -0x50(%rbp), %r9d
callq 0x30ab
addl %eax, 0x8(%r15)
movl -0x68(%rbp), %eax
movl %eax, %ecx
jmp 0x33e6
movq -0x48(%rbp), %rdi
callq 0x2150
pushq $0x1
popq %r15
jmp 0x354f
movq -0x38(%rbp), %rsi
leaq 0x3cc9(%rip), %rdi      # 0x7211
xorl %eax, %eax
callq 0x2130
movl -0x70(%rbp), %ebx
movq -0x38(%rbp), %rdi
callq 0x2030
andq $0x0, -0x38(%rbp)
testl %ebx, %ebx
je 0x3332
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x3d9b(%rip), %rsi      # 0x7311
pushq $0x7
popq %rdx
callq 0x20d0
cmpq $0x7, %rax
je 0x3590
leaq 0x3d47(%rip), %rdi      # 0x72d2
callq 0x2280
movq $0x0, -0xa8(%rbp)
movl %r15d, -0x4c(%rbp)
movq %r13, -0x78(%rbp)
movl $0x101, %edi            # imm = 0x101
callq 0x2200
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x431e
testl %eax, %eax
jns 0x35d4
movl $0x1, 0x6be0(%rip)      # 0xa1b4
movl 0x6bda(%rip), %eax      # 0xa1b4
cmpl $0x1, %eax
jne 0x35e9
movq -0x38(%rbp), %rax
movl $0x657962, (%rax)       # imm = 0x657962
callq 0x22b0
cmpl $0x1, %eax
jne 0x35fd
movl $0x1, 0x6bb7(%rip)      # 0xa1b4
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3be5(%rip), %rsi      # 0x71f0
callq 0x2180
testl %eax, %eax
jne 0x361e
movl $0x1, 0x6b96(%rip)      # 0xa1b4
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x2e08
movl %eax, %r12d
movq -0x30(%rbp), %r14
movq %r14, %rdi
leaq 0x3c0b(%rip), %rsi      # 0x7248
callq 0x2180
testl %eax, %eax
je 0x3e7a
movl 0x6b64(%rip), %eax      # 0xa1b4
cmpl $0x1, %eax
je 0x3e7a
movq %r14, %rdi
leaq 0x3beb(%rip), %rsi      # 0x724e
callq 0x2180
testl %eax, %eax
je 0x38bf
movq %r14, %rdi
leaq 0x3c01(%rip), %rsi      # 0x727b
callq 0x2180
testl %eax, %eax
je 0x3738
movq %r14, %rdi
leaq 0x3bf0(%rip), %rsi      # 0x7281
callq 0x2180
testl %eax, %eax
je 0x3738
movq %r14, %rdi
leaq 0x3c0e(%rip), %rsi      # 0x72b6
callq 0x2180
testl %eax, %eax
jne 0x3a5b
movl $0x0, 0x6af9(%rip)      # 0xa1b8
movl $0x80, %edi
callq 0x2200
movq %rax, %rbx
movq $0x0, -0x88(%rbp)
pushq $0x1
popq %r14
xorl %r13d, %r13d
movq $0x0, -0x48(%rbp)
pushq $0x8
popq %r15
cmpl $-0x1, %r12d
je 0x3ab5
movq -0x38(%rbp), %rdi
leaq (%rbx,%r13), %rsi
movl %r12d, %edx
callq 0x2e08
movl %eax, %r12d
movl %r15d, %eax
cmpq %rax, %r14
jne 0x3724
addl %r15d, %r15d
movslq %r15d, %rsi
shlq $0x4, %rsi
movq %rbx, %rdi
callq 0x2220
movq %rax, %rbx
decq -0x48(%rbp)
addq $0x10, %r13
incq %r14
incq -0x88(%rbp)
jmp 0x36ea
movq %r14, %rdi
leaq 0x3b3f(%rip), %rsi      # 0x7281
callq 0x2180
movl %eax, %r15d
movq %r14, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %r12d, %edx
callq 0x2e08
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %ecx, %ecx
testl %r15d, %r15d
setne %cl
leaq 0x3b21(%rip), %r14      # 0x729d
leaq 0x3b04(%rip), %rax      # 0x7287
cmovneq %rax, %r14
movl -0x50(%rbp), %edx
callq 0x5f61
movq %rax, %rbx
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
callq 0x21e0
movq %r15, %rdi
callq 0x2040
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
pushq $0x1a
popq %rsi
leaq 0x3a95(%rip), %rdx      # 0x7252
movq %rax, %rcx
callq 0x2240
movq -0x30(%rbp), %rcx
movq -0x60(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21a0
movq -0x30(%rbp), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x5c18
testq %rax, %rax
je 0x3a15
movq %rbx, %rdi
callq 0x5c18
movq %rax, %rdi
callq 0x2120
movq %rax, %r14
movq %rbx, %rdi
callq 0x5c21
movl %eax, %edi
callq 0x43c3
addl %r14d, %eax
addl $0x2, %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x5c21
movl %eax, %edi
callq 0x43e9
movq %rax, %r15
movq -0x30(%rbp), %r12
movq %rbx, %rdi
callq 0x5c18
movq %r12, %rdi
movq %rax, %rsi
callq 0x2080
movq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x2120
movw $0x20, (%r12,%rax)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x22a0
movq %r15, %rdi
callq 0x2030
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
callq 0x20d0
cmpq %r14, %rax
jne 0x3e47
movq -0x30(%rbp), %rdx
movq -0x60(%rbp), %rdi
leaq 0x39d1(%rip), %rsi      # 0x7277
xorl %eax, %eax
callq 0x21a0
movq -0x30(%rbp), %rdi
callq 0x2030
movl -0x4c(%rbp), %r15d
jmp 0x3a53
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
callq 0x21e0
movq %rbx, %rdi
callq 0x2040
leaq -0xf0(%rbp), %rdi
pushq $0x1a
popq %rsi
leaq 0x396b(%rip), %rdx      # 0x7252
movq %rax, %rcx
callq 0x2240
movq -0x30(%rbp), %rdi
callq 0x2030
andq $0x0, -0x30(%rbp)
testl %r15d, %r15d
je 0x3a69
movq -0x80(%rbp), %r12
movl 0xc(%r12), %edi
callq 0x43c3
movl %eax, %ebx
movl 0x8(%r12), %edi
callq 0x43c3
movl %eax, %r14d
movl 0x10(%r12), %edi
callq 0x43c3
addl %ebx, %r14d
addl %r14d, %eax
addl $0x3, %eax
movslq %eax, %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
movl 0xc(%r12), %edi
callq 0x43e9
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x2080
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x2120
movw $0x20, %cx
movw %cx, (%r15,%rax)
movq %r14, %rdi
callq 0x2030
movl 0x8(%r12), %edi
callq 0x43e9
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x22a0
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x2120
movw $0x20, %cx
movw %cx, (%r15,%rax)
movq %r14, %rdi
callq 0x2030
movl 0x10(%r12), %edi
movl -0x4c(%rbp), %r15d
callq 0x43e9
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2030
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x30(%rbp), %rsi
movq %rbx, %rdx
callq 0x20d0
cmpq %rbx, %rax
jne 0x3aa4
movq -0x30(%rbp), %rcx
movq -0x60(%rbp), %rdi
leaq 0x3863(%rip), %rsi      # 0x7264
leaq -0xf0(%rbp), %rdx
xorl %eax, %eax
callq 0x21a0
movq -0x30(%rbp), %rdi
jmp 0x3a56
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x3905(%rip), %rsi      # 0x7328
pushq $0x2
popq %r14
movq %r14, %rdx
callq 0x20d0
cmpq $0x2, %rax
movl -0x4c(%rbp), %r15d
jne 0x3e58
leaq 0x386f(%rip), %rdi      # 0x72b3
movq %r14, %rsi
pushq $0x1
popq %rdx
movq -0x60(%rbp), %rcx
callq 0x22d0
movq %rbx, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
jmp 0x35a3
pushq $0x6
popq %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
movl $0x20302030, (%rax)     # imm = 0x20302030
movw $0x30, 0x4(%rax)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x388f(%rip), %rsi      # 0x7321
movq %rbx, %rdx
callq 0x20d0
cmpq $0x6, %rax
je 0x39f2
leaq 0x3827(%rip), %rdi      # 0x72d2
callq 0x2280
jmp 0x39f2
movq -0xa8(%rbp), %rax
movl %eax, %eax
movq -0x48(%rbp), %r12
subq %r12, %rax
movq %rax, -0xa8(%rbp)
movabsq $0xffffffff0, %rax      # imm = 0xFFFFFFFF0
andq %rax, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2220
andq $0x0, -0xa0(%rbp)
andq $0x0, -0xb0(%rbp)
andl $0x0, -0x8c(%rbp)
andl $0x0, -0x54(%rbp)
movq %rax, -0x68(%rbp)
negq %r12
movq %r12, -0x48(%rbp)
xorl %r12d, %r12d
movq -0x78(%rbp), %r13
cmpq %r12, -0x48(%rbp)
je 0x3bba
movl 0x6697(%rip), %eax      # 0xa1b8
cmpl $0x1, %eax
je 0x3bba
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq %r12, %r14
shlq $0x4, %r14
movq -0x68(%rbp), %r15
movq (%r15,%r14), %rsi
movl -0x50(%rbp), %edx
callq 0x6049
movq %rax, %rbx
movq %rax, 0x8(%r15,%r14)
movq %rax, %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x54(%rbp), %rdx
callq 0x2deb
testq %rbx, %rbx
je 0x3bb2
movq -0xa0(%rbp), %rdx
movl -0x54(%rbp), %ecx
leaq -0xb0(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
callq 0x3f6a
xorl %ebx, %ebx
movslq -0x54(%rbp), %rax
movq -0xa0(%rbp), %rdi
cmpq %rax, %rbx
jge 0x3ba5
movq (%rdi,%rbx,8), %rdi
callq 0x2030
incq %rbx
jmp 0x3b87
callq 0x2030
andq $0x0, -0xa0(%rbp)
incq %r12
jmp 0x3b11
movl -0x8c(%rbp), %r14d
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
cmpl $0x0, 0x65e4(%rip)      # 0xa1b8
movq -0xb0(%rbp), %r15
jne 0x3d49
xorl %eax, %eax
movq %r14, -0xc8(%rbp)
movq %r15, -0x70(%rbp)
cmpq %rax, %r14
je 0x3d25
movq (%r15,%rax,8), %r14
movq %rax, %r13
movq %rax, -0x48(%rbp)
movslq (%r14), %rax
imulq $0x18, %rax, %rax
movq -0x78(%rbp), %rcx
movq 0x8(%rcx,%rax), %rdi
movq %rcx, %r12
callq 0x2120
movq %rax, %rbx
movl 0x4(%r14), %edi
incl %edi
callq 0x43c3
movl %eax, %r14d
movq (%r15,%r13,8), %rax
movslq (%rax), %rcx
imulq $0x18, %rcx, %r15
movq (%r12,%r15), %rcx
movq %r12, %r13
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rdi
callq 0x2120
addl %r14d, %ebx
addl %ebx, %eax
addl $0x3, %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x2200
movq %rax, %r12
movq 0x8(%r13,%r15), %rsi
movq %rax, %rdi
callq 0x2080
movq %r12, %rdi
callq 0x2120
movw $0x20, %r15w
movw %r15w, (%r12,%rax)
movq -0x70(%rbp), %rax
movq -0x48(%rbp), %rbx
movq (%rax,%rbx,8), %rax
movl 0x4(%rax), %edi
incl %edi
callq 0x43e9
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
callq 0x22a0
movq %r12, %rdi
callq 0x2120
movw %r15w, (%r12,%rax)
movq -0x70(%rbp), %r15
movq (%r15,%rbx,8), %rax
movslq (%rax), %rcx
imulq $0x18, %rcx, %rcx
movq -0x78(%rbp), %rdx
movq (%rdx,%rcx), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x22a0
movb $0x0, -0x1(%r12,%r14)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x20d0
cmpq %r14, %rax
jne 0x3d17
movq %r13, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
movq -0x48(%rbp), %rax
incq %rax
movq -0xc8(%rbp), %r14
jmp 0x3bee
leaq 0x35a0(%rip), %rdi      # 0x72be
callq 0x2280
jmp 0x3cf4
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x35e6(%rip), %rsi      # 0x7319
pushq $0x7
popq %rdx
callq 0x20d0
cmpq $0x7, %rax
movq -0x78(%rbp), %r13
jne 0x3e69
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x3d5e
movq (%r15,%rbx,8), %rdi
callq 0x2030
incq %rbx
jmp 0x3d4b
movq %r15, %rdi
callq 0x2030
movq -0x68(%rbp), %r14
addq $0x8, %r14
movq -0x88(%rbp), %r12
movq -0x60(%rbp), %rbx
subq $0x1, %r12
jb 0x3e16
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
callq 0x21e0
movq %r15, %rdi
callq 0x2040
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
pushq $0x1a
popq %rsi
leaq 0x34a4(%rip), %rdx      # 0x7252
movq %rax, %rcx
callq 0x2240
movq -0x8(%r14), %rcx
movq %rbx, %rdi
leaq 0x3520(%rip), %rsi      # 0x72e4
movq %r15, %rdx
xorl %eax, %eax
callq 0x21a0
movq (%r14), %rdi
callq 0x2dcf
movq %rbx, %r15
testq %rax, %rax
je 0x3dff
movq %rax, %rbx
movq %r15, %rdi
leaq 0x348c(%rip), %rsi      # 0x7277
movq %rax, %rdx
xorl %eax, %eax
callq 0x21a0
movq %rbx, %rdi
callq 0x2030
jmp 0x3e0a
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x2160
movq %r15, %rbx
addq $0x10, %r14
jmp 0x3d79
movq -0x68(%rbp), %rbx
movl -0x4c(%rbp), %r15d
movq -0x88(%rbp), %r14
subq $0x1, %r14
jb 0x3e39
movq (%rbx), %rdi
callq 0x2030
addq $0x10, %rbx
jmp 0x3e25
movq -0x68(%rbp), %rdi
callq 0x2030
jmp 0x3a0f
leaq 0x3484(%rip), %rdi      # 0x72d2
callq 0x2280
jmp 0x3897
leaq 0x3473(%rip), %rdi      # 0x72d2
callq 0x2280
jmp 0x3a3d
leaq 0x3461(%rip), %rdi      # 0x72d1
callq 0x2280
jmp 0x3d49
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
xorl %ebx, %ebx
movq -0x98(%rbp), %r12
testl %r12d, %r12d
cmovlel %ebx, %r12d
cmpq %r12, %rbx
je 0x3ed8
imulq $0x18, %rbx, %r14
addq %r13, %r14
xorl %r15d, %r15d
movslq 0x10(%r14), %rax
movq (%r14), %rdi
cmpq %rax, %r15
jge 0x3ec5
movq (%rdi,%r15,8), %rdi
callq 0x2030
incq %r15
jmp 0x3eab
callq 0x2030
movq 0x8(%r14), %rdi
callq 0x2030
incq %rbx
jmp 0x3e9c
movq %r13, %rdi
callq 0x2030
movq -0x80(%rbp), %rbx
movq (%rbx), %rdi
callq 0x2ccd
movq %rbx, %rdi
callq 0x2030
movq -0xc0(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rdi
callq 0x2100
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x3414(%rip), %rsi      # 0x732b
pushq $0xe
popq %rdx
callq 0x20d0
cmpq $0xe, %rax
je 0x3f31
leaq 0x33c9(%rip), %rdi      # 0x72f5
callq 0x20a0
movq -0x40(%rbp), %rbx
movl 0x8(%rbx), %edi
callq 0x2140
movl 0x18(%rbx), %edi
callq 0x2140
movq (%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2030
movq -0xa8(%rbp), %rdi
callq 0x22c0