// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movl $0x10, -0xa4(%rbp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0x10b63(%rip)     # 0x153fc
leaq 0xa787(%rip), %rbx      # 0xf027
testl %eax, %eax
js 0x59e9
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0x10b41(%rip)     # 0x15400
testl %eax, %eax
js 0x59e9
movq $0x0, 0x10b42(%rip) # 0x15414
leaq 0x10b33(%rip), %rsi     # 0x1540c
movq $0xfa0002, 0x10b28(%rip) # imm = 0xFA0002
movl 0x10b12(%rip), %edi     # 0x153fc
movl $0x10, %edx
callq 0x4070
leaq 0xa742(%rip), %rbx      # 0xf03d
testl %eax, %eax
js 0x59e9
movq $0x0, 0x10b06(%rip) # 0x15414
leaq 0x10af7(%rip), %rsi     # 0x1540c
movq $0x1fa0002, 0x10aec(%rip) # imm = 0x1FA0002
movl 0x10ada(%rip), %edi     # 0x15400
movl $0x10, %edx
callq 0x4070
testl %eax, %eax
js 0x59e9
leaq -0xb4(%rbp), %rbx
movq $0x0, 0x8(%rbx)
movw $0x2, (%rbx)
leaq 0xa6f6(%rip), %rdi      # 0xf049
callq 0x4310
movl %eax, 0x4(%rbx)
movw $0x50c3, 0x2(%rbx)      # imm = 0x50C3
movl 0x10a95(%rip), %edi     # 0x153fc
movl $0x50, %edx
leaq -0xa0(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xc4(%rbp), %r8
leaq -0xa4(%rbp), %r9
callq 0x4270
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x4a3a
movslq 0x10a3c(%rip), %rdx     # 0x153d8
testq %rdx, %rdx
jle 0x49de
movl -0xc0(%rbp), %ecx
movq 0x10a22(%rip), %rax     # 0x153d0
shlq $0x4, %rdx
leaq (%rdx,%rdx,8), %rdx
movl $0x8, %r15d
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpl 0x4(%rax,%r13), %ecx
je 0x4a88
addq $0x90, %r13
addq $0x20, %r15
incl %ebx
cmpq %r13, %rdx
jne 0x49c1
cmpl $0x2f, %r12d
jne 0x4a79
callq 0x47bc
movl $0x18, %edx
movq 0x105d7(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa66e(%rip), %rsi      # 0xf071
callq 0x4370
movl -0xc0(%rbp), %edi
callq 0x4130
testq %rax, %rax
je 0x517b
movq %rax, %rbx
movq %rax, %rdi
callq 0x4120
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4370
jmp 0x5193
callq 0x47bc
movl $0x1d, %edx
movq 0x10585(%rip), %rbx     # 0x14fd0
movq %rbx, %rdi
leaq 0xa5fe(%rip), %rsi      # 0xf053
callq 0x4370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %rbx, %rdi
jmp 0x51c1
xorl %r9d, %r9d
movb $0x1, %cl
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4cb9
movb 0x7(%rax,%r13), %cl
movb %cl, -0x98(%rbp)
movb 0x6(%rax,%r13), %cl
movb %cl, -0x97(%rbp)
movb 0x5(%rax,%r13), %cl
movb %cl, -0x96(%rbp)
movb 0x4(%rax,%r13), %cl
movb %cl, -0x95(%rbp)
xorl %ecx, %ecx
cmpl $0x2f, %r12d
jne 0x4cb6
movb -0x8c(%rbp), %dl
movb -0x8b(%rbp), %cl
movl %edx, %esi
xorb $0xa, %sil
movl %ecx, %r8d
xorb $0x5, %r8b
orb %sil, %r8b
movb -0x8a(%rbp), %sil
movl %esi, %r9d
xorb $0xa, %r9b
movb -0x89(%rbp), %dil
movl %edi, %r10d
xorb $0x10, %r10b
orb %r9b, %r10b
orb %r8b, %r10b
movb -0x84(%rbp), %r8b
movl %r8d, %r9d
xorb $0x1, %r9b
orb %r10b, %r9b
jne 0x51d3
movzbl -0x81(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x7e(%rbp), %esi
orl %ecx, %esi
movzbl -0x83(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x80(%rbp), %r14d
orl %ecx, %r14d
movzbl -0x88(%rbp), %edi
movl $0x0, 0x74(%rax,%r13)
movl %r14d, %ecx
orl %esi, %ecx
je 0x4961
movl 0x84(%rax,%r13), %ecx
cmpl %esi, %ecx
setne %dl
testl %ecx, %ecx
sete %cl
orb %dl, %cl
je 0x5421
movl 0x80(%rax,%r13), %ecx
cmpl %esi, %ecx
setne %dl
testl %ecx, %ecx
sete %cl
orb %dl, %cl
je 0x561a
cmpb 0x49(%rax,%r13), %dil
movl %edi, -0x38(%rbp)
jne 0x584b
movl $0x1, 0x38(%rax,%r13)
movl %esi, 0x4c(%rax,%r13)
movl %esi, 0x40(%rax,%r13)
movl %r14d, 0x68(%rax,%r13)
movl %esi, -0x2c(%rbp)
callq 0x47bc
movl $0xc, %edx
movq 0x10410(%rip), %rdi     # 0x14fd0
leaq 0xa704(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0x1080d(%rip), %rax     # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq 0x103ed(%rip), %rdi     # 0x14fd0
callq 0x4370
movq %rax, -0x40(%rbp)
movl $0x1e, %edx
movq %rax, %rdi
leaq 0xa549(%rip), %rsi      # 0xf144
callq 0x4370
movq -0x40(%rbp), %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa4ed(%rip), %rsi      # 0xf10b
callq 0x4370
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa523(%rip), %rsi      # 0xf163
callq 0x4370
movq %r14, %rdi
movl -0x38(%rbp), %esi
callq 0x4520
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x1074f(%rip), %rax     # 0x153d0
movl $0x0, 0x28(%rax,%r13)
movb -0x8c(%rbp), %dl
movb -0x8b(%rbp), %cl
movb -0x8a(%rbp), %sil
movb -0x89(%rbp), %dil
movl $0x1, %r9d
movb -0x84(%rbp), %r8b
jmp 0x51d6
xorl %r9d, %r9d
cmpl $0x3b, %r12d
je 0x5121
cmpl $0x35, %r12d
je 0x5121
cmpl $0x2b, %r12d
jne 0x4961
movslq %ebx, %r13
movq 0x106ef(%rip), %rax     # 0x153d0
leaq (,%r13,8), %r14
addq %r13, %r14
shlq $0x4, %r14
cmpl $0x1, 0x7c(%rax,%r14)
je 0x4961
leaq (%rax,%r14), %rsi
cmpl $0x1, 0x88(%rsi)
jne 0x4961
movzwl -0x87(%rbp), %r15d
movzwl -0x89(%rbp), %r12d
movzbl -0x8c(%rbp), %edi
cmpb 0x49(%rsi), %dil
movl %edi, -0x2c(%rbp)
jne 0x54dc
movb -0x8f(%rbp), %dl
movb -0x8e(%rbp), %cl
cmpb $0x6, %dl
movl %r15d, -0x40(%rbp)
movl %r12d, -0x44(%rbp)
jne 0x4e81
cmpb $0x18, %cl
jne 0x4e81
cmpb $0x20, -0x8b(%rbp)
jne 0x4e81
movl $0x1, 0x38(%rsi)
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %rcx
movq %rcx, -0x38(%rbp)
movl -0x40(%rbp), %r15d
movl %r15d, 0x4c(%rax,%rcx)
movl %r15d, 0x40(%rax,%rcx)
movl %r12d, 0x68(%rax,%rcx)
callq 0x47bc
movl $0xc, %edx
movq 0x10232(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa523(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0x1062c(%rip), %rax     # 0x153e0
movq %r13, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %r14, %rdi
callq 0x4370
movq %rax, %r14
movl $0x26, %edx
movq %rax, %rdi
leaq 0xa43d(%rip), %rsi      # 0xf21b
callq 0x4370
movq %r14, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa30b(%rip), %rsi      # 0xf10b
callq 0x4370
movq %r14, %rdi
movl %r15d, %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa341(%rip), %rsi      # 0xf163
callq 0x4370
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x1056d(%rip), %rax     # 0x153d0
movq -0x38(%rbp), %rcx
movl $0x0, 0x28(%rax,%rcx)
movb -0x8f(%rbp), %dl
movb -0x8e(%rbp), %cl
movl $0x1, %r9d
movl %edx, %esi
xorb $0x1, %sil
movl %ecx, %edi
xorb $0x18, %dil
orb %sil, %dil
movl %r9d, -0x38(%rbp)
jne 0x4faa
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %r15
movl $0x1, 0x38(%rax,%r15)
movl 0x4c(%rax,%r15), %ecx
movl %ecx, -0x40(%rbp)
movl 0x68(%rax,%r15), %r12d
callq 0x47bc
movl $0xc, %edx
movq 0x10104(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa3f5(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0x104fe(%rip), %rax     # 0x153e0
movq %r13, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %r14, %rdi
callq 0x4370
movq %rax, %r14
movl $0x25, %edx
movq %rax, %rdi
leaq 0xa336(%rip), %rsi      # 0xf242
callq 0x4370
movq %r14, %rdi
movl %r12d, -0x44(%rbp)
movl %r12d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa1d9(%rip), %rsi      # 0xf10b
callq 0x4370
movq %r14, %rdi
movl -0x40(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa20f(%rip), %rsi      # 0xf163
callq 0x4370
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x1043b(%rip), %rax     # 0x153d0
movl $0x0, 0x28(%rax,%r15)
movb -0x8f(%rbp), %dl
movb -0x8e(%rbp), %cl
cmpb $0x6, %dl
movl -0x40(%rbp), %r12d
jne 0x50c0
cmpb $0x18, %cl
jne 0x50c0
cmpb $0x10, -0x8b(%rbp)
je 0x4fd6
cmpb $0x8, -0x8d(%rbp)
jne 0x50c0
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %r15
xorl %edx, %edx
movl %edx, 0x38(%rax,%r15)
movl 0x4c(%rax,%r15), %ecx
movl %ecx, 0x50(%rax,%r15)
movl %edx, 0x28(%rax,%r15)
callq 0x47bc
movl $0xc, %edx
movq 0xffc8(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0xa2b9(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0x103c2(%rip), %rax     # 0x153e0
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq %r14, %rdi
callq 0x4370
movq %rax, %r14
movl $0x25, %edx
movq %rax, %rdi
leaq 0xa223(%rip), %rsi      # 0xf268
callq 0x4370
movq %r14, %rdi
movl -0x44(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa0a4(%rip), %rsi      # 0xf10b
callq 0x4370
movq %r14, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x10328(%rip), %rax     # 0x153d0
xorl %ecx, %ecx
movl %ecx, 0x28(%rax,%r15)
movl 0x4c(%rax,%r15), %r12d
jmp 0x50c0
movl $0x1, %edi
callq 0x4450
cmpl $0x1, 0x1033d(%rip)     # 0x15404
je 0x50b6
movl $0x1, 0x10331(%rip)     # 0x15404
movl 0x10323(%rip), %edi     # 0x153fc
movl $0x2b, %edx
leaq -0xa0(%rbp), %r14
movq %r14, %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x102fe(%rip)     # 0x15404
movq %r14, %rdi
movl $0x2b, %esi
movl %r12d, %edx
movl %ebx, %ecx
movl -0x38(%rbp), %r8d
callq 0x5a05
jmp 0x4961
movq 0x102a8(%rip), %r8      # 0x153d0
movslq %ebx, %r13
leaq (,%r13,8), %r14
addq %r13, %r14
shlq $0x4, %r14
cmpl $0x0, 0x7c(%r8,%r14)
jne 0x4961
testb %cl, %cl
je 0x534e
cmpl $0x0, 0x10287(%rip)     # 0x153dc
je 0x4961
callq 0x47bc
movl $0x17, %edx
movq 0xfe64(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0x9efc(%rip), %rsi      # 0xf072
jmp 0x4a03
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x44f0
movl $0x11, %edx
movq %r14, %rdi
leaq 0x9ee8(%rip), %rsi      # 0xf08a
callq 0x4370
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
jmp 0x4961
xorl %r9d, %r9d
cmpb $0xa, %dl
jne 0x5320
cmpb $0x5, %cl
jne 0x5320
cmpb $0xa, %sil
jne 0x5320
cmpb $0x10, %dil
jne 0x5320
cmpb $0x8, %r8b
jne 0x5320
movzbl -0x81(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x7e(%rbp), %edx
orl %ecx, %edx
movzbl -0x83(%rbp), %ecx
shll $0x8, %ecx
movzbl -0x80(%rbp), %r14d
orl %ecx, %r14d
movl %r14d, %ecx
orl %edx, %ecx
je 0x4961
cmpl $0x0, 0x38(%rax,%r13)
je 0x4961
movl %edx, -0x2c(%rbp)
movzbl -0x88(%rbp), %ecx
cmpb 0x49(%rax,%r13), %cl
jne 0x56f2
xorl %edx, %edx
movl %edx, 0x38(%rax,%r13)
movl 0x4c(%rax,%r13), %ecx
movl %ecx, 0x50(%rax,%r13)
movl %edx, 0x28(%rax,%r13)
movl %r9d, -0x38(%rbp)
callq 0x47bc
movl $0xc, %edx
movq 0xfd51(%rip), %rdi      # 0x14fd0
leaq 0xa045(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0x1014e(%rip), %rax     # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq 0xfd2e(%rip), %rdi      # 0x14fd0
callq 0x4370
movq %rax, %r15
movl $0x1d, %edx
movq %rax, %rdi
leaq 0x9ed4(%rip), %rsi      # 0xf18d
callq 0x4370
movq %r15, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9e30(%rip), %rsi      # 0xf10b
callq 0x4370
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl -0x38(%rbp), %r9d
movq 0x100b0(%rip), %rax     # 0x153d0
cmpl $0x0, 0x7c(%rax,%r13)
jne 0x4961
movl %r9d, -0x38(%rbp)
movl 0x4c(%rax,%r13), %r14d
cmpl $0x1, 0x100c8(%rip)     # 0x15404
jne 0x547c
movl $0x1, %edi
callq 0x4450
jmp 0x5335
movb -0x9f(%rbp), %cl
movb -0x8b(%rbp), %al
orb -0xa0(%rbp), %cl
sete %cl
cmpb $-0x67, %al
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x53d6
cmpl $0x1, 0x1008e(%rip)     # 0x15404
jne 0x5392
movl $0x1, %edi
callq 0x4450
cmpl $0x1, 0x1007b(%rip)     # 0x15404
je 0x5378
movq 0x1003e(%rip), %r8      # 0x153d0
movl $0x1, 0x10068(%rip)     # 0x15404
movb $-0x68, -0x8b(%rbp)
movl 0x10053(%rip), %edi     # 0x153fc
andl $0x3f, %r12d
addq %r14, %r8
leaq -0xa0(%rbp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x10033(%rip)     # 0x15404
jmp 0x4961
cmpb $-0x68, %al
sete %al
testb %al, %cl
jne 0x4961
leaq (%r8,%r14), %rax
movl $0x0, 0x74(%rax)
cmpl $0x0, 0x38(%rax)
je 0x599b
movl %r9d, -0x38(%rbp)
movl $0x0, 0x28(%rax)
movl 0x4c(%r8,%r14), %r14d
cmpl $0x1, 0xfff5(%rip)      # 0x15404
jne 0x568b
movl $0x1, %edi
callq 0x4450
jmp 0x5408
movl $0x1, 0x7c(%rax,%r13)
movl %esi, %r14d
callq 0x47bc
movl $0xd, %edx
movq 0xfb92(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9c54(%rip), %rsi      # 0xf09c
callq 0x4370
movq 0xff8c(%rip), %rax      # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x18, %edx
movq %rax, %rdi
leaq 0x9c33(%rip), %rsi      # 0xf0aa
jmp 0x5670
movl $0x1, 0xff7e(%rip)      # 0x15404
movl 0xff70(%rip), %edi      # 0x153fc
movl $0x2f, %edx
leaq -0xa0(%rbp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0xff4b(%rip)      # 0x15404
movq %r15, %rdi
movl $0x2f, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl -0x38(%rbp), %r14d
movl %r14d, %r8d
callq 0x5a05
xorl %ecx, %ecx
movl %r14d, %r9d
jmp 0x4cb9
callq 0x47bc
movl $0xc, %edx
movq 0xfae3(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9dd4(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0xfedd(%rip), %rax      # 0x153e0
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x2d, %edx
movq %rax, %rdi
leaq 0x9cc3(%rip), %rsi      # 0xf1ed
callq 0x4370
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9bbf(%rip), %rsi      # 0xf10b
callq 0x4370
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9ba8(%rip), %rsi      # 0xf116
callq 0x4370
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0x9b95(%rip), %rsi      # 0xf125
callq 0x4370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
cmpl $0x1, 0xfe41(%rip)      # 0x15404
jne 0x55d1
movl $0x1, %edi
callq 0x4450
jmp 0x55bc
movl $0x1, 0xfe29(%rip)      # 0x15404
movl 0xfe1b(%rip), %edi      # 0x153fc
movl $0x2b, %edx
leaq -0xa0(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
xorl %ecx, %ecx
movl %ecx, 0xfdfb(%rip)      # 0x15404
movq 0xfdc0(%rip), %rax      # 0x153d0
movl %ecx, 0x38(%rax,%r14)
jmp 0x4961
movl $0x0, 0x7c(%rax,%r13)
movl %esi, %r14d
callq 0x47bc
movl $0xe, %edx
movq 0xf999(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9a82(%rip), %rsi      # 0xf0c3
callq 0x4370
movq 0xfd93(%rip), %rax      # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x17, %edx
movq %rax, %rdi
leaq 0x9a62(%rip), %rsi      # 0xf0d2
callq 0x4370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %rbx
movq (%rax), %rax
jmp 0x4a5d
movl $0x1, 0xfd6f(%rip)      # 0x15404
movl 0xfd61(%rip), %edi      # 0x153fc
movl %r12d, %edx
andl $0x3f, %edx
leaq -0xa0(%rbp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0xfd3b(%rip)      # 0x15404
movq %r15, %rdi
movl %r12d, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl -0x38(%rbp), %r14d
movl %r14d, %r8d
callq 0x5a05
movl %r14d, %r9d
cmpl $0x2b, %r12d
jne 0x4961
jmp 0x4cda
movl %ecx, %r12d
callq 0x47bc
movl $0xc, %edx
movq 0xf8ca(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9bbb(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0xfcc4(%rip), %rax      # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x1f, %edx
movq %rax, %rdi
leaq 0x9a2e(%rip), %rsi      # 0xf16d
callq 0x4370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x99aa(%rip), %rsi      # 0xf10b
callq 0x4370
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9993(%rip), %rsi      # 0xf116
callq 0x4370
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0x9980(%rip), %rsi      # 0xf125
callq 0x4370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
cmpl $0x1, 0xfc2c(%rip)      # 0x15404
jne 0x57e6
movl $0x1, %edi
callq 0x4450
jmp 0x57d1
movl $0x1, 0xfc14(%rip)      # 0x15404
movl 0xfc06(%rip), %edi      # 0x153fc
movl $0x2f, %edx
leaq -0xa0(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0xfbe4(%rip)      # 0x15404
cmpl $0x0, -0x2c(%rbp)
jne 0x4961
movq 0xfb9f(%rip), %rax      # 0x153d0
xorl %ecx, %ecx
movl %ecx, 0x38(%rax,%r13)
movl %ecx, 0x28(%rax,%r13)
movq $0x0, 0x4c(%rax,%r13)
jmp 0x4961
movl %esi, %r12d
callq 0x47bc
movl $0xc, %edx
movq 0xf771(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9a62(%rip), %rsi      # 0xf2cb
callq 0x4370
movq 0xfb6b(%rip), %rax      # 0x153e0
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x20, %edx
movq %rax, %rdi
leaq 0x9852(%rip), %rsi      # 0xf0ea
callq 0x4370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9851(%rip), %rsi      # 0xf10b
callq 0x4370
movq %rbx, %rdi
movl %r12d, %r14d
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9837(%rip), %rsi      # 0xf116
callq 0x4370
movq %rbx, %rdi
movl -0x38(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0x9824(%rip), %rsi      # 0xf125
callq 0x4370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
cmpl $0x1, 0xfad0(%rip)      # 0x15404
jne 0x5942
movl $0x1, %edi
callq 0x4450
jmp 0x592d
movl $0x1, %ebx
movl %ebx, 0xfab7(%rip)      # 0x15404
movl 0xfaa9(%rip), %edi      # 0x153fc
movl $0x2f, %edx
leaq -0xa0(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb4(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
xorl %ecx, %ecx
movl %ecx, 0xfa89(%rip)      # 0x15404
movq 0xfa4e(%rip), %rax      # 0x153d0
movl %ebx, 0x38(%rax,%r13)
movl %ecx, 0x28(%rax,%r13)
movl %r14d, 0x4c(%rax,%r13)
movl %r14d, 0x50(%rax,%r13)
jmp 0x4961
cmpl $0x0, 0xfa3a(%rip)      # 0x153dc
je 0x4961
callq 0x47bc
movl $0x29, %edx
movq 0xf617(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0x97e8(%rip), %rsi      # 0xf1ab
callq 0x4370
movq %r14, %rdi
movl %ebx, %esi
callq 0x4520
movq %rax, %rbx
movl $0x17, %edx
movq %rax, %rdi
leaq 0x97f1(%rip), %rsi      # 0xf1d5
jmp 0x4a55
movq %rbx, %rdi
callq 0x42b0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq