// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq %rdi, -0x40(%rbp)
leaq -0x52(%rip), %rax       # 0x32ec
leaq -0x180(%rbp), %rdi
movq %rax, -0x8(%rdi)
movl $0x0, 0x80(%rdi)
callq 0x21d0
leaq -0x188(%rbp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x337b
leaq 0x3dd3(%rip), %rdi      # 0x7149
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0x3, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x339e
leaq 0x3dc4(%rip), %rdi      # 0x715d
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xf, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x33c1
leaq 0x3db6(%rip), %rdi      # 0x7172
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xa, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x33e4
leaq 0x3da8(%rip), %rdi      # 0x7187
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xd, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3407
leaq 0x3d9a(%rip), %rdi      # 0x719c
callq 0x2290
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
callq 0x20e0
movl %eax, %edi
callq 0x4675
movq %rax, %rbx
callq 0x20e0
movl %eax, %edi
callq 0x4646
addl $0x31, %eax
movslq %eax, %rdi
callq 0x2210
movq %rax, %r15
movups 0x3d70(%rip), %xmm0     # 0x71b1
movups %xmm0, (%rax)
movups 0x3d76(%rip), %xmm0     # 0x71c1
movups %xmm0, 0x10(%rax)
movups 0x3d7b(%rip), %xmm0     # 0x71d1
movups %xmm0, 0x20(%rax)
movb $0x0, 0x30(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x22b0
movq %rbx, %rdi
callq 0x2030
leaq 0x3b98(%rip), %rsi      # 0x7010
movq %r15, -0xc0(%rbp)
movq %r15, %rdi
callq 0x2280
movq %rax, -0x78(%rbp)
testq %rax, %rax
jne 0x34a6
leaq 0x3d4b(%rip), %rdi      # 0x71e2
callq 0x2290
movl $0x31, %edi
callq 0x22d0
movl %r14d, -0x44(%rbp)
movl $0x18, %edi
callq 0x2210
movq %rax, %r12
movl $0x18, %edi
callq 0x2210
movq %rax, %rbx
movl $0x61, %edi
callq 0x2dd8
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movq %rbx, -0x80(%rbp)
movl $0x0, 0x10(%rbx)
xorl %r14d, %r14d
movl $0x0, -0x98(%rbp)
movq %r14, %r15
movl $0x101, %edi            # imm = 0x101
callq 0x2210
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x4586
movl %eax, %r14d
movl %eax, %edi
leaq 0x3cc5(%rip), %rsi      # 0x71e8
movl $0xc, %edx
callq 0x4568
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3cbe(%rip), %rsi      # 0x71f9
callq 0x2190
xorl %ecx, %ecx
testl %eax, %eax
jne 0x3555
movl $0x1, 0x6c6c(%rip)      # 0xa1bc
movl $0x1, %ecx
movl %ecx, -0x88(%rbp)
movq %rbx, %rdi
leaq 0x3ca2(%rip), %rsi      # 0x7207
callq 0x2190
testl %r14d, %r14d
je 0x3573
testl %eax, %eax
jne 0x3595
movq %rbx, %rdi
leaq 0x3c90(%rip), %rsi      # 0x720d
callq 0x2190
testl %eax, %eax
je 0x3595
movl $0x1, -0x88(%rbp)
jmp 0x3753
movq %rbx, %rdi
callq 0x2110
testq %rax, %rax
je 0x3741
movq %rax, %rbx
movq %rax, %rdi
callq 0x2200
movq %rax, %r14
movl %r15d, %r13d
testq %rax, %rax
movq %rbx, -0x58(%rbp)
je 0x375f
leal 0x1(%r15), %ecx
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x68(%rbp)
movq %r15, -0x50(%rbp)
movslq %r15d, %rax
movq %rax, -0x60(%rbp)
movl %ecx, -0xa8(%rbp)
cmpb $0x8, 0x12(%r14)
jne 0x36de
movq %r12, %rdi
movq -0x68(%rbp), %rsi
callq 0x2230
movq %rax, %r13
movq -0x38(%rbp), %r12
movq %r12, %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 0x2210
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %r12
callq 0x2080
movq %rbx, %rdi
callq 0x2120
movw $0x2f, (%rbx,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22b0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
sarq $0x20, %r15
movb $0x0, (%rbx,%r15)
movq -0x60(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq (,%rax,8), %r14
addq %r13, %r14
leaq 0x10(,%rax,8), %rdx
addq %r13, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x249c
testl %eax, %eax
jns 0x36e7
leaq 0x3b82(%rip), %rdi      # 0x7234
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2130
movq %rbx, %rdi
callq 0x2030
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, %r14
testq %rax, %rax
jne 0x35e8
jmp 0x3758
movq -0x50(%rbp), %rax
movl %eax, %r13d
jmp 0x3727
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 -0x50(%rbp), %rcx
movq %r15, %r8
movl -0x44(%rbp), %r9d
callq 0x321e
addl %eax, 0x8(%r15)
movl -0xa8(%rbp), %r13d
movl %r13d, %eax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, %r14
testq %rax, %rax
movq -0x50(%rbp), %r15
jne 0x35c4
jmp 0x375f
movq -0x38(%rbp), %rsi
leaq 0x3ace(%rip), %rdi      # 0x721a
xorl %eax, %eax
callq 0x2130
movq %r15, %r14
jmp 0x3774
movq -0x50(%rbp), %rax
movl %eax, %r13d
movq %rbx, %rdi
callq 0x2160
movl $0x1, -0x98(%rbp)
movl %r13d, %r14d
movq -0x38(%rbp), %rdi
callq 0x2030
movq $0x0, -0x38(%rbp)
cmpl $0x0, -0x88(%rbp)
je 0x34f1
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x3b7a(%rip), %rsi      # 0x731a
movl $0x7, %edx
callq 0x20d0
cmpq $0x7, %rax
je 0x37bc
leaq 0x3b24(%rip), %rdi      # 0x72db
callq 0x2290
movl $0x0, -0x94(%rbp)
movq %r12, -0x60(%rbp)
movq %r14, -0x50(%rbp)
movl $0x101, %edi            # imm = 0x101
callq 0x2210
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x4586
testl %eax, %eax
jns 0x37ff
movl $0x1, 0x69bd(%rip)      # 0xa1bc
movl 0x69b7(%rip), %eax      # 0xa1bc
cmpl $0x1, %eax
jne 0x3814
movq -0x38(%rbp), %rax
movl $0x657962, (%rax)       # imm = 0x657962
callq 0x22c0
cmpl $0x1, %eax
jne 0x3828
movl $0x1, 0x6994(%rip)      # 0xa1bc
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x39c3(%rip), %rsi      # 0x71f9
callq 0x2190
testl %eax, %eax
jne 0x3849
movl $0x1, 0x6973(%rip)      # 0xa1bc
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x2f3c
movl %eax, %ebx
movq -0x30(%rbp), %r14
movq %r14, %rdi
leaq 0x39ea(%rip), %rsi      # 0x7251
callq 0x2190
testl %eax, %eax
je 0x40c1
movl 0x6942(%rip), %eax      # 0xa1bc
cmpl $0x1, %eax
je 0x40c1
movq %r14, %rdi
leaq 0x39ca(%rip), %rsi      # 0x7257
callq 0x2190
testl %eax, %eax
je 0x3ae0
movq %r14, %rdi
leaq 0x39e0(%rip), %rsi      # 0x7284
callq 0x2190
testl %eax, %eax
je 0x3958
movq %r14, %rdi
leaq 0x39cf(%rip), %rsi      # 0x728a
callq 0x2190
testl %eax, %eax
je 0x3958
movq %r14, %rdi
leaq 0x39ed(%rip), %rsi      # 0x72bf
callq 0x2190
testl %eax, %eax
jne 0x3c81
movl $0x0, 0x68d7(%rip)      # 0xa1c0
movl $0x80, %edi
callq 0x2210
movq %rax, %r14
cmpl $-0x1, %ebx
je 0x3cdc
movl $0x8, %r15d
movl $0x1, %eax
xorl %r12d, %r12d
movq -0x38(%rbp), %rdi
leaq (%r14,%r12), %rsi
movl %ebx, %edx
movq %rax, %r13
callq 0x2f3c
movl %eax, %ebx
movl %r15d, %eax
cmpq %rax, %r13
jne 0x393e
addl %r15d, %r15d
movslq %r15d, %rsi
shlq $0x4, %rsi
movq %r14, %rdi
callq 0x2230
movq %rax, %r14
movq %r13, %rax
addq $0x10, %r12
incq %rax
cmpl $-0x1, %ebx
jne 0x390d
decl %eax
movq -0x60(%rbp), %r12
jmp 0x3cde
movq %r14, %rdi
leaq 0x3928(%rip), %rsi      # 0x728a
callq 0x2190
movl %eax, %r15d
movq %r14, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %ebx, %edx
callq 0x2f3c
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %ecx, %ecx
testl %r15d, %r15d
setne %cl
leaq 0x390b(%rip), %r14      # 0x72a6
leaq 0x38ee(%rip), %rax      # 0x7290
cmovneq %rax, %r14
movl -0x44(%rbp), %edx
callq 0x63a9
movq %rax, %rbx
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
callq 0x21f0
movq %r15, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
leaq 0x387d(%rip), %rdx      # 0x725b
movq %rax, %rcx
callq 0x2250
movq -0x30(%rbp), %rcx
movq -0x78(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21b0
movq -0x30(%rbp), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x6018
testq %rax, %rax
je 0x3c3d
movq %rbx, %rdi
callq 0x6018
movq %rax, %rdi
callq 0x2120
movq %rax, %r14
movq %rbx, %rdi
callq 0x6021
movl %eax, %edi
callq 0x4646
addl %r14d, %eax
addl $0x2, %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x6021
movl %eax, %edi
callq 0x4675
movq %rax, %r15
movq -0x30(%rbp), %r12
movq %rbx, %rdi
callq 0x6018
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 0x22b0
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 0x408e
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %rdi
leaq 0x37b9(%rip), %rsi      # 0x7280
xorl %eax, %eax
callq 0x21b0
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %r12
jmp 0x3c79
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %rdi
leaq 0x3751(%rip), %rdx      # 0x725b
movq %rax, %rcx
callq 0x2250
movq -0x30(%rbp), %rdi
callq 0x2030
movq $0x0, -0x30(%rbp)
cmpl $0x0, -0x98(%rbp)
je 0x3c8f
movq -0x80(%rbp), %r12
movl 0xc(%r12), %edi
callq 0x4646
movl %eax, %ebx
movl 0x8(%r12), %edi
callq 0x4646
movl %eax, %r14d
movl 0x10(%r12), %edi
callq 0x4646
addl %ebx, %r14d
addl %r14d, %eax
addl $0x3, %eax
movslq %eax, %rbx
movq %rbx, %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
movl 0xc(%r12), %edi
callq 0x4675
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x2080
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x2120
movw $0x20, %r13w
movw %r13w, (%r15,%rax)
movq %r14, %rdi
callq 0x2030
movl 0x8(%r12), %edi
callq 0x4675
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x22b0
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x2120
movw %r13w, (%r15,%rax)
movq -0x40(%rbp), %r15
movq %r14, %rdi
callq 0x2030
movl 0x10(%r12), %edi
movq -0x60(%rbp), %r12
callq 0x4675
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2030
movl 0x18(%r15), %edi
movq -0x30(%rbp), %rsi
movq %rbx, %rdx
callq 0x20d0
cmpq %rbx, %rax
jne 0x3ccb
movq -0x30(%rbp), %rcx
movq -0x78(%rbp), %rdi
leaq 0x3644(%rip), %rsi      # 0x726d
leaq -0xf0(%rbp), %rdx
xorl %eax, %eax
callq 0x21b0
movq -0x30(%rbp), %rdi
jmp 0x3c7c
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x2, %edx
leaq 0x36e1(%rip), %rsi      # 0x7331
callq 0x20d0
cmpq $0x2, %rax
jne 0x409f
movl $0x2, %esi
movl $0x1, %edx
leaq 0x364c(%rip), %rdi      # 0x72bc
movq -0x78(%rbp), %rcx
callq 0x22e0
movq %rbx, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
jmp 0x37ce
movl $0x6, %edi
callq 0x2210
movq %rax, -0x30(%rbp)
movl $0x20302030, (%rax)     # imm = 0x20302030
movw $0x30, 0x4(%rax)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x6, %edx
leaq 0x366e(%rip), %rsi      # 0x732a
callq 0x20d0
cmpq $0x6, %rax
je 0x3c1a
leaq 0x3609(%rip), %rdi      # 0x72db
callq 0x2290
jmp 0x3c1a
xorl %eax, %eax
movl %eax, %r13d
movq %r13, %rsi
shlq $0x4, %rsi
movq %r14, %rdi
movq %rax, %rbx
callq 0x2230
movq %rax, -0x68(%rbp)
xorl %eax, %eax
movq %rax, -0x90(%rbp)
movq %rax, -0xa0(%rbp)
movl %eax, -0x6c(%rbp)
movl %eax, -0x48(%rbp)
movq %rbx, -0xb0(%rbp)
testl %ebx, %ebx
movl -0x44(%rbp), %r14d
je 0x3dd9
xorl %ebx, %ebx
movl 0x6498(%rip), %eax      # 0xa1c0
cmpl $0x1, %eax
je 0x3dd9
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq %rbx, %r15
shlq $0x4, %r15
movq -0x68(%rbp), %rax
movq (%rax,%r15), %rsi
movl %r14d, %edx
callq 0x64ae
movq %rax, %r14
movq -0x68(%rbp), %rax
movq %r14, 0x8(%rax,%r15)
movq %r14, %rdi
leaq -0x90(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x2f20
testq %r14, %r14
je 0x3dc9
movq -0x90(%rbp), %rdx
movl -0x48(%rbp), %ecx
leaq -0xa0(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x41ba
cmpl $0x0, -0x48(%rbp)
jle 0x3db2
xorl %r14d, %r14d
movq -0x90(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2030
incq %r14
movslq -0x48(%rbp), %rax
cmpq %rax, %r14
jl 0x3d96
movq -0x90(%rbp), %rdi
callq 0x2030
movq $0x0, -0x90(%rbp)
incq %rbx
cmpq %r13, %rbx
movl -0x44(%rbp), %r14d
jne 0x3d22
cmpl $0x0, 0x63e0(%rip)      # 0xa1c0
jne 0x3f67
movq %r13, -0x58(%rbp)
movslq -0x6c(%rbp), %rax
movq %rax, -0xc8(%rbp)
testq %rax, %rax
jle 0x3f41
movq -0xa0(%rbp), %rax
movq %rax, -0x88(%rbp)
xorl %ebx, %ebx
movq -0x88(%rbp), %rax
movq (%rax,%rbx,8), %r15
movq %rax, %r13
movslq (%r15), %rax
leaq (%rax,%rax,2), %rax
movq 0x8(%r12,%rax,8), %rdi
callq 0x2120
movq %rax, %r14
movl 0x4(%r15), %edi
incl %edi
callq 0x4646
movl %eax, %r15d
movq (%r13,%rbx,8), %rax
movslq (%rax), %rcx
leaq (%rcx,%rcx,2), %r13
movq (%r12,%r13,8), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rdi
callq 0x2120
addl %r15d, %r14d
addl %r14d, %eax
addl $0x3, %eax
movq %r12, %r15
movslq %eax, %r12
movq %r12, %rdi
callq 0x2210
movq %rax, %r14
movq 0x8(%r15,%r13,8), %rsi
movq %rax, %rdi
callq 0x2080
movq %r14, %rdi
callq 0x2120
movw $0x20, %cx
movw %cx, (%r14,%rax)
movq -0x88(%rbp), %r13
movq (%r13,%rbx,8), %rax
movl 0x4(%rax), %edi
incl %edi
callq 0x4675
movq %r14, %rdi
movq %rax, -0xa8(%rbp)
movq %rax, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2120
movw $0x20, %cx
movw %cx, (%r14,%rax)
movq (%r13,%rbx,8), %rax
movslq (%rax), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%r15,%rcx,8), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x22b0
movb $0x0, -0x1(%r14,%r12)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x20d0
cmpq %r12, %rax
jne 0x3f33
movq -0xa8(%rbp), %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
incq %rbx
cmpq %rbx, -0xc8(%rbp)
movq -0x60(%rbp), %r12
jne 0x3e0e
jmp 0x3f41
leaq 0x338d(%rip), %rdi      # 0x72c7
callq 0x2290
jmp 0x3f09
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x7, %edx
leaq 0x33ce(%rip), %rsi      # 0x7322
callq 0x20d0
cmpq $0x7, %rax
movq -0x58(%rbp), %r13
jne 0x40b0
movslq -0x6c(%rbp), %rbx
testq %rbx, %rbx
jle 0x3f8b
movq -0xa0(%rbp), %r14
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2030
incq %r15
cmpq %r15, %rbx
jne 0x3f7a
movq -0xa0(%rbp), %rdi
callq 0x2030
cmpl $0x0, -0xb0(%rbp)
movq -0x78(%rbp), %r14
movq -0x68(%rbp), %r15
je 0x4074
shlq $0x4, %r13
xorl %ebx, %ebx
movq %r13, -0x58(%rbp)
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
callq 0x21f0
movq %r15, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
leaq 0x3278(%rip), %rdx      # 0x725b
movq %rax, %rcx
callq 0x2250
movq -0x68(%rbp), %r13
movq (%r13,%rbx), %rcx
movq %r14, %rdi
leaq 0x32ef(%rip), %rsi      # 0x72ed
movq %r15, %rdx
xorl %eax, %eax
callq 0x21b0
movq 0x8(%r13,%rbx), %rdi
callq 0x2f04
movq %r14, %r15
testq %rax, %rax
je 0x403b
movq %rax, %r14
movq %r15, %rdi
leaq 0x3259(%rip), %rsi      # 0x7280
movq %rax, %rdx
xorl %eax, %eax
callq 0x21b0
movq %r14, %rdi
callq 0x2030
jmp 0x4048
movl $0xa, %edi
movq %r15, %rsi
callq 0x2170
movq %r15, %r14
movq -0x58(%rbp), %r13
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0x3fb6
xorl %ebx, %ebx
movq -0x68(%rbp), %r15
movq (%r15,%rbx), %rdi
callq 0x2030
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0x4062
movq -0xb0(%rbp), %rax
addl %eax, -0x94(%rbp)
movq %r15, %rdi
callq 0x2030
jmp 0x3c37
leaq 0x3246(%rip), %rdi      # 0x72db
callq 0x2290
jmp 0x3ab8
leaq 0x3235(%rip), %rdi      # 0x72db
callq 0x2290
jmp 0x3c5f
leaq 0x3223(%rip), %rdi      # 0x72da
callq 0x2290
jmp 0x3f67
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x50(%rbp), %rax
testl %eax, %eax
jle 0x4127
movl %eax, %ebx
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
leaq (%r12,%rax,8), %r15
cmpl $0x0, 0x10(%r15)
jle 0x410a
xorl %r12d, %r12d
movq (%r15), %rax
movq (%rax,%r12,8), %rdi
callq 0x2030
incq %r12
movslq 0x10(%r15), %rax
cmpq %rax, %r12
jl 0x40f2
movq (%r15), %rdi
callq 0x2030
movq 0x8(%r15), %rdi
callq 0x2030
incq %r14
cmpq %rbx, %r14
movq -0x60(%rbp), %r12
jne 0x40e0
movq %r12, %rdi
callq 0x2030
movq -0x80(%rbp), %rbx
movq (%rbx), %rdi
callq 0x2e02
movq %rbx, %rdi
callq 0x2030
movq -0xc0(%rbp), %rdi
callq 0x2030
movq -0x78(%rbp), %rdi
callq 0x2100
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x31ce(%rip), %rsi      # 0x7334
movl $0xe, %edx
callq 0x20d0
cmpq $0xe, %rax
je 0x4182
leaq 0x3181(%rip), %rdi      # 0x72fe
callq 0x20a0
movq -0x40(%rbp), %rbx
movl 0x8(%rbx), %edi
callq 0x2150
movl 0x18(%rbx), %edi
callq 0x2150
movq (%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2030
movl -0x94(%rbp), %edi
callq 0x22d0