// File: /workspace/github_c_makefile_star2_O3/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, -0x6c(%rbp)
movq %rdi, -0x40(%rbp)
leaq -0x52(%rip), %rax       # 0x331c
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 0x33ab
leaq 0x3d9a(%rip), %rdi      # 0x7140
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0x3, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x33ce
leaq 0x3d8b(%rip), %rdi      # 0x7154
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xf, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x33f1
leaq 0x3d7d(%rip), %rdi      # 0x7169
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xa, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3414
leaq 0x3d6f(%rip), %rdi      # 0x717e
callq 0x2290
leaq -0x188(%rbp), %rsi
movl $0xd, %edi
xorl %edx, %edx
callq 0x20b0
testl %eax, %eax
jns 0x3437
leaq 0x3d61(%rip), %rdi      # 0x7193
callq 0x2290
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
callq 0x20e0
movl %eax, %edi
callq 0x46c9
movq %rax, %rbx
callq 0x20e0
movl %eax, %edi
callq 0x469a
addl $0x31, %eax
movslq %eax, %rdi
callq 0x2210
movq %rax, %r14
movups 0x3d37(%rip), %xmm0     # 0x71a8
movups %xmm0, (%rax)
movups 0x3d3d(%rip), %xmm0     # 0x71b8
movups %xmm0, 0x10(%rax)
movups 0x3d42(%rip), %xmm0     # 0x71c8
movups %xmm0, 0x20(%rax)
movb $0x0, 0x30(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x22b0
movq %rbx, %rdi
callq 0x2030
leaq 0x3ec1(%rip), %rsi      # 0x7369
movq %r14, -0xb8(%rbp)
movq %r14, %rdi
callq 0x2280
testq %rax, %rax
jne 0x34d2
leaq 0x3d16(%rip), %rdi      # 0x71d9
callq 0x2290
movl $0x31, %edi
callq 0x22d0
movq %rax, -0x78(%rbp)
movl $0x18, %edi
callq 0x2210
movq %rax, %r12
movl $0x18, %edi
callq 0x2210
movq %rax, %rbx
movl $0x61, %edi
callq 0x2e20
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movq %rbx, -0x88(%rbp)
movl $0x0, 0x10(%rbx)
xorl %r14d, %r14d
movl $0x0, -0x4c(%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 0x45da
movl %eax, %r14d
movl %eax, %edi
leaq 0x3c90(%rip), %rsi      # 0x71df
movl $0xc, %edx
callq 0x45bc
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3c89(%rip), %rsi      # 0x71f0
callq 0x2190
xorl %ecx, %ecx
testl %eax, %eax
jne 0x3581
movl $0x1, 0x6c40(%rip)      # 0xa1bc
movl $0x1, %ecx
movl %ecx, -0x58(%rbp)
movq %rbx, %rdi
leaq 0x3c70(%rip), %rsi      # 0x71fe
callq 0x2190
testl %r14d, %r14d
je 0x359c
testl %eax, %eax
jne 0x35bb
movq %rbx, %rdi
leaq 0x3c5e(%rip), %rsi      # 0x7204
callq 0x2190
testl %eax, %eax
je 0x35bb
movl $0x1, -0x58(%rbp)
jmp 0x3776
movq %rbx, %rdi
callq 0x2110
testq %rax, %rax
je 0x3764
movq %rax, %rbx
movq %rax, %rdi
callq 0x2200
movq %rax, %r14
movl %r15d, %r13d
testq %rax, %rax
movq %rbx, -0x80(%rbp)
je 0x3782
leal 0x1(%r15), %ecx
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x68(%rbp)
movq %r15, -0x60(%rbp)
movslq %r15d, %rax
movq %rax, -0x48(%rbp)
movl %ecx, -0x4c(%rbp)
cmpb $0x8, 0x12(%r14)
jne 0x3701
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 -0x48(%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 0x370a
leaq 0x3b56(%rip), %rdi      # 0x722b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2130
movq %rbx, %rdi
callq 0x2030
movq -0x80(%rbp), %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, %r14
testq %rax, %rax
jne 0x360b
jmp 0x377b
movq -0x60(%rbp), %rax
movl %eax, %r13d
jmp 0x374a
movq -0x88(%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 -0x60(%rbp), %rcx
movq %r15, %r8
movl -0x6c(%rbp), %r9d
callq 0x324d
addl %eax, 0x8(%r15)
movl -0x4c(%rbp), %r13d
movl %r13d, %eax
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rbx
movq %rbx, %rdi
callq 0x2200
movq %rax, %r14
testq %rax, %rax
movq -0x60(%rbp), %r15
jne 0x35ea
jmp 0x3782
movq -0x38(%rbp), %rsi
leaq 0x3aa2(%rip), %rdi      # 0x7211
xorl %eax, %eax
callq 0x2130
movq %r15, %r14
jmp 0x3794
movq -0x60(%rbp), %rax
movl %eax, %r13d
movq %rbx, %rdi
callq 0x2160
movl $0x1, -0x4c(%rbp)
movl %r13d, %r14d
movq -0x38(%rbp), %rdi
callq 0x2030
movq $0x0, -0x38(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x351d
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x3b54(%rip), %rsi      # 0x7311
movl $0x7, %edx
callq 0x20d0
cmpq $0x7, %rax
je 0x37d9
leaq 0x3afe(%rip), %rdi      # 0x72d2
callq 0x2290
movl $0x0, -0x94(%rbp)
movq %r12, -0x48(%rbp)
movq %r14, -0x60(%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 0x45da
testl %eax, %eax
jns 0x381c
movl $0x1, 0x69a0(%rip)      # 0xa1bc
movl 0x699a(%rip), %eax      # 0xa1bc
cmpl $0x1, %eax
jne 0x3831
movq -0x38(%rbp), %rax
movl $0x657962, (%rax)       # imm = 0x657962
callq 0x22c0
cmpl $0x1, %eax
jne 0x3845
movl $0x1, 0x6977(%rip)      # 0xa1bc
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x399d(%rip), %rsi      # 0x71f0
callq 0x2190
testl %eax, %eax
jne 0x3866
movl $0x1, 0x6956(%rip)      # 0xa1bc
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x2f84
movl %eax, %ebx
movq -0x30(%rbp), %r14
movq %r14, %rdi
leaq 0x39c4(%rip), %rsi      # 0x7248
callq 0x2190
testl %eax, %eax
je 0x4115
movl 0x6925(%rip), %eax      # 0xa1bc
cmpl $0x1, %eax
je 0x4115
movq %r14, %rdi
leaq 0x39a4(%rip), %rsi      # 0x724e
callq 0x2190
testl %eax, %eax
je 0x3af8
movq %r14, %rdi
leaq 0x39ba(%rip), %rsi      # 0x727b
callq 0x2190
testl %eax, %eax
je 0x396d
movq %r14, %rdi
leaq 0x39a9(%rip), %rsi      # 0x7281
callq 0x2190
testl %eax, %eax
je 0x396d
movq %r14, %rdi
leaq 0x39c7(%rip), %rsi      # 0x72b6
callq 0x2190
testl %eax, %eax
jne 0x3c99
movl $0x0, 0x68ba(%rip)      # 0xa1c0
movl $0x80, %edi
callq 0x2210
movq %rax, %r14
cmpl $-0x1, %ebx
je 0x3cf4
movl $0x8, %r15d
movl $0x1, %r12d
xorl %r13d, %r13d
movq -0x38(%rbp), %rdi
leaq (%r14,%r13), %rsi
movl %ebx, %edx
callq 0x2f84
movl %eax, %ebx
movl %r15d, %eax
cmpq %rax, %r12
jne 0x3959
addl %r15d, %r15d
movslq %r15d, %rsi
shlq $0x4, %rsi
movq %r14, %rdi
callq 0x2230
movq %rax, %r14
addq $0x10, %r13
incq %r12
cmpl $-0x1, %ebx
jne 0x392b
decl %r12d
jmp 0x3cf7
movq %r14, %rdi
leaq 0x390a(%rip), %rsi      # 0x7281
callq 0x2190
movl %eax, %r15d
movq %r14, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %ebx, %edx
callq 0x2f84
movq -0x88(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %ecx, %ecx
testl %r15d, %r15d
setne %cl
leaq 0x38ea(%rip), %r14      # 0x729d
leaq 0x38cd(%rip), %rax      # 0x7287
cmovneq %rax, %r14
movl -0x6c(%rbp), %edx
callq 0x6519
movq %rax, %rbx
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
callq 0x21f0
movq %r15, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
leaq 0x385c(%rip), %rdx      # 0x7252
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 0x6180
testq %rax, %rax
je 0x3c55
movq %rbx, %rdi
callq 0x6180
movq %rax, %rdi
callq 0x2120
movq %rax, %r14
movq %rbx, %rdi
callq 0x6189
movl %eax, %edi
callq 0x469a
addl %r14d, %eax
addl $0x2, %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x6189
movl %eax, %edi
callq 0x46c9
movq %rax, %r15
movq -0x30(%rbp), %r12
movq %rbx, %rdi
callq 0x6180
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 0x3f84
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %rdi
leaq 0x3798(%rip), %rsi      # 0x7277
xorl %eax, %eax
callq 0x21b0
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %r12
jmp 0x3c91
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %rdi
leaq 0x3730(%rip), %rdx      # 0x7252
movq %rax, %rcx
callq 0x2250
movq -0x30(%rbp), %rdi
callq 0x2030
movq $0x0, -0x30(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x3ca7
movq -0x88(%rbp), %r12
movl 0xc(%r12), %edi
callq 0x469a
movl %eax, %ebx
movl 0x8(%r12), %edi
callq 0x469a
movl %eax, %r14d
movl 0x10(%r12), %edi
callq 0x469a
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 0x46c9
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 0x46c9
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 -0x48(%rbp), %r12
callq 0x46c9
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 0x3ce3
movq -0x30(%rbp), %rcx
movq -0x78(%rbp), %rdi
leaq 0x3623(%rip), %rsi      # 0x7264
leaq -0xf0(%rbp), %rdx
xorl %eax, %eax
callq 0x21b0
movq -0x30(%rbp), %rdi
jmp 0x3c94
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x2, %edx
leaq 0x36c0(%rip), %rsi      # 0x7328
callq 0x20d0
cmpq $0x2, %rax
jne 0x40f3
movl $0x2, %esi
movl $0x1, %edx
leaq 0x362b(%rip), %rdi      # 0x72b3
movq -0x78(%rbp), %rcx
callq 0x22e0
movq %rbx, %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
jmp 0x37eb
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 0x364d(%rip), %rsi      # 0x7321
callq 0x20d0
cmpq $0x6, %rax
je 0x3c32
leaq 0x35e8(%rip), %rdi      # 0x72d2
callq 0x2290
jmp 0x3c32
xorl %r12d, %r12d
movl %r12d, %r13d
movq %r13, -0x80(%rbp)
shlq $0x4, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x2230
movq %rax, %r15
xorl %eax, %eax
movq %rax, -0x90(%rbp)
movq %rax, -0xa0(%rbp)
movl %eax, -0x98(%rbp)
movl %eax, -0x50(%rbp)
testl %r12d, %r12d
movq %r15, -0x68(%rbp)
je 0x3f6a
xorl %ebx, %ebx
movl 0x6482(%rip), %eax      # 0xa1c0
cmpl $0x1, %eax
je 0x3df2
movq -0x88(%rbp), %rax
movq (%rax), %rdi
movq %rbx, %r15
shlq $0x4, %r15
movq -0x68(%rbp), %rax
movq (%rax,%r15), %rsi
movl -0x6c(%rbp), %edx
callq 0x660e
movq %rax, %r14
movq -0x68(%rbp), %rax
movq %r14, 0x8(%rax,%r15)
movq %r14, %rdi
leaq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x2f68
testq %r14, %r14
je 0x3de5
movq -0x90(%rbp), %rdx
movl -0x50(%rbp), %ecx
leaq -0xa0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4211
cmpl $0x0, -0x50(%rbp)
jle 0x3dce
xorl %r14d, %r14d
movq -0x90(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2030
incq %r14
movslq -0x50(%rbp), %rax
cmpq %rax, %r14
jl 0x3db2
movq -0x90(%rbp), %rdi
callq 0x2030
movq $0x0, -0x90(%rbp)
incq %rbx
cmpq -0x80(%rbp), %rbx
jne 0x3d38
movl -0x98(%rbp), %r15d
cmpl $0x0, 0x63c0(%rip)      # 0xa1c0
jne 0x3fc3
testl %r15d, %r15d
jle 0x3fa1
movq %r13, -0xc0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x58(%rbp)
xorl %ebx, %ebx
movq %r15, -0xc8(%rbp)
movq -0x58(%rbp), %rax
movq (%rax,%rbx,8), %r15
movq %rax, %r13
movslq (%r15), %rax
leaq (%rax,%rax,2), %rax
movq -0x48(%rbp), %rcx
movq 0x8(%rcx,%rax,8), %rdi
callq 0x2120
movq %rax, %r14
movl 0x4(%r15), %edi
incl %edi
callq 0x469a
movl %eax, -0xa8(%rbp)
movq (%r13,%rbx,8), %rax
movslq (%rax), %rcx
leaq (%rcx,%rcx,2), %r15
movq -0x48(%rbp), %r13
movq (%r13,%r15,8), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rdi
callq 0x2120
addl -0xa8(%rbp), %r14d
addl %r14d, %eax
addl $0x3, %eax
movslq %eax, %rdi
movq %rdi, -0xa8(%rbp)
callq 0x2210
movq %rax, %r14
movq 0x8(%r13,%r15,8), %rsi
movq %rax, %rdi
callq 0x2080
movq %r14, %rdi
callq 0x2120
movw $0x20, %cx
movw %cx, (%r14,%rax)
movq -0x58(%rbp), %r13
movq (%r13,%rbx,8), %rax
movl 0x4(%rax), %edi
incl %edi
callq 0x46c9
movq %rax, %r15
movq %r14, %rdi
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 -0x48(%rbp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x22b0
movq -0xa8(%rbp), %rdx
movb $0x0, -0x1(%r14,%rdx)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movq %r14, %rsi
movq %rdx, %r13
callq 0x20d0
cmpq %r13, %rax
jne 0x3f5c
movq %r15, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
incq %rbx
movq -0xc8(%rbp), %r15
cmpq %rbx, %r15
jne 0x3e2a
jmp 0x3f95
leaq 0x335b(%rip), %rdi      # 0x72be
callq 0x2290
jmp 0x3f37
cmpl $0x0, 0x624f(%rip)      # 0xa1c0
je 0x3f9e
movq -0xa0(%rbp), %rdi
callq 0x2030
jmp 0x40d2
leaq 0x3347(%rip), %rdi      # 0x72d2
callq 0x2290
jmp 0x3ad0
movq -0xc0(%rbp), %r13
jmp 0x3fa1
xorl %r15d, %r15d
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x7, %edx
leaq 0x3365(%rip), %rsi      # 0x7319
callq 0x20d0
cmpq $0x7, %rax
jne 0x4104
movq -0xa0(%rbp), %r14
testl %r15d, %r15d
jle 0x3fe6
movl %r15d, %ebx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2030
incq %r15
cmpq %r15, %rbx
jne 0x3fd5
movq %r14, %rdi
callq 0x2030
cmpq $0x0, -0x80(%rbp)
movq -0x78(%rbp), %r14
movq -0x68(%rbp), %r15
je 0x40d2
movq %r12, -0x58(%rbp)
xorl %ebx, %ebx
movq %r13, %r12
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
callq 0x21f0
movq %r15, %rdi
callq 0x2040
movl $0x1a, %esi
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
leaq 0x321b(%rip), %rdx      # 0x7252
movq %rax, %rcx
callq 0x2250
movq -0x68(%rbp), %r13
movq (%r13,%rbx), %rcx
movq %r14, %rdi
leaq 0x3292(%rip), %rsi      # 0x72e4
movq %r15, %rdx
xorl %eax, %eax
callq 0x21b0
movq 0x8(%r13,%rbx), %rdi
callq 0x2f4c
movq %r14, %r15
testq %rax, %rax
je 0x408f
movq %rax, %r14
movq %r15, %rdi
leaq 0x31fc(%rip), %rsi      # 0x7277
movq %rax, %rdx
xorl %eax, %eax
callq 0x21b0
movq %r14, %rdi
callq 0x2030
jmp 0x409c
movl $0xa, %edi
movq %r15, %rsi
callq 0x2170
movq %r15, %r14
movq %r12, %r13
addq $0x10, %rbx
cmpq %rbx, %r12
jne 0x4007
cmpq $0x0, -0x80(%rbp)
movq -0x68(%rbp), %r15
movq -0x58(%rbp), %r12
je 0x40d2
xorl %ebx, %ebx
movq (%r15,%rbx), %rdi
callq 0x2030
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0x40c0
addl %r12d, -0x94(%rbp)
movq %r15, %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %r12
jmp 0x3c99
leaq 0x31d8(%rip), %rdi      # 0x72d2
callq 0x2290
jmp 0x3c77
leaq 0x31c6(%rip), %rdi      # 0x72d1
callq 0x2290
jmp 0x3fc3
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rax
testl %eax, %eax
jle 0x417b
movl %eax, %ebx
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
leaq (%r12,%rax,8), %r15
cmpl $0x0, 0x10(%r15)
jle 0x415e
xorl %r12d, %r12d
movq (%r15), %rax
movq (%rax,%r12,8), %rdi
callq 0x2030
incq %r12
movslq 0x10(%r15), %rax
cmpq %rax, %r12
jl 0x4146
movq (%r15), %rdi
callq 0x2030
movq 0x8(%r15), %rdi
callq 0x2030
incq %r14
cmpq %rbx, %r14
movq -0x48(%rbp), %r12
jne 0x4134
movq %r12, %rdi
callq 0x2030
movq -0x88(%rbp), %rbx
movq (%rbx), %rdi
callq 0x2e4a
movq %rbx, %rdi
callq 0x2030
movq -0xb8(%rbp), %rdi
callq 0x2030
movq -0x78(%rbp), %rdi
callq 0x2100
movq -0x40(%rbp), %rax
movl 0x18(%rax), %edi
leaq 0x316e(%rip), %rsi      # 0x732b
movl $0xe, %edx
callq 0x20d0
cmpq $0xe, %rax
je 0x41d9
leaq 0x3121(%rip), %rdi      # 0x72f5
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