// File: /workspace/github_c_makefile_star2_O1/stefpant[P]TCPserver/webcrawler/webcrawler.c
// Function: main
int main(int argc,char* argv[]){
	int s_port,c_port;
	int n_threads = 5;//by default 5 threads
	char *savedir = NULL;
	char *hostid = NULL;
	pid_t pid;//for calling jobExec and in the end wait termination
	char *starting_url = NULL;
	int flagSHUTDOWN=0;//when set 1 exit
	int flagSEARCH=1;//first time(if crawler ready) call jobExecutor
	int FIFOfd,FIFOfd2;
	printf("Parent %ld: just started!\n", pthread_self());
//~~~~~~~~~~~~~~~~~~~~~~~~~~PARSE ARGUMENTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	if(input_parse(argc,argv,&s_port,&c_port,&n_threads,&savedir,&hostid,&starting_url) < 0){
		free(savedir);
		free(hostid);
		free(starting_url);
		exit(9);
	}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~INIT: pool,mutexes,conditions~~~~~~~~~~~~~~~~~~~~~~~
	urlpool_init(&up);

	pthread_mutex_init(&mtx, 0);
	pthread_mutex_init(&mtxwt, 0);
	pthread_mutex_init(&pumtx, 0);
	pthread_mutex_init(&mtxcounter, 0);
	pthread_mutex_init(&mtxbytes, 0);
	pthread_cond_init(&cv_notempty, 0);
	pthread_cond_init(&cv_notfull, 0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MAKING THREADS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	pthread_t *tids = NULL;
	tids = malloc(n_threads*sizeof(pthread_t));

	tdata *dat;//struct to send to threads
	dat = malloc(sizeof(tdata));
	dat->port = s_port;
	dat->savedir = malloc((strlen(savedir)+1)*sizeof(char));
	strcpy(dat->savedir,savedir);
	dat->hostname = malloc((strlen(hostid)+1)*sizeof(char));
	strcpy(dat->hostname,hostid);

	for(int i=0; i<n_threads; i++)//create threads to execute threadExec
		pthread_create(tids+i,NULL,threadExec, (void *)dat);

	printf("Parent %ld: just created new threads!\n", pthread_self());
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	pthread_mutex_lock(&pumtx);
	placedurls=malloc(sizeof(char*));
	pucounter++;
	placedurls[0]=starting_url;
	pthread_mutex_unlock(&pumtx);
	//place starting url in pool
	place(&up, starting_url);
	pthread_cond_signal(&cv_notempty);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	time_t start,localend;
	int hh,mm,ss;
	time(&start);//crawler started
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~MAKING SOCKETS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	int c_sock,newcsock;
	struct sockaddr_in server;
	struct sockaddr * serverptr = (struct sockaddr *)&server;
	if( (c_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) //socket for command port
		{perror("socket");exit(9);}
	server.sin_family = AF_INET;
	server.sin_addr.s_addr = htonl(INADDR_ANY);
	server.sin_port = htons(c_port);

	if( setsockopt(c_sock, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 },sizeof(int)) < 0 )
		{perror("setsockopt");exit(9);}
	if( bind(c_sock,serverptr,sizeof(server)) < 0 ){perror("bind");exit(9);}
	if( listen(c_sock,100) < 0 ){perror("listen");exit(9);}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~INIT POLL~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	struct pollfd pfd[1];
	pfd[0].fd = c_sock;
	pfd[0].events = POLLIN;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~LOOP:ACCEPTING CONNECTIONS~~~~~~~~~~~~~~~~~~~~~~~
	while( 1 ){//only on command port

		poll(pfd,1,-1);//wait a connection
		if(pfd[0].revents & POLLIN){//client on command port
			if( (newcsock = accept(c_sock,NULL,NULL)) < 0)
				{perror("accept");exit(9);}
			while(1){//1
				char *buf = malloc(9*sizeof(char));//should not be resized
				read_command(newcsock,&buf,9);
				if( !strcmp(buf,"STATS") ){
					time(&localend);
					localend -= start;
					hh = localend/3600;//creating time format
					localend -= hh*3600;
					mm = localend/60;
					ss = localend - mm*60;
					char* statrep=NULL;
					if(asprintf(&statrep,"Crawler up for %02d:%02d:%02d, downloaded %d pages, %d bytes\n",hh,mm,ss,totalrc,totalBytes) != -1){
						int len=strlen(statrep);
						write(newcsock,statrep,len+1);
						free(statrep);
					}
					//printf("Crawler up for %02d:%02d:%02d, downloaded %d pages, %d bytes\n",hh,mm,ss,totalrc,totalBytes);
				}
				else if( !strcmp(buf,"SHUTDOWN") ){
					close(newcsock);
					free(buf);
					flagSHUTDOWN=1;//2
					break;
				}
				else if( !strcmp(buf,"STOP") ){//3
					close(newcsock);//4
					free(buf);//5
					break;//6
				}//7
				else{
					char* ms=NULL;//maybe search command
					//printf("%s\n",buf);
					nextWord(buf,&ms,0);
					if( !strcmp(ms,"SEARCH") ){
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~check if crawling is over~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
						if( waitingThreads!=n_threads || up->count!=0 ){//pool not empty or some threads not waiting
							//printf("Crawling in progress,wait!\n");
							write(newcsock,"Crawling in progress,wait!\n",28);
							free(ms);free(buf);
							continue;
						}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
						
						if(flagSEARCH){//first time got SEARCH command,init some structs
							char* sdoc="docfile.txt";
							createDocfile(savedir,sdoc);
//~~~~~~~~~~~~~~~~~~~~fifo for crawler-jobExecutor communication~~~~~~~~~~~~~~~~~~~~~~
							if(mkfifo("../JECfifo",0666) == -1){
								if(errno != EEXIST){
									perror("mkfifo");
									exit(21);
								}
								else{//if fifo exists unlink it and make it again :-)
									unlink("../JECfifo");
									if(mkfifo("../JECfifo",0666) == -1){
										perror("mkfifo isn't working");
										exit(99);
									}
								}
							}
							if(mkfifo("../CJEfifo",0666) == -1){
								if(errno != EEXIST){
									perror("mkfifo");
									exit(21);
								}
								else{//if fifo exists unlink it and make it again :-)
									unlink("../CJEfifo");
									if(mkfifo("../CJEfifo",0666) == -1){
										perror("mkfifo isn't working");
										exit(99);
									}
								}
							}
							pid = fork();
							if(pid < 0){perror("fork");exit(87);}
							else if(pid == 0){//child call jobExecutor...
								close(newcsock);
								char *const args[]={//arguments for jobExecutor
												"../PantoulasStefanosProject2/jobExecutor",//executable
												"-d",//flag for docfile
												"docfile.txt",//docfile
												"-w",//flag for workers
												"5",//workers
												"-n",//flag for fifo names for C-jE communication
												"../JECfifo",//jE reads from C in this fifo
												"../CJEfifo",//C reads from jE in this fifo
												NULL};
								execv("../PantoulasStefanosProject2/jobExecutor",args);
								exit(54);//unexpected return here
							}
							//parent continue from here
							FIFOfd = open("../JECfifo",O_WRONLY);
							FIFOfd2 = open("../CJEfifo",O_RDONLY);
							flagSEARCH=0;//never again here
						}
						char* msg=malloc((strlen(buf)+9)*sizeof(char));
						strcpy(msg,buf);
						strcat(msg," -d 1000");//add the deadline

						write(FIFOfd,msg,strlen(msg)+1);
						free(msg);

						while( 1 ){
							char *ans = malloc(9*sizeof(char));//should not be resized
							read_command(FIFOfd2,&ans,9);//read jobExec answers
							if(!strcmp(ans,"_STOP_")){free(ans);break;}//no more results
							char *realans=malloc((strlen(ans)+2)*sizeof(char));
							strcpy(realans,ans);
							strcat(realans,"\n");
							write(newcsock,realans,strlen(ans)+2);//write ans to socket
							free(realans);
							free(ans);
						}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					}
					else
						write(newcsock,"Unknown command!\n",18);
					free(ms);
				}
				free(buf);
				//close(newcsock);//--8
			}
		}//9
		if(flagSHUTDOWN) break;//10
	}

	//clear pool and then place in pool exit msg
	urlpool_clear(&up);
	//here if i got SHUTDOWN command to send exit msg(sending "exit" in pool)
	for(int i=0; i<n_threads; i++){
		place(&up,"exit");
		pthread_cond_signal(&cv_notempty);
		printf("Parent: send stop!\n");
	}

	for(int i=0; i<n_threads; i++)
		 pthread_join(*(tids+i),NULL);//join threads

	if( !flagSEARCH ){//free struct from search
		write(FIFOfd,"/exit",6);
		close(FIFOfd);
		close(FIFOfd2);
	}

	//free structs
	pthread_mutex_destroy(&mtx);
	pthread_mutex_destroy(&mtxwt);
	pthread_mutex_destroy(&pumtx);
	pthread_mutex_destroy(&mtxcounter);
	pthread_mutex_destroy(&mtxbytes);
	pthread_cond_destroy(&cv_notempty);
	pthread_cond_destroy(&cv_notfull);
	urlpool_destroy(&up);
	destroyPU();
	free(dat->savedir);
	free(dat->hostname);
	free(savedir);
	free(hostid);
	free(tids);
	free(dat);
	if( !flagSEARCH ){//free other structs first to give jE some
		waitpid(pid,0,0);//time to exit and then
		unlink("../JECfifo");//unlink fifos
		unlink("../CJEfifo");
	}
	printf("Crawler about to exit!\n");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r15
movl %edi, %r12d
leaq -0x2c(%rbp), %rax
movl $0x5, (%rax)
xorl %eax, %eax
leaq -0x58(%rbp), %r13
movq %rax, (%r13)
leaq -0x68(%rbp), %rbx
movq %rax, (%rbx)
leaq -0x60(%rbp), %r14
movq %rax, (%r14)
callq 0x2290
leaq 0x1714(%rip), %rdi      # 0x51f3
movq %rax, -0x40(%rbp)
movq %rax, %rsi
xorl %eax, %eax
callq 0x2100
leaq -0x78(%rbp), %rdx
leaq -0x74(%rbp), %rcx
movl %r12d, %edi
movq %r15, %rsi
leaq -0x2c(%rbp), %r8
movq %r13, %r9
pushq %r14
pushq %rbx
callq 0x3053
addq $0x10, %rsp
testl %eax, %eax
js 0x43f0
movl $0x18, %edi
callq 0x2220
movq %rax, %r14
movq %rax, 0x378e(%rip)      # 0x72b8
movl $0x50, %edi
callq 0x2220
movq %rax, (%r14)
movq $0xa, 0x8(%r14)
movl $0xffffffff, 0x10(%r14) # imm = 0xFFFFFFFF
leaq 0x36ea(%rip), %rdi      # 0x7238
xorl %esi, %esi
callq 0x2360
leaq 0x3734(%rip), %rdi      # 0x7290
xorl %esi, %esi
callq 0x2360
leaq 0x36a6(%rip), %rdi      # 0x7210
xorl %esi, %esi
callq 0x2360
leaq 0x3778(%rip), %rdi      # 0x72f0
xorl %esi, %esi
callq 0x2360
leaq 0x3792(%rip), %rdi      # 0x7318
xorl %esi, %esi
callq 0x2360
leaq 0x36cc(%rip), %rdi      # 0x7260
xorl %esi, %esi
callq 0x21f0
leaq 0x371e(%rip), %rdi      # 0x72c0
xorl %esi, %esi
callq 0x21f0
movslq -0x2c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2220
movq %rax, %r13
movl $0x18, %edi
callq 0x2220
movq %rax, %rbx
movl -0x78(%rbp), %eax
movl %eax, (%rbx)
movq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0x20f0
leaq 0x1(%rax), %rdi
callq 0x2220
movq %rax, 0x10(%rbx)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
movq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x20f0
leaq 0x1(%rax), %rdi
callq 0x2220
movq %rax, 0x8(%rbx)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
cmpl $0x0, -0x2c(%rbp)
jle 0x3c46
xorl %r12d, %r12d
leaq -0x584(%rip), %r14      # 0x369f
movq %r13, %r15
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x2280
incq %r12
movslq -0x2c(%rbp), %rax
addq $0x8, %r15
cmpq %rax, %r12
jl 0x3c26
movq %rbx, -0x98(%rbp)
leaq 0x15ba(%rip), %rdi      # 0x520e
movq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x35aa(%rip), %rbx      # 0x7210
movq %rbx, %rdi
callq 0x2390
movl $0x8, %edi
callq 0x2220
incl 0x358a(%rip)            # 0x7208
movq %rax, 0x357b(%rip)      # 0x7200
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movq %rbx, %rdi
callq 0x2210
movq -0x60(%rbp), %rsi
leaq 0x3619(%rip), %rdi      # 0x72b8
callq 0x355d
leaq 0x35b5(%rip), %rdi      # 0x7260
callq 0x2160
leaq -0xa0(%rbp), %rdi
callq 0x21d0
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x23a0
testl %eax, %eax
js 0x4415
movl %eax, %r14d
movw $0x2, -0xb4(%rbp)
movzwl -0x74(%rbp), %eax
rolw $0x8, %ax
movl $0x0, -0xb0(%rbp)
movw %ax, -0xb2(%rbp)
leaq -0xa4(%rbp), %rcx
movl $0x1, (%rcx)
movl %r14d, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x441a
leaq -0xb4(%rbp), %rsi
movl %r14d, %edi
movl $0x10, %edx
callq 0x2270
testl %eax, %eax
js 0x441f
movq %r13, -0x90(%rbp)
movl %r14d, %edi
movl $0x64, %esi
callq 0x2230
testl %eax, %eax
js 0x4424
leaq -0x88(%rbp), %r15
movl %r14d, (%r15)
movw $0x1, 0x4(%r15)
movl $0x1, -0x30(%rbp)
leaq -0x50(%rbp), %rbx
leaq 0x14d1(%rip), %r13      # 0x5253
movl %r14d, -0x70(%rbp)
movl $0x1, %esi
movq %r15, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2260
movb $0x1, %al
testb $0x1, -0x82(%rbp)
je 0x41f5
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
testl %eax, %eax
js 0x4398
movl %eax, %r14d
movl $0x0, -0x40(%rbp)
movl $0x9, %edi
callq 0x2220
movq %rax, -0x50(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movl $0x9, %edx
callq 0x296d
movq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x2180
testl %eax, %eax
je 0x3e71
movq %r15, %rdi
leaq 0x1497(%rip), %rsi      # 0x5297
callq 0x2180
testl %eax, %eax
je 0x3f6e
movq %r15, %rdi
leaq 0x1489(%rip), %rsi      # 0x52a0
callq 0x2180
testl %eax, %eax
je 0x3f7f
movq $0x0, -0x48(%rbp)
movq %r15, %rdi
leaq -0x48(%rbp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0x2a24
movq -0x48(%rbp), %rdi
leaq 0x145d(%rip), %rsi      # 0x52a5
callq 0x2180
testl %eax, %eax
je 0x3f8c
movl $0x12, %edx
movl %r14d, %edi
leaq 0x14e8(%rip), %rsi      # 0x534c
callq 0x20b0
movb $0x1, %r13b
jmp 0x3fc7
leaq -0x80(%rbp), %rdi
callq 0x21d0
movq -0x80(%rbp), %r8
subq -0xa0(%rbp), %r8
movq %r8, %rax
movabsq $0x48d159e26af37c05, %rcx # imm = 0x48D159E26AF37C05
imulq %rcx
movq %rdx, %r10
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xa, %r10
addq %rax, %r10
movq %r10, %rax
movabsq $0xe1000000000, %rcx    # imm = 0xE1000000000
imulq %rcx, %rax
sarq $0x20, %rax
subq %rax, %r8
movq %r8, -0x80(%rbp)
movq %r8, %rax
movabsq $-0x7777777777777777, %rcx # imm = 0x8888888888888889
imulq %rcx
movq %rdx, %rcx
addq %r8, %rcx
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x5, %rcx
addq %rax, %rcx
movq %rcx, %rax
movabsq $0x3c00000000, %rdx     # imm = 0x3C00000000
imulq %rdx, %rax
shrq $0x20, %rax
subl %eax, %r8d
movq $0x0, -0x100(%rbp)
movl 0x32e0(%rip), %r9d      # 0x71f0
movl 0x32dd(%rip), %r11d     # 0x71f4
subq $0x8, %rsp
leaq -0x100(%rbp), %rdi
leaq 0x1330(%rip), %rsi      # 0x5259
movl %r10d, %edx
xorl %eax, %eax
pushq %r11
callq 0x2250
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x3f69
movq -0x100(%rbp), %r15
movq %r15, %rdi
callq 0x20f0
incl %eax
movslq %eax, %rdx
movl %r14d, %edi
movq %r15, %rsi
callq 0x20b0
movq -0x100(%rbp), %rdi
callq 0x2030
xorl %r15d, %r15d
jmp 0x3fde
movl %r14d, %edi
callq 0x2130
movl $0x1, -0x40(%rbp)
jmp 0x3f87
movl %r14d, %edi
callq 0x2130
movb $0x1, %r15b
jmp 0x3fde
movl 0x3266(%rip), %eax      # 0x71f8
cmpl -0x2c(%rbp), %eax
jne 0x3fa4
movq 0x331a(%rip), %rax      # 0x72b8
cmpl $0x0, 0xc(%rax)
je 0x3ff5
movl $0x1c, %edx
movl %r14d, %edi
leaq 0x12f9(%rip), %rsi      # 0x52ac
callq 0x20b0
movq -0x48(%rbp), %rdi
callq 0x2030
xorl %r13d, %r13d
movq %rbx, %r15
movq (%r15), %rdi
callq 0x2030
xorl %r15d, %r15d
testb %r13b, %r13b
leaq 0x1277(%rip), %r13      # 0x5253
je 0x3fe7
movq -0x50(%rbp), %rdi
callq 0x2030
testb %r15b, %r15b
je 0x3dc5
jmp 0x41e3
cmpl $0x0, -0x30(%rbp)
je 0x40d0
movq -0x58(%rbp), %rdi
leaq 0x12be(%rip), %rsi      # 0x52c8
callq 0x2e85
leaq 0x12be(%rip), %r15      # 0x52d4
movq %r15, %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
leaq 0x12ce(%rip), %r12      # 0x52fb
jne 0x405b
callq 0x2040
cmpl $0x11, (%rax)
jne 0x43dc
movq %r15, %rdi
callq 0x2050
movq %r15, %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
je 0x43eb
movq %r12, %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
jne 0x4099
callq 0x2040
cmpl $0x11, (%rax)
jne 0x43e1
movq %r12, %rdi
callq 0x2050
movq %r12, %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
je 0x43e6
callq 0x2380
testl %eax, %eax
js 0x43d7
movl %eax, -0x6c(%rbp)
je 0x439d
movq %r15, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x22c0
movl %eax, -0x34(%rbp)
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22c0
movl %eax, %r12d
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20f0
leaq 0x9(%rax), %rdi
callq 0x2220
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
movq %r13, %rdi
callq 0x20f0
movabsq $0x3030303120642d20, %rcx # imm = 0x3030303120642D20
movq %rcx, (%r13,%rax)
movb $0x0, 0x8(%r13,%rax)
movq %r13, %rdi
callq 0x20f0
leaq 0x1(%rax), %rdx
movl -0x34(%rbp), %edi
movq %r13, %rsi
callq 0x20b0
movq %r13, %rdi
callq 0x2030
movl $0x9, %edi
callq 0x2220
movq %rax, -0x100(%rbp)
movl %r12d, %edi
leaq -0x100(%rbp), %rsi
movl $0x9, %edx
callq 0x296d
movq -0x100(%rbp), %r15
movq %r15, %rdi
leaq 0x11e0(%rip), %rsi      # 0x5345
callq 0x2180
testl %eax, %eax
je 0x41c8
movq %r15, %rdi
callq 0x20f0
leaq 0x2(%rax), %rdi
callq 0x2220
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
movq %r13, %rdi
callq 0x20f0
movw $0xa, (%r13,%rax)
movq %r15, %rdi
callq 0x20f0
leaq 0x2(%rax), %rdx
movl %r14d, %edi
movq %r13, %rsi
callq 0x20b0
movq %r13, %rdi
callq 0x2030
movq -0x100(%rbp), %rdi
jmp 0x412a
movq %r15, %rdi
callq 0x2030
movb $0x1, %r13b
movl $0x0, -0x30(%rbp)
leaq -0x48(%rbp), %r15
jmp 0x3fc7
cmpl $0x0, -0x40(%rbp)
sete %al
movl -0x70(%rbp), %r14d
leaq -0x88(%rbp), %r15
testb %al, %al
jne 0x3d86
leaq 0x30b4(%rip), %rdi      # 0x72b8
callq 0x34d3
cmpl $0x0, -0x2c(%rbp)
jle 0x424c
xorl %ebx, %ebx
leaq 0x1147(%rip), %r14      # 0x535f
leaq 0x3041(%rip), %r15      # 0x7260
leaq 0x1189(%rip), %r13      # 0x53af
leaq 0x308b(%rip), %rdi      # 0x72b8
movq %r14, %rsi
callq 0x355d
movq %r15, %rdi
callq 0x2160
movq %r13, %rdi
callq 0x2090
incl %ebx
cmpl -0x2c(%rbp), %ebx
jl 0x4226
cmpl $0x0, -0x2c(%rbp)
movq -0x90(%rbp), %r14
jle 0x4272
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
xorl %esi, %esi
callq 0x2350
incq %rbx
movslq -0x2c(%rbp), %rax
cmpq %rax, %rbx
jl 0x425b
movl -0x30(%rbp), %r15d
testl %r15d, %r15d
jne 0x42a0
leaq 0x10dc(%rip), %rsi      # 0x535e
movl $0x6, %edx
movl -0x34(%rbp), %ebx
movl %ebx, %edi
callq 0x20b0
movl %ebx, %edi
callq 0x2130
movl %r12d, %edi
callq 0x2130
leaq 0x2f91(%rip), %rdi      # 0x7238
callq 0x2110
leaq 0x2fdd(%rip), %rdi      # 0x7290
callq 0x2110
leaq 0x2f51(%rip), %rdi      # 0x7210
callq 0x2110
leaq 0x3025(%rip), %rdi      # 0x72f0
callq 0x2110
leaq 0x3041(%rip), %rdi      # 0x7318
callq 0x2110
leaq 0x2f7d(%rip), %rdi      # 0x7260
callq 0x22b0
leaq 0x2fd1(%rip), %rdi      # 0x72c0
callq 0x22b0
movq 0x2fbd(%rip), %rax      # 0x72b8
movq (%rax), %rdi
callq 0x2030
movq 0x2fae(%rip), %rdi      # 0x72b8
callq 0x2030
callq 0x3455
movq -0x98(%rbp), %rbx
movq 0x10(%rbx), %rdi
callq 0x2030
movq 0x8(%rbx), %rdi
callq 0x2030
movq -0x58(%rbp), %rdi
callq 0x2030
movq -0x68(%rbp), %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2030
testl %r15d, %r15d
jne 0x4378
movl -0x6c(%rbp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22a0
leaq 0xf6d(%rip), %rdi       # 0x52d4
callq 0x2050
leaq 0xf88(%rip), %rdi       # 0x52fb
callq 0x2050
leaq 0x1019(%rip), %rdi      # 0x5398
callq 0x2090
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2498
movl %r14d, %edi
callq 0x2130
leaq 0x2a04(%rip), %rsi      # 0x6db0
leaq -0x100(%rbp), %rax
movl $0x9, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0xf46(%rip), %rdi       # 0x530b
movq %rax, %rsi
callq 0x2370
movl $0x36, %edi
callq 0x2330
callq 0x2450
callq 0x2420
callq 0x2438
callq 0x2468
callq 0x2480
movq -0x58(%rbp), %rdi
callq 0x2030
movq -0x68(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rdi
callq 0x2030
movl $0x9, %edi
callq 0x2330
callq 0x24f8
callq 0x24e0
callq 0x24c8
callq 0x24b0