// File: /workspace/github_c_makefile_star2_O0/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
subq $0x190, %rsp            # imm = 0x190
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x5, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x1, -0x48(%rbp)
callq 0x2290
movq %rax, %rsi
leaq 0xfc2(%rip), %rdi       # 0x5247
movb $0x0, %al
callq 0x2100
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x14(%rbp), %rdx
leaq -0x18(%rbp), %rcx
leaq -0x1c(%rbp), %r8
leaq -0x28(%rbp), %r9
leaq -0x30(%rbp), %r10
leaq -0x40(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x3360
cmpl $0x0, %eax
jge 0x42e3
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
callq 0x2030
movl $0x9, %edi
callq 0x2330
leaq 0x2fce(%rip), %rdi      # 0x72b8
callq 0x3970
leaq 0x2f42(%rip), %rdi      # 0x7238
xorl %eax, %eax
movl %eax, %esi
callq 0x2360
leaq 0x2f8a(%rip), %rdi      # 0x7290
xorl %eax, %eax
movl %eax, %esi
callq 0x2360
leaq 0x2efa(%rip), %rdi      # 0x7210
xorl %eax, %eax
movl %eax, %esi
callq 0x2360
leaq 0x2fca(%rip), %rdi      # 0x72f0
xorl %eax, %eax
movl %eax, %esi
callq 0x2360
leaq 0x2fe2(%rip), %rdi      # 0x7318
xorl %eax, %eax
movl %eax, %esi
callq 0x2360
leaq 0x2f1a(%rip), %rdi      # 0x7260
xorl %eax, %eax
movl %eax, %esi
callq 0x21f0
leaq 0x2f6a(%rip), %rdi      # 0x72c0
xorl %eax, %eax
movl %eax, %esi
callq 0x21f0
movq $0x0, -0x58(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2220
movq %rax, -0x58(%rbp)
movl $0x18, %edi
callq 0x2220
movq %rax, -0x60(%rbp)
movl -0x14(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x2220
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x2070
movq -0x30(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x2220
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x2070
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4436
movq -0x58(%rbp), %rdi
movslq -0x64(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x60(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x796(%rip), %rdx      # 0x3c90
callq 0x2280
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x4400
callq 0x2290
movq %rax, %rsi
leaq 0xe1d(%rip), %rdi       # 0x5262
movb $0x0, %al
callq 0x2100
leaq 0x2dbd(%rip), %rdi      # 0x7210
callq 0x2390
movl $0x8, %edi
callq 0x2220
movq %rax, 0x2d97(%rip)      # 0x7200
movl 0x2d99(%rip), %eax      # 0x7208
addl $0x1, %eax
movl %eax, 0x2d90(%rip)      # 0x7208
movq -0x40(%rbp), %rcx
movq 0x2d7d(%rip), %rax      # 0x7200
movq %rcx, (%rax)
leaq 0x2d83(%rip), %rdi      # 0x7210
callq 0x2210
movq -0x40(%rbp), %rsi
leaq 0x2e1b(%rip), %rdi      # 0x72b8
callq 0x3aa0
leaq 0x2db7(%rip), %rdi      # 0x7260
callq 0x2160
leaq -0x70(%rbp), %rdi
callq 0x21d0
leaq -0x9c(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x23a0
movl %eax, -0x88(%rbp)
cmpl $0x0, %eax
jge 0x44f7
leaq 0xcfb(%rip), %rdi       # 0x51e3
callq 0x22e0
movl $0x9, %edi
callq 0x2330
movw $0x2, -0x9c(%rbp)
xorl %edi, %edi
callq 0x2120
movl %eax, -0x98(%rbp)
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x20f0
movw %ax, -0x9a(%rbp)
movl -0x88(%rbp), %edi
movl $0x1, -0xac(%rbp)
movl $0x1, %esi
movl $0x2, %edx
leaq -0xac(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
cmpl $0x0, %eax
jge 0x4566
leaq 0xd32(%rip), %rdi       # 0x5289
callq 0x22e0
movl $0x9, %edi
callq 0x2330
movl -0x88(%rbp), %edi
movq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rsi
movl $0x10, %edx
callq 0x2270
cmpl $0x0, %eax
jge 0x45a6
leaq 0xcfd(%rip), %rdi       # 0x5294
callq 0x22e0
movl $0x9, %edi
callq 0x2330
movl -0x88(%rbp), %edi
movl $0x64, %esi
callq 0x2230
cmpl $0x0, %eax
jge 0x45d1
leaq 0xcd7(%rip), %rdi       # 0x5299
callq 0x22e0
movl $0x9, %edi
callq 0x2330
movl -0x88(%rbp), %eax
movl %eax, -0xc0(%rbp)
movw $0x1, -0xbc(%rbp)
leaq -0xc0(%rbp), %rdi
movl $0x1, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2260
movswl -0xba(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4bdc
movl -0x88(%rbp), %edi
movq $0x0, -0xc8(%rbp)
movq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x22f0
movl %eax, -0x8c(%rbp)
cmpl $0x0, %eax
jge 0x4651
leaq 0xc5e(%rip), %rdi       # 0x52a0
callq 0x22e0
movl $0x9, %edi
callq 0x2330
jmp 0x4653
movl $0x9, %edi
callq 0x2220
movq %rax, -0xd0(%rbp)
movl -0x8c(%rbp), %edi
leaq -0xd0(%rbp), %rsi
movl $0x9, %edx
callq 0x28c0
movq -0xd0(%rbp), %rdi
leaq 0xc1e(%rip), %rsi       # 0x52a7
callq 0x2180
cmpl $0x0, %eax
jne 0x477d
leaq -0x78(%rbp), %rdi
callq 0x21d0
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
movl %eax, -0x7c(%rbp)
imull $0xe10, -0x7c(%rbp), %eax # imm = 0xE10
movslq %eax, %rcx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movl %eax, -0x80(%rbp)
movq -0x78(%rbp), %rax
imull $0x3c, -0x80(%rbp), %ecx
movslq %ecx, %rcx
subq %rcx, %rax
movl %eax, -0x84(%rbp)
movq $0x0, -0xd8(%rbp)
movl -0x7c(%rbp), %edx
movl -0x80(%rbp), %ecx
movl -0x84(%rbp), %r8d
movl 0x2ad7(%rip), %r9d      # 0x71f0
movl 0x2ad5(%rip), %eax      # 0x71f4
leaq -0xd8(%rbp), %rdi
leaq 0xb80(%rip), %rsi       # 0x52ad
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2250
cmpl $-0x1, %eax
je 0x4778
movq -0xd8(%rbp), %rdi
callq 0x20e0
movl %eax, -0xdc(%rbp)
movl -0x8c(%rbp), %edi
movq -0xd8(%rbp), %rsi
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x20a0
movq -0xd8(%rbp), %rdi
callq 0x2030
jmp 0x4bc9
movq -0xd0(%rbp), %rdi
leaq 0xb60(%rip), %rsi       # 0x52eb
callq 0x2180
cmpl $0x0, %eax
jne 0x47b8
movl -0x8c(%rbp), %edi
callq 0x2130
movq -0xd0(%rbp), %rdi
callq 0x2030
movl $0x1, -0x44(%rbp)
jmp 0x4bda
movq -0xd0(%rbp), %rdi
leaq 0xb2e(%rip), %rsi       # 0x52f4
callq 0x2180
cmpl $0x0, %eax
jne 0x47ec
movl -0x8c(%rbp), %edi
callq 0x2130
movq -0xd0(%rbp), %rdi
callq 0x2030
jmp 0x4bda
movq $0x0, -0xe8(%rbp)
movq -0xd0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x29b0
movq -0xe8(%rbp), %rdi
leaq 0xadf(%rip), %rsi       # 0x52f9
callq 0x2180
cmpl $0x0, %eax
jne 0x4ba2
movl 0x29ca(%rip), %eax      # 0x71f8
cmpl -0x1c(%rbp), %eax
jne 0x4840
movq 0x2a7e(%rip), %rax      # 0x72b8
cmpl $0x0, 0xc(%rax)
je 0x4874
movl -0x8c(%rbp), %edi
leaq 0xab3(%rip), %rsi       # 0x5300
movl $0x1c, %edx
callq 0x20a0
movq -0xe8(%rbp), %rdi
callq 0x2030
movq -0xd0(%rbp), %rdi
callq 0x2030
jmp 0x4653
cmpl $0x0, -0x48(%rbp)
je 0x4a1c
leaq 0xa97(%rip), %rax       # 0x531c
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x30c0
leaq 0xa85(%rip), %rdi       # 0x5328
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
jne 0x490e
callq 0x2040
cmpl $0x11, (%rax)
je 0x48d2
leaq 0xa70(%rip), %rdi       # 0x5333
callq 0x22e0
movl $0x15, %edi
callq 0x2330
leaq 0xa4f(%rip), %rdi       # 0x5328
callq 0x2050
leaq 0xa43(%rip), %rdi       # 0x5328
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
jne 0x490a
leaq 0xa3f(%rip), %rdi       # 0x533a
callq 0x22e0
movl $0x63, %edi
callq 0x2330
jmp 0x490c
jmp 0x490e
leaq 0xa3a(%rip), %rdi       # 0x534f
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
jne 0x4980
callq 0x2040
cmpl $0x11, (%rax)
je 0x4944
leaq 0x9fe(%rip), %rdi       # 0x5333
callq 0x22e0
movl $0x15, %edi
callq 0x2330
leaq 0xa04(%rip), %rdi       # 0x534f
callq 0x2050
leaq 0x9f8(%rip), %rdi       # 0x534f
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x21b0
cmpl $-0x1, %eax
jne 0x497c
leaq 0x9cd(%rip), %rdi       # 0x533a
callq 0x22e0
movl $0x63, %edi
callq 0x2330
jmp 0x497e
jmp 0x4980
callq 0x2380
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x49a4
leaq 0x9c5(%rip), %rdi       # 0x535a
callq 0x22e0
movl $0x57, %edi
callq 0x2330
cmpl $0x0, -0x34(%rbp)
jne 0x49ea
movl -0x8c(%rbp), %edi
callq 0x2130
leaq -0x140(%rbp), %rdi
leaq 0x23ed(%rip), %rsi      # 0x6db0
movl $0x48, %edx
callq 0x21c0
leaq -0x140(%rbp), %rsi
leaq 0x984(%rip), %rdi       # 0x535f
callq 0x2370
movl $0x36, %edi
callq 0x2330
jmp 0x49ec
leaq 0x935(%rip), %rdi       # 0x5328
movl $0x1, %esi
movb $0x0, %al
callq 0x22c0
movl %eax, -0x4c(%rbp)
leaq 0x946(%rip), %rdi       # 0x534f
xorl %esi, %esi
movb $0x0, %al
callq 0x22c0
movl %eax, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
addq $0x9, %rdi
shlq $0x0, %rdi
callq 0x2220
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2070
movq -0x148(%rbp), %rdi
leaq 0x930(%rip), %rsi       # 0x5390
callq 0x2310
movl -0x4c(%rbp), %eax
movl %eax, -0x16c(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x148(%rbp), %rdi
callq 0x20e0
movl -0x16c(%rbp), %edi
movq -0x168(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x20a0
movq -0x148(%rbp), %rdi
callq 0x2030
movl $0x9, %edi
callq 0x2220
movq %rax, -0x150(%rbp)
movl -0x50(%rbp), %edi
leaq -0x150(%rbp), %rsi
movl $0x9, %edx
callq 0x28c0
movq -0x150(%rbp), %rdi
leaq 0x8b9(%rip), %rsi       # 0x5399
callq 0x2180
cmpl $0x0, %eax
jne 0x4afb
movq -0x150(%rbp), %rdi
callq 0x2030
jmp 0x4ba0
movq -0x150(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
addq $0x2, %rdi
shlq $0x0, %rdi
callq 0x2220
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x2070
movq -0x158(%rbp), %rdi
leaq 0x4fc(%rip), %rsi       # 0x503b
callq 0x2310
movl -0x8c(%rbp), %eax
movl %eax, -0x17c(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x150(%rbp), %rdi
callq 0x20e0
movl -0x17c(%rbp), %edi
movq -0x178(%rbp), %rsi
movq %rax, %rdx
addq $0x2, %rdx
callq 0x20a0
movq -0x158(%rbp), %rdi
callq 0x2030
movq -0x150(%rbp), %rdi
callq 0x2030
jmp 0x4aad
jmp 0x4bb9
movl -0x8c(%rbp), %edi
leaq 0x7f1(%rip), %rsi       # 0x53a0
movl $0x12, %edx
callq 0x20a0
movq -0xe8(%rbp), %rdi
callq 0x2030
jmp 0x4bc7
jmp 0x4bc9
movq -0xd0(%rbp), %rdi
callq 0x2030
jmp 0x4653
jmp 0x4bdc
cmpl $0x0, -0x44(%rbp)
je 0x4be4
jmp 0x4be9
jmp 0x45e6
leaq 0x26c8(%rip), %rdi      # 0x72b8
callq 0x39e0
movl $0x0, -0x15c(%rbp)
movl -0x15c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4c48
leaq 0x26a7(%rip), %rdi      # 0x72b8
leaq 0x7af(%rip), %rsi       # 0x53c7
callq 0x3aa0
leaq 0x263c(%rip), %rdi      # 0x7260
callq 0x2160
leaq 0x782(%rip), %rdi       # 0x53b2
movb $0x0, %al
callq 0x2100
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x4bff
movl $0x0, -0x160(%rbp)
movl -0x160(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4c86
movq -0x58(%rbp), %rax
movslq -0x160(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2350
movl -0x160(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x160(%rbp)
jmp 0x4c52
cmpl $0x0, -0x48(%rbp)
jne 0x4cb0
movl -0x4c(%rbp), %edi
leaq 0x730(%rip), %rsi       # 0x53c6
movl $0x6, %edx
callq 0x20a0
movl -0x4c(%rbp), %edi
callq 0x2130
movl -0x50(%rbp), %edi
callq 0x2130
leaq 0x2581(%rip), %rdi      # 0x7238
callq 0x2110
leaq 0x25cd(%rip), %rdi      # 0x7290
callq 0x2110
leaq 0x2541(%rip), %rdi      # 0x7210
callq 0x2110
leaq 0x2615(%rip), %rdi      # 0x72f0
callq 0x2110
leaq 0x2631(%rip), %rdi      # 0x7318
callq 0x2110
leaq 0x256d(%rip), %rdi      # 0x7260
callq 0x22b0
leaq 0x25c1(%rip), %rdi      # 0x72c0
callq 0x22b0
leaq 0x25ad(%rip), %rdi      # 0x72b8
callq 0x3a70
callq 0x3920
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2030
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x58(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rdi
callq 0x2030
cmpl $0x0, -0x48(%rbp)
jne 0x4d7f
movl -0x34(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x22a0
leaq 0x5ba(%rip), %rdi       # 0x5328
callq 0x2050
leaq 0x5d5(%rip), %rdi       # 0x534f
callq 0x2050
leaq 0x646(%rip), %rdi       # 0x53cc
movb $0x0, %al
callq 0x2100
xorl %eax, %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq