// File: /workspace/github_cpp_makefile_star2_O2/rthoelen[P]NXCore_Kenwood/main.cc
// Function: listen_thread(void*)
void *listen_thread(void *thread_id)
{
        struct sockaddr_in remaddr;     /* remote address */
        socklen_t addrlen = sizeof(remaddr);            /* length of addresses */
        int recvlen;                    /* # bytes received */
        unsigned char buf[80];     /* receive buffer */
	int rpt_id;
	int strt_packet;

	struct sockaddr_in tport; // This is a test port to reflect what is received
	int GID, UID, RAN;

        /* create UDP socket for repeaters */

        if ((socket_00 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                perror("cannot create socket\n");
                return 0;
        }

        if ((socket_01 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                perror("cannot create socket\n");
                return 0;
        }

        /* bind the socket to any valid IP address and a specific port */

        memset((char *)&myaddr_00, 0, sizeof(myaddr_00));
        myaddr_00.sin_family = AF_INET;
        myaddr_00.sin_addr.s_addr = htonl(INADDR_ANY);
        myaddr_00.sin_port = htons(64000);

        if (bind(socket_00, (struct sockaddr *)&myaddr_00, sizeof(myaddr_00)) < 0) {
                perror("bind failed");
                return 0;
        }

        memset((char *)&myaddr_00, 0, sizeof(myaddr_00));
        myaddr_00.sin_family = AF_INET;
        myaddr_00.sin_addr.s_addr = htonl(INADDR_ANY);
        myaddr_00.sin_port = htons(64001);

        if (bind(socket_01, (struct sockaddr *)&myaddr_00, sizeof(myaddr_00)) < 0) {
                perror("bind failed");
                return 0;
        }


	// Set up the test port
	memset((char *)&tport, 0, sizeof(tport));
	tport.sin_family = AF_INET;
	tport.sin_addr.s_addr = inet_addr("127.0.0.1");
	tport.sin_port = htons(50000);

        /* now loop, receiving data and printing what we received */
        for (;;) {
                recvlen = recvfrom(socket_00, buf, 80, 0, (struct sockaddr *)&remaddr, &addrlen);

		if (recvlen == -1)
		{
			ptime();
			std::cout << "Receive socket returned error" << std::endl;
			continue;
		}

		strt_packet = 0;

		rpt_id = get_repeater_id(&remaddr);
		if ( rpt_id != -1)
		{
			buf[8] = (repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 24;
			buf[9] = ((repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 16) & 0xff;
			buf[10] = ((repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 8) & 0xff;
			buf[11] = (repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) & 0xff;

		}

		// Detect start/stop for voice 

                if (recvlen == 47) {



			if (rpt_id == -1)
			{
				ptime();
				std::cout << " Unauthorized repeater, "
					<< inet_ntoa(remaddr.sin_addr)
					<< ", dropping packet" << std::endl;

				continue;  // Throw out packet, not in our list
			}


			// This would be a start packet
			if((buf[20] == 0x0a) && (buf[21] == 0x05) &&
				(buf[22] == 0x0a) && (buf[23] == 0x10) &&
					(buf[28] == 0x01))
			{
				GID = (buf[31] << 8) + buf[34];
				UID = (buf[29] << 8) + buf[32];
				RAN = buf[24];
				repeater[rpt_id].keydown = 0; // need to stop a shutdown transmission if receiving

				if ((UID==0) && (GID==0))
					continue;

                                if ((repeater[rpt_id].tg_network_off == GID) && (repeater[rpt_id].tg_network_off != 0))
                                {
                                        repeater[rpt_id].disable = 1;
					ptime();
                                        std::cout << "Repeater  -> " << r_list[rpt_id]
                                                << " <- disabled due to TG: " << GID << std::endl;
					continue;
                                }

                                if ((repeater[rpt_id].tg_network_on == GID) && (repeater[rpt_id].tg_network_on != 0))
                                {
                                        repeater[rpt_id].disable = 0;
					ptime();
                                        std::cout << "Repeater  ->  " << r_list[rpt_id]
                                                << " <- enabled due to TG: " << GID << std::endl;
					continue;
                                }


				if (RAN != repeater[rpt_id].rx_ran)
				{
					ptime();
					std::cout << "Repeater  ->" << r_list[rpt_id]
						<< "<-  not passing start from UID: " << UID
						<< " from TG: " << GID
						<< " because RAN: " << RAN
						<< " isn't the correct receive RAN" << std::endl;
					while(tx_sem == 1)
						usleep(1);
				
						tx_sem = 1;
						sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 					sizeof(tport));
						tx_sem = 0;



					repeater[rpt_id].rx_activity = 1;
					repeater[rpt_id].time_since_rx = 0;
					repeater[rpt_id].active_tg = GID;
					repeater[rpt_id].last_tg = GID;
						
					continue;
				}

				repeater[rpt_id].rx_activity = 1;
				repeater[rpt_id].active_tg = GID;
				repeater[rpt_id].busy_tg = GID;
				repeater[rpt_id].uid = UID;
				strt_packet = 1;

				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving start from UID: " << UID
					<< " from TG: " << GID
					<< " on RAN: " << RAN << std::endl;

				repeater[rpt_id].time_since_rx = 0;
			}
		
			// End, send shutdown on 64001	
			if((buf[20] == 0x0a) && (buf[21] == 0x05) &&
				(buf[22] == 0x0a) && (buf[23] == 0x10) &&
					(buf[28] == 0x08))
			{
				GID = (buf[31] << 8) + buf[34];
				UID = (buf[29] << 8) + buf[32];
				RAN = buf[24];
				if ((UID==0) && (GID==0))
					continue;

				if (repeater[rpt_id].rx_activity == 0)
					continue;

				if (RAN != repeater[rpt_id].rx_ran)
				{
					ptime();
					std::cout << "Repeater  ->" << r_list[rpt_id]
						<< "<-  not passing stop from UID: " << UID
						<< " from TG: " << GID
						<< " because RAN: " << RAN
						<< " isn't the correct receive RAN" << std::endl;

					while(tx_sem == 1)
						usleep(1);	

						tx_sem = 1;
						sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 					sizeof(tport));
						tx_sem = 0;

					// Special case: if no talkgroup and different RAN, assume local
					// and block network activity

					if (GID == 0)
					{
						repeater[rpt_id].rx_activity = 0;
						repeater[rpt_id].time_since_rx = 0;
						repeater[rpt_id].active_tg = GID;
						repeater[rpt_id].last_tg = repeater[rpt_id].active_tg;
					}
					continue;
				}

				repeater[rpt_id].rx_activity = 0;    // Activity on channel is over
				repeater[rpt_id].last_tg = repeater[rpt_id].active_tg;
	
				repeater[rpt_id].time_since_rx = 0;
				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving stop from UID: " << UID
					<< " from TG: " << GID << std::endl;
			}	


                        if(repeater[rpt_id].disable)
                                continue;
				
			// Need to put GID back if not a start packet

			GID = repeater[rpt_id].active_tg;

			while(tx_sem == 1)
				usleep(1);
			
				tx_sem = 1;
				sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 			sizeof(tport));
				tx_sem = 0;

			snd_packet(buf, recvlen, GID, rpt_id, strt_packet);

				
		}
                
		if ((recvlen == 59) || (recvlen == 53)) {

                        if(repeater[rpt_id].disable)
                                continue;

			if (rpt_id == -1)
			{
				if(debug)
				{
					ptime();
					std::cout << "Unauthorized repeater, " 
						<< inet_ntoa(remaddr.sin_addr) 
						<< ", dropping packet" << std::endl;
				}	

				continue;  // Throw out packet, not in our list
			}	

			// Heartbeat packet from another repeater, bounce back
			// but then continue 
			if ((buf[0] == 0x00) && (buf[1] == 0x00) && (buf[21] == 0x99))
			{
				
				while(tx_sem==1)
					usleep(1);
				tx_sem=1;

				buf[21] = 0x98; // return code so we don't loop

				sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&repeater[rpt_id].rpt_addr_00,
		 			sizeof(repeater[rpt_id].rpt_addr_00));
				tx_sem=0;
				continue; 
			}

			// If we receive a reply, ignore it

			if ((buf[0] == 0x00) && (buf[1] == 0x00) && (buf[21] == 0x98))
				continue;
		

			// Special case where we don't get start packet, if there is activity in 2 seconds
			// and talkgroup matches, just start letting packets through

			// Commenting all this out, causing problems
			//

			//if((repeater[rpt_id].time_since_rx < 2)&&(repeater[rpt_id].time_since_rx > 1)&&(repeater[rpt_id].rx_activity == 0))
			//{
			//		std::cout << "Repeater ->" << r_list[rpt_id] << "<-  Sending non-IDed data through since rx was close enough, TG: "
			//			<< repeater[rpt_id].active_tg << std::endl;
			//	repeater[rpt_id].rx_activity = 1;
			//	strt_packet=1;
			//}

			repeater[rpt_id].keydown = 0; // need to prevent transmitting shutdown if receive activity

			if (repeater[rpt_id].rx_activity == 0)
			{
				if(debug)
				{
					ptime();
					std::cout << "Not sending vocoder packet from Repeater " 
						<< rpt_id << " due to rx_flag not set" << std::endl;
				}

				continue;
			}


			repeater[rpt_id].time_since_rx = 0;	
			GID = repeater[rpt_id].active_tg;

			// send packet to repeaters that can receive it


			while(tx_sem==1)
				usleep(1);
			tx_sem=1;
			sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));
			tx_sem=0;

			snd_packet(buf, recvlen, GID, rpt_id, strt_packet);
		}

		if ((recvlen == 43) && (repeater[rpt_id].disable != 1)&&(repeater[rpt_id].msg_flag ==1))
		{

			GID = (buf[26] << 8) + buf[25];
			UID = (buf[24] << 8) + buf[23];
			RAN = buf[20];

			if (RAN != repeater[rpt_id].rx_ran)
			{
				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  not passing messaging datagram from UID: " << UID
					<< " from TG: " << GID
					<< " because RAN: " << RAN
					<< " isn't the correct receive RAN" << std::endl;
				while(tx_sem == 1)
					usleep(1);
				
					tx_sem = 1;
					sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 				sizeof(tport));
					tx_sem = 0;

				repeater[rpt_id].rx_activity=0;
				continue;
			}
			// handle start of message

			if((buf[17]==0x06)&&(buf[18]==0x18)&&(buf[21]==0x20))
			{

				repeater[rpt_id].rx_activity = 1;
				repeater[rpt_id].active_tg = GID;
				repeater[rpt_id].busy_tg = GID;
				repeater[rpt_id].uid = UID;
				strt_packet = 1;

				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving message start from UID: " << UID
					<< " from TG: " << GID
					<< " on RAN: " << RAN << std::endl;

				repeater[rpt_id].time_since_rx = 0;
			}
	
			if((buf[17]==0x01)&&(buf[18]==0x18))
			{

				repeater[rpt_id].rx_activity = 1;
				GID = repeater[rpt_id].active_tg;
				UID = repeater[rpt_id].uid;

				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving message data from UID: " << UID
					<< " from TG: " << GID
					<< " on RAN: " << RAN << std::endl;

				repeater[rpt_id].time_since_rx = 0;
			}
	

			if((buf[17]==0x06)&&(buf[18]==0x18)&&((buf[21]==0x10)||buf[19]==0x08))
			{
				repeater[rpt_id].rx_activity = 0;    // Activity on channel is over
				repeater[rpt_id].last_tg = repeater[rpt_id].active_tg;
	
				repeater[rpt_id].time_since_rx = 0;
				ptime();
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving message stop from UID: " << UID
					<< " from TG: " << GID << std::endl;

				repeater[rpt_id].time_since_rx = 0;	
				GID = repeater[rpt_id].active_tg;
			}

			// send packet to repeaters that can receive it


			while(tx_sem==1)
				usleep(1);
			tx_sem=1;
			sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));
			tx_sem=0;

			snd_packet(buf, recvlen, GID, rpt_id, strt_packet);

		}
		
        }	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl $0x10, -0x94(%rbp)
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0xfbac(%rip)      # 0x1441c
leaq 0x87b0(%rip), %rbx      # 0xd027
testl %eax, %eax
js 0x5574
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0xfb8f(%rip)      # 0x14420
testl %eax, %eax
js 0x5574
andq $0x0, 0xfb93(%rip)      # 0x14434
leaq 0xfb84(%rip), %rsi      # 0x1442c
movq $0xfa0002, 0xfb79(%rip) # imm = 0xFA0002
movl 0xfb63(%rip), %edi      # 0x1441c
pushq $0x10
popq %rdx
callq 0x4060
leaq 0x8775(%rip), %rbx      # 0xd03d
testl %eax, %eax
js 0x5574
andq $0x0, 0xfb5c(%rip)      # 0x14434
leaq 0xfb4d(%rip), %rsi      # 0x1442c
movq $0x1fa0002, 0xfb42(%rip) # imm = 0x1FA0002
movl 0xfb30(%rip), %edi      # 0x14420
pushq $0x10
popq %rdx
callq 0x4060
testl %eax, %eax
js 0x5574
leaq -0xa4(%rbp), %rbx
andq $0x0, 0x8(%rbx)
movw $0x2, (%rbx)
leaq 0x8731(%rip), %rdi      # 0xd049
callq 0x4340
movl %eax, 0x4(%rbx)
movw $0x50c3, 0x2(%rbx)      # imm = 0x50C3
movl 0xfaf0(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %rsi
pushq $0x50
popq %rdx
xorl %ecx, %ecx
leaq -0xb4(%rbp), %rbx
movq %rbx, %r8
leaq -0x94(%rbp), %r9
callq 0x4280
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x4b37
movq %rbx, %rdi
callq 0x4801
movl %eax, %r15d
movslq %eax, %r13
cmpl $-0x1, %eax
je 0x4b4c
movq 0xfa77(%rip), %rax      # 0x143f0
imulq $0x90, %r13, %r14
movb 0x7(%rax,%r14), %cl
movb %cl, -0x88(%rbp)
movb 0x6(%rax,%r14), %cl
movb %cl, -0x87(%rbp)
movb 0x5(%rax,%r14), %cl
movb %cl, -0x86(%rbp)
movb 0x4(%rax,%r14), %cl
movb %cl, -0x85(%rbp)
cmpl $0x2f, %r12d
jne 0x4b9f
movb -0x7c(%rbp), %dl
movb -0x7b(%rbp), %cl
movl %edx, %esi
xorb $0xa, %sil
movl %ecx, %r8d
xorb $0x5, %r8b
orb %sil, %r8b
movb -0x7a(%rbp), %sil
movl %esi, %r9d
xorb $0xa, %r9b
movb -0x79(%rbp), %dil
movl %edi, %r10d
xorb $0x10, %r10b
orb %r9b, %r10b
orb %r8b, %r10b
movb -0x74(%rbp), %r8b
movl %r8d, %r9d
xorb $0x1, %r9b
orb %r10b, %r9b
jne 0x4f25
movzbl -0x71(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x6e(%rbp), %edi
orl %ecx, %edi
movzbl -0x73(%rbp), %ecx
movzbl -0x70(%rbp), %ebx
movzbl -0x78(%rbp), %r8d
andl $0x0, 0x74(%rax,%r14)
shll $0x8, %ecx
orl %ecx, %ebx
movl %ebx, %ecx
orl %edi, %ecx
je 0x4926
leaq (%rax,%r14), %rcx
movl 0x84(%rax,%r14), %edx
cmpl %edi, %edx
setne %sil
testl %edx, %edx
sete %dl
orb %sil, %dl
je 0x5051
movl 0x80(%rcx), %edx
cmpl %edi, %edx
setne %sil
testl %edx, %edx
sete %dl
orb %sil, %dl
je 0x519a
cmpb 0x49(%rcx), %r8b
movl %r8d, -0x30(%rbp)
jne 0x5437
movl $0x1, 0x38(%rcx)
movl %edi, 0x4c(%rax,%r14)
movl %edi, 0x40(%rax,%r14)
movl %ebx, 0x68(%rax,%r14)
movl %edi, -0x2c(%rbp)
callq 0x479c
movq 0xf538(%rip), %rdi      # 0x13fd0
leaq 0x882c(%rip), %rsi      # 0xd2cb
callq 0x4320
movq %r13, %rsi
shlq $0x5, %rsi
addq 0xf94e(%rip), %rsi      # 0x14400
movq %rax, %rdi
callq 0x42f0
movq %rax, %rdi
leaq 0x8680(%rip), %rsi      # 0xd144
callq 0x4320
movq %rax, %rdi
movl %ebx, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x862e(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x866c(%rip), %rsi      # 0xd163
callq 0x4320
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x4540
movq %rax, %rdi
callq 0x4150
movq 0xf8da(%rip), %rax      # 0x143f0
andl $0x0, 0x28(%rax,%r14)
movb -0x7c(%rbp), %dl
movb -0x7b(%rbp), %cl
movb -0x7a(%rbp), %sil
movb -0x79(%rbp), %dil
movb -0x74(%rbp), %r8b
pushq $0x1
popq %r9
jmp 0x4f28
callq 0x479c
movq 0xf48d(%rip), %rdi      # 0x13fd0
leaq 0x8509(%rip), %rsi      # 0xd053
jmp 0x4b8d
cmpl $0x2f, %r12d
jne 0x4b9f
callq 0x479c
movq 0xf472(%rip), %rdi      # 0x13fd0
leaq 0x850c(%rip), %rsi      # 0xd071
callq 0x4320
movq %rax, %rbx
movl -0xb0(%rbp), %edi
callq 0x4110
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x84fd(%rip), %rsi      # 0xd08a
callq 0x4320
movq %rax, %rdi
callq 0x4150
jmp 0x4926
xorl %r8d, %r8d
cmpl $0x3b, %r12d
je 0x4ebe
cmpl $0x35, %r12d
je 0x4ebe
cmpl $0x2b, %r12d
jne 0x4926
movq 0xf829(%rip), %rax      # 0x143f0
imulq $0x90, %r13, %rbx
cmpl $0x1, 0x7c(%rax,%rbx)
je 0x4926
leaq (%rax,%rbx), %rsi
cmpl $0x1, 0x88(%rsi)
jne 0x4926
movzwl -0x77(%rbp), %r14d
movzwl -0x79(%rbp), %r12d
movzbl -0x7c(%rbp), %edi
cmpb 0x49(%rsi), %dil
jne 0x51ec
movl %r14d, -0x2c(%rbp)
movb -0x7f(%rbp), %dl
movb -0x7e(%rbp), %cl
cmpb $0x6, %dl
pushq $0x1
popq %r14
movl %r12d, -0x34(%rbp)
movl %edi, -0x38(%rbp)
jne 0x4ce3
cmpb $0x18, %cl
jne 0x4ce3
cmpb $0x20, -0x7b(%rbp)
jne 0x4ce3
movl $0x1, 0x38(%rsi)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x4c(%rax,%rbx)
movl %ecx, 0x40(%rax,%rbx)
movl %r12d, 0x68(%rax,%rbx)
callq 0x479c
movq 0xf37a(%rip), %rdi      # 0x13fd0
leaq 0x866e(%rip), %rsi      # 0xd2cb
callq 0x4320
movq %r13, %rsi
shlq $0x5, %rsi
addq 0xf790(%rip), %rsi      # 0x14400
movq %rax, %rdi
callq 0x42f0
movq %rax, %rdi
leaq 0x8599(%rip), %rsi      # 0xd21b
callq 0x4320
movq %rax, %rdi
movl %r12d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x846f(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x84ad(%rip), %rsi      # 0xd163
callq 0x4320
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x4540
movq %rax, %rdi
callq 0x4150
movq 0xf71b(%rip), %rax      # 0x143f0
andl $0x0, 0x28(%rax,%rbx)
movb -0x7f(%rbp), %dl
movb -0x7e(%rbp), %cl
movl %r14d, %r8d
movl %edx, %esi
xorb $0x1, %sil
movl %ecx, %edi
xorb $0x18, %dil
orb %sil, %dil
movl %r8d, -0x30(%rbp)
jne 0x4daa
movl $0x1, 0x38(%rax,%rbx)
movl 0x4c(%rax,%rbx), %ecx
movl %ecx, -0x2c(%rbp)
movl 0x68(%rax,%rbx), %r12d
callq 0x479c
movq 0xf2b4(%rip), %rdi      # 0x13fd0
leaq 0x85a8(%rip), %rsi      # 0xd2cb
callq 0x4320
movq %r13, %rsi
shlq $0x5, %rsi
addq 0xf6ca(%rip), %rsi      # 0x14400
movq %rax, %rdi
callq 0x42f0
movq %rax, %rdi
leaq 0x84fa(%rip), %rsi      # 0xd242
callq 0x4320
movq %rax, %rdi
movl %r12d, -0x34(%rbp)
movl %r12d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x83a5(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x83e3(%rip), %rsi      # 0xd163
callq 0x4320
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x4540
movq %rax, %rdi
callq 0x4150
movq 0xf651(%rip), %rax      # 0x143f0
andl $0x0, 0x28(%rax,%rbx)
movb -0x7f(%rbp), %dl
movb -0x7e(%rbp), %cl
cmpb $0x6, %dl
jne 0x4e65
cmpb $0x18, %cl
jne 0x4e65
cmpb $0x10, -0x7b(%rbp)
je 0x4dcc
cmpb $0x8, -0x7d(%rbp)
jne 0x4e65
andl $0x0, 0x38(%rax,%rbx)
movl 0x4c(%rax,%rbx), %ecx
movl %ecx, 0x50(%rax,%rbx)
andl $0x0, 0x28(%rax,%rbx)
callq 0x479c
movq 0xf1e6(%rip), %rdi      # 0x13fd0
leaq 0x84da(%rip), %rsi      # 0xd2cb
callq 0x4320
shlq $0x5, %r13
addq 0xf5ff(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x8452(%rip), %rsi      # 0xd268
callq 0x4320
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x82db(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
callq 0x4150
movq 0xf5a1(%rip), %rax      # 0x143f0
andl $0x0, 0x28(%rax,%rbx)
movl 0x4c(%rax,%rbx), %eax
movl %eax, -0x2c(%rbp)
jmp 0x4e65
movl %r14d, %edi
callq 0x4490
cmpl $0x1, 0xf5b8(%rip)      # 0x14424
je 0x4e5d
movl $0x1, 0xf5ac(%rip)      # 0x14424
movl 0xf59e(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %rbx
movq %rbx, %rsi
pushq $0x2b
popq %rdx
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf580(%rip)      # 0x14424
movq %rbx, %rdi
pushq $0x2b
popq %rsi
movl -0x2c(%rbp), %edx
movl %r15d, %ecx
movl -0x30(%rbp), %r8d
callq 0x5590
jmp 0x4926
movq 0xf52b(%rip), %rax      # 0x143f0
movslq %r15d, %r13
imulq $0x90, %r13, %rbx
cmpl $0x0, 0x7c(%rax,%rbx)
jne 0x4926
cmpl $-0x1, %r15d
je 0x5097
movb -0x8f(%rbp), %dl
movb -0x7b(%rbp), %cl
orb -0x90(%rbp), %dl
sete %dl
cmpb $-0x67, %cl
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x5110
pushq $0x1
popq %r14
cmpl $0x1, 0xf50f(%rip)      # 0x14424
jne 0x5157
movl %r14d, %edi
callq 0x4490
jmp 0x4f0e
xorl %r9d, %r9d
cmpb $0xa, %dl
jne 0x5024
cmpb $0x5, %cl
jne 0x5024
cmpb $0xa, %sil
jne 0x5024
cmpb $0x10, %dil
jne 0x5024
cmpb $0x8, %r8b
jne 0x5024
movzbl -0x71(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x6e(%rbp), %edx
orl %ecx, %edx
movzbl -0x73(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x70(%rbp), %ebx
orl %ecx, %ebx
movl %ebx, %ecx
orl %edx, %ecx
je 0x4926
cmpl $0x0, 0x38(%rax,%r14)
je 0x4926
movl %edx, -0x2c(%rbp)
movzbl -0x78(%rbp), %edx
leaq (%rax,%r14), %rcx
cmpb 0x49(%rcx), %dl
jne 0x52dd
andl $0x0, 0x38(%rcx)
movl 0x4c(%rcx), %edx
movl %edx, 0x50(%rcx)
andl $0x0, 0x28(%rax,%r14)
movl %r9d, -0x30(%rbp)
callq 0x479c
movq 0xf014(%rip), %rdi      # 0x13fd0
leaq 0x8308(%rip), %rsi      # 0xd2cb
callq 0x4320
movq %r13, %rsi
shlq $0x5, %rsi
addq 0xf42a(%rip), %rsi      # 0x14400
movq %rax, %rdi
callq 0x42f0
movq %rax, %rdi
leaq 0x81a5(%rip), %rsi      # 0xd18d
callq 0x4320
movq %rax, %rdi
movl %ebx, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x810a(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
callq 0x4150
movl -0x30(%rbp), %r9d
movq 0xf3cc(%rip), %rax      # 0x143f0
cmpl $0x0, 0x7c(%rax,%r14)
jne 0x4926
movl %r9d, -0x30(%rbp)
addq %r14, %rax
movl 0x4c(%rax), %ebx
pushq $0x1
popq %r14
cmpl $0x1, 0xf3df(%rip)      # 0x14424
jne 0x50bc
movl %r14d, %edi
callq 0x4490
jmp 0x503e
movl $0x1, 0x7c(%rcx)
movl %edi, %ebx
callq 0x479c
movq 0xef6a(%rip), %rdi      # 0x13fd0
leaq 0x802f(%rip), %rsi      # 0xd09c
callq 0x4320
shlq $0x5, %r13
addq 0xf383(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x8018(%rip), %rsi      # 0xd0aa
jmp 0x51d8
cmpl $0x0, 0xf35e(%rip)      # 0x143fc
je 0x4926
callq 0x479c
movq 0xef20(%rip), %rdi      # 0x13fd0
leaq 0x7fbb(%rip), %rsi      # 0xd072
jmp 0x4b65
movl $0x1, 0xf35e(%rip)      # 0x14424
movl 0xf350(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %r14
movq %r14, %rsi
pushq $0x2f
popq %rdx
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf332(%rip)      # 0x14424
movq %r14, %rdi
pushq $0x2f
popq %rsi
movl %ebx, %edx
movl %r15d, %ecx
movl -0x30(%rbp), %ebx
movl %ebx, %r8d
callq 0x5590
movl %ebx, %r8d
jmp 0x4ba2
cmpb $-0x68, %cl
sete %cl
testb %cl, %dl
jne 0x4926
leaq (%rax,%rbx), %rcx
andl $0x0, 0x74(%rcx)
cmpl $0x0, 0x38(%rcx)
je 0x5535
movl %r8d, -0x30(%rbp)
andl $0x0, 0x28(%rcx)
movl 0x4c(%rax,%rbx), %ebx
pushq $0x1
popq %r14
cmpl $0x1, 0xf2dd(%rip)      # 0x14424
jne 0x53e0
movl %r14d, %edi
callq 0x4490
jmp 0x5140
movl $0x1, 0xf2c3(%rip)      # 0x14424
movb $-0x68, -0x7b(%rbp)
movl 0xf2b1(%rip), %edi      # 0x1441c
andl $0x3f, %r12d
addq 0xf27a(%rip), %rbx      # 0x143f0
leaq -0x90(%rbp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %rbx, %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf28f(%rip)      # 0x14424
jmp 0x4926
andl $0x0, 0x7c(%rcx)
movl %edi, %ebx
callq 0x479c
movq 0xee24(%rip), %rdi      # 0x13fd0
leaq 0x7f10(%rip), %rsi      # 0xd0c3
callq 0x4320
shlq $0x5, %r13
addq 0xf23d(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x7efa(%rip), %rsi      # 0xd0d2
callq 0x4320
movq %rax, %rdi
movl %ebx, %esi
callq 0x4540
jmp 0x4b92
movl %edi, %r15d
callq 0x479c
movq 0xedd5(%rip), %rdi      # 0x13fd0
leaq 0x80c9(%rip), %rsi      # 0xd2cb
callq 0x4320
shlq $0x5, %r13
addq 0xf1ee(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x7fc6(%rip), %rsi      # 0xd1ed
callq 0x4320
movq %rax, %rdi
movl %r12d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7eca(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl %r14d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7ebb(%rip), %rsi      # 0xd116
callq 0x4320
movq %rax, %rdi
movl %r15d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7eb0(%rip), %rsi      # 0xd125
callq 0x4320
movq %rax, %rdi
callq 0x4150
pushq $0x1
popq %r14
cmpl $0x1, 0xf197(%rip)      # 0x14424
jne 0x5299
movl %r14d, %edi
callq 0x4490
jmp 0x5286
movl $0x1, 0xf181(%rip)      # 0x14424
movl 0xf173(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %rsi
pushq $0x2b
popq %rdx
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf158(%rip)      # 0x14424
movq 0xf11d(%rip), %rax      # 0x143f0
andl $0x0, 0x38(%rax,%rbx)
jmp 0x4926
movl %edx, %r15d
callq 0x479c
movq 0xece4(%rip), %rdi      # 0x13fd0
leaq 0x7fd8(%rip), %rsi      # 0xd2cb
callq 0x4320
shlq $0x5, %r13
addq 0xf0fd(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x7e55(%rip), %rsi      # 0xd16d
callq 0x4320
movq %rax, %rdi
movl %ebx, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7dda(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7dcb(%rip), %rsi      # 0xd116
callq 0x4320
movq %rax, %rdi
movl %r15d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7dc0(%rip), %rsi      # 0xd125
callq 0x4320
movq %rax, %rdi
callq 0x4150
cmpl $0x1, 0xf0ab(%rip)      # 0x14424
jne 0x5385
pushq $0x1
popq %rdi
callq 0x4490
jmp 0x5372
movl $0x1, 0xf095(%rip)      # 0x14424
movl 0xf087(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %rsi
pushq $0x2f
popq %rdx
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf06c(%rip)      # 0x14424
cmpl $0x0, -0x2c(%rbp)
jne 0x4926
movq 0xf027(%rip), %rax      # 0x143f0
andl $0x0, 0x38(%rax,%r14)
andl $0x0, 0x28(%rax,%r14)
andq $0x0, 0x4c(%rax,%r14)
jmp 0x4926
movl $0x1, 0xf03a(%rip)      # 0x14424
movl 0xf02c(%rip), %edi      # 0x1441c
movl %r12d, %edx
andl $0x3f, %edx
leaq -0x90(%rbp), %r14
movq %r14, %rsi
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xf00b(%rip)      # 0x14424
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
movl %r15d, %ecx
movl -0x30(%rbp), %ebx
movl %ebx, %r8d
callq 0x5590
movl %ebx, %r8d
jmp 0x4bb6
movl %edi, %r15d
callq 0x479c
movq 0xeb8a(%rip), %rdi      # 0x13fd0
leaq 0x7e7e(%rip), %rsi      # 0xd2cb
callq 0x4320
shlq $0x5, %r13
addq 0xefa3(%rip), %r13      # 0x14400
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
movq %rax, %rdi
leaq 0x7c78(%rip), %rsi      # 0xd0ea
callq 0x4320
movq %rax, %rdi
movl %ebx, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7c80(%rip), %rsi      # 0xd10b
callq 0x4320
movq %rax, %rdi
movl %r15d, %r12d
movl %r15d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7c6e(%rip), %rsi      # 0xd116
callq 0x4320
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7c63(%rip), %rsi      # 0xd125
callq 0x4320
movq %rax, %rdi
callq 0x4150
cmpl $0x1, 0xef4e(%rip)      # 0x14424
jne 0x54e2
pushq $0x1
popq %rdi
callq 0x4490
jmp 0x54cf
pushq $0x1
popq %rbx
movl %ebx, 0xef39(%rip)      # 0x14424
movl 0xef2b(%rip), %edi      # 0x1441c
leaq -0x90(%rbp), %rsi
pushq $0x2f
popq %rdx
xorl %ecx, %ecx
leaq -0xa4(%rbp), %r8
pushq $0x10
popq %r9
callq 0x4050
andl $0x0, 0xef10(%rip)      # 0x14424
movq 0xeed5(%rip), %rax      # 0x143f0
movl %ebx, 0x38(%rax,%r14)
andl $0x0, 0x28(%rax,%r14)
movl %r12d, 0x4c(%rax,%r14)
movl %r12d, 0x50(%rax,%r14)
jmp 0x4926
cmpl $0x0, 0xeec0(%rip)      # 0x143fc
je 0x4926
callq 0x479c
movq 0xea82(%rip), %rdi      # 0x13fd0
leaq 0x7c56(%rip), %rsi      # 0xd1ab
callq 0x4320
movq %rax, %rdi
movl %r15d, %esi
callq 0x4540
movq %rax, %rdi
leaq 0x7c66(%rip), %rsi      # 0xd1d5
jmp 0x4b8d
movq %rbx, %rdi
callq 0x42c0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq