// File: /workspace/github_cpp_makefile_star2_O1/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)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0x10b83(%rip)     # 0x153fc
leaq 0xa7c3(%rip), %rbx      # 0xf043
testl %eax, %eax
js 0x5941
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0x10b61(%rip)     # 0x15400
testl %eax, %eax
js 0x5941
xorps %xmm0, %xmm0
movups %xmm0, 0x10b5b(%rip)    # 0x1540c
leaq 0x10b54(%rip), %rsi     # 0x1540c
movq $0xfa0002, 0x10b49(%rip) # imm = 0xFA0002
movl 0x10b33(%rip), %edi     # 0x153fc
movl $0x10, %edx
callq 0x4070
leaq 0xa77f(%rip), %rbx      # 0xf059
testl %eax, %eax
js 0x5941
xorps %xmm0, %xmm0
movups %xmm0, 0x10b20(%rip)    # 0x1540c
leaq 0x10b19(%rip), %rsi     # 0x1540c
movq $0x1fa0002, 0x10b0e(%rip) # imm = 0x1FA0002
movl 0x10afc(%rip), %edi     # 0x15400
movl $0x10, %edx
callq 0x4070
testl %eax, %eax
js 0x5941
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rbx
movaps %xmm0, (%rbx)
movw $0x2, (%rbx)
leaq 0xa736(%rip), %rdi      # 0xf065
callq 0x4310
movl %eax, 0x4(%rbx)
movw $0x50c3, 0x2(%rbx)      # imm = 0x50C3
movl 0x10ab9(%rip), %edi     # 0x153fc
movl $0x50, %edx
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xc0(%rbp), %r8
leaq -0x94(%rbp), %r9
callq 0x4270
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x49a6
movslq 0x10a64(%rip), %rax     # 0x153d8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
jle 0x49e7
movl -0xbc(%rbp), %ecx
movq 0x10a45(%rip), %rdx     # 0x153d0
addq $0x4, %rdx
xorl %esi, %esi
cmpl (%rdx), %ecx
je 0x49e5
incq %rsi
addq $0x90, %rdx
cmpq %rsi, %rax
jne 0x4991
jmp 0x49e7
callq 0x479c
movl $0x1d, %edx
movq 0x10619(%rip), %rbx     # 0x14fd0
movq %rbx, %rdi
leaq 0xa6ae(%rip), %rsi      # 0xf06f
callq 0x4370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42f0
movsbl %al, %esi
movq %rbx, %rdi
jmp 0x4e1d
movl %esi, %ebx
cmpl $-0x1, %ebx
je 0x4a26
movq 0x109dd(%rip), %rax     # 0x153d0
movslq %ebx, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x4, %rcx
movb 0x7(%rax,%rcx), %dl
movb %dl, -0x88(%rbp)
movb 0x6(%rax,%rcx), %dl
movb %dl, -0x87(%rbp)
movb 0x5(%rax,%rcx), %dl
movb %dl, -0x86(%rbp)
movb 0x4(%rax,%rcx), %al
movb %al, -0x85(%rbp)
xorl %r15d, %r15d
cmpl $0x2f, %r12d
jne 0x4ede
cmpl $-0x1, %ebx
je 0x4d8c
xorl %r15d, %r15d
cmpb $0xa, -0x7c(%rbp)
jne 0x4c0b
cmpb $0x5, -0x7b(%rbp)
jne 0x4c0b
cmpb $0xa, -0x7a(%rbp)
jne 0x4c0b
cmpb $0x10, -0x79(%rbp)
jne 0x4c0b
cmpb $0x1, -0x74(%rbp)
jne 0x4c0b
movzbl -0x71(%rbp), %eax
shll $0x8, %eax
movzbl -0x6e(%rbp), %edi
orl %eax, %edi
movzbl -0x73(%rbp), %eax
shll $0x8, %eax
movzbl -0x70(%rbp), %r14d
orl %eax, %r14d
movzbl -0x78(%rbp), %r8d
movq 0x10937(%rip), %rax     # 0x153d0
movslq %ebx, %r15
leaq (%r15,%r15,8), %r13
shlq $0x4, %r13
movl $0x0, 0x74(%rax,%r13)
movl %r14d, %ecx
orl %edi, %ecx
je 0x493d
leaq (%rax,%r13), %rcx
movl 0x84(%rax,%r13), %edx
cmpl %edi, %edx
setne %sil
testl %edx, %edx
sete %dl
orb %sil, %dl
je 0x4e2f
movl 0x80(%rcx), %edx
cmpl %edi, %edx
setne %sil
testl %edx, %edx
sete %dl
orb %sil, %dl
je 0x5013
cmpb 0x49(%rcx), %r8b
movl %r8d, -0x2c(%rbp)
jne 0x579f
movl $0x1, 0x38(%rcx)
movq %r15, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %rcx
movq %rcx, -0x38(%rbp)
movl %edi, 0x4c(%rax,%rcx)
movl %edi, 0x40(%rax,%rcx)
movl %r14d, 0x68(%rax,%rcx)
movl %edi, -0x30(%rbp)
callq 0x479c
movl $0xc, %edx
movq 0x10499(%rip), %r13     # 0x14fd0
movq %r13, %rdi
leaq 0xa7a6(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0x10893(%rip), %rax     # 0x153e0
shlq $0x5, %r15
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %r13, %rdi
callq 0x4370
movq %rax, %r13
movl $0x1e, %edx
movq %rax, %rdi
leaq 0xa5ec(%rip), %rsi      # 0xf160
callq 0x4370
movq %r13, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa591(%rip), %rsi      # 0xf127
callq 0x4370
movq %r14, %rdi
movl -0x30(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa5c7(%rip), %rsi      # 0xf17f
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 0x107d7(%rip), %rax     # 0x153d0
movq -0x38(%rbp), %rcx
movl $0x0, 0x28(%rax,%rcx)
movl $0x1, %r15d
cmpb $0xa, -0x7c(%rbp)
jne 0x4d4f
cmpb $0x5, -0x7b(%rbp)
jne 0x4d4f
cmpb $0xa, -0x7a(%rbp)
jne 0x4d4f
cmpb $0x10, -0x79(%rbp)
jne 0x4d4f
cmpb $0x8, -0x74(%rbp)
jne 0x4d4f
movzbl -0x71(%rbp), %eax
shll $0x8, %eax
movzbl -0x6e(%rbp), %ecx
orl %eax, %ecx
movzbl -0x73(%rbp), %eax
shll $0x8, %eax
movzbl -0x70(%rbp), %r13d
orl %eax, %r13d
movl %r13d, %eax
orl %ecx, %eax
je 0x493d
movq 0x10765(%rip), %rax     # 0x153d0
movslq %ebx, %r14
leaq (%r14,%r14,8), %rdi
shlq $0x4, %rdi
cmpl $0x0, 0x38(%rax,%rdi)
je 0x493d
movl %ecx, -0x2c(%rbp)
movzbl -0x78(%rbp), %edx
leaq (%rax,%rdi), %rcx
cmpb 0x49(%rcx), %dl
jne 0x5086
xorl %esi, %esi
movl %esi, 0x38(%rcx)
movl 0x4c(%rcx), %edx
movl %edx, 0x50(%rcx)
movl %esi, 0x28(%rax,%rdi)
callq 0x479c
movl $0xc, %edx
movq 0x1031b(%rip), %rdi     # 0x14fd0
leaq 0xa62b(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0x10718(%rip), %rax     # 0x153e0
shlq $0x5, %r14
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
movq 0x102f4(%rip), %rdi     # 0x14fd0
callq 0x4370
movq %rax, %r14
movl $0x1d, %edx
movq %rax, %rdi
leaq 0xa4b6(%rip), %rsi      # 0xf1a9
callq 0x4370
movq %r14, %rdi
movl %r13d, %esi
callq 0x4520
movq %rax, %r13
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa412(%rip), %rsi      # 0xf127
callq 0x4370
movq %r13, %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 0x1067a(%rip), %rax     # 0x153d0
movslq %ebx, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x4, %rcx
cmpl $0x0, 0x7c(%rax,%rcx)
jne 0x493d
addq %rcx, %rax
movl 0x4c(%rax), %r14d
cmpl $0x1, 0x1068a(%rip)     # 0x15404
jne 0x4e8c
movl $0x1, %edi
callq 0x4450
jmp 0x4d73
callq 0x479c
movl $0x18, %edx
movq 0x10233(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa2e6(%rip), %rsi      # 0xf08d
callq 0x4370
movl -0xbc(%rbp), %edi
callq 0x4130
testq %rax, %rax
je 0x4dd7
movq %rax, %rbx
movq %rax, %rdi
callq 0x4120
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4370
jmp 0x4def
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 0xa2a8(%rip), %rsi      # 0xf0a6
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 0x493d
movl $0x1, 0x7c(%rcx)
movl %edi, %r14d
callq 0x479c
movl $0xd, %edx
movq 0x10186(%rip), %rbx     # 0x14fd0
movq %rbx, %rdi
leaq 0xa264(%rip), %rsi      # 0xf0b8
callq 0x4370
movq 0x10580(%rip), %rax     # 0x153e0
shlq $0x5, %r15
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x18, %edx
movq %rax, %rdi
leaq 0xa23f(%rip), %rsi      # 0xf0c6
jmp 0x506b
movl $0x1, 0x1056e(%rip)     # 0x15404
movl 0x10560(%rip), %edi     # 0x153fc
movl $0x2f, %edx
leaq -0x90(%rbp), %r13
movq %r13, %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x1053b(%rip)     # 0x15404
movq %r13, %rdi
movl $0x2f, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x595d
cmpl $0x2b, %r12d
je 0x5241
cmpl $0x3b, %r12d
je 0x4ef8
cmpl $0x35, %r12d
jne 0x493d
movq 0x104d1(%rip), %rax     # 0x153d0
movslq %ebx, %rcx
leaq (%rcx,%rcx,8), %r14
shlq $0x4, %r14
cmpl $0x0, 0x7c(%rax,%r14)
jne 0x493d
cmpl $-0x1, %ebx
je 0x4f56
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 0x4f83
cmpl $0x1, 0x104c0(%rip)     # 0x15404
jne 0x4fcb
movl $0x1, %edi
callq 0x4450
jmp 0x4f3d
cmpl $0x0, 0x1047f(%rip)     # 0x153dc
je 0x493d
callq 0x479c
movl $0x17, %edx
movq 0x1005c(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa110(%rip), %rsi      # 0xf08e
jmp 0x4da7
cmpb $-0x68, %cl
sete %cl
testb %cl, %dl
jne 0x493d
leaq (%rax,%r14), %rcx
movl $0x0, 0x74(%rcx)
cmpl $0x0, 0x38(%rcx)
je 0x58f3
movl $0x0, 0x28(%rcx)
movl 0x4c(%rax,%r14), %r14d
cmpl $0x1, 0x1044b(%rip)     # 0x15404
jne 0x51e6
movl $0x1, %edi
callq 0x4450
jmp 0x4fb2
movl $0x1, 0x1042f(%rip)     # 0x15404
movb $-0x68, -0x7b(%rbp)
movl 0x1041d(%rip), %edi     # 0x153fc
andl $0x3f, %r12d
addq 0x103e6(%rip), %r14     # 0x153d0
leaq -0x90(%rbp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x103f6(%rip)     # 0x15404
jmp 0x493d
movl $0x0, 0x7c(%rcx)
movl %edi, %r14d
callq 0x479c
movl $0xe, %edx
movq 0xffa2(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0xa0a7(%rip), %rsi      # 0xf0df
callq 0x4370
movq 0x1039c(%rip), %rax     # 0x153e0
shlq $0x5, %r15
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x17, %edx
movq %rax, %rdi
leaq 0xa083(%rip), %rsi      # 0xf0ee
callq 0x4370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %rbx
movq (%rax), %rax
jmp 0x49c9
movq %rdi, %r15
movl %edx, %r12d
callq 0x479c
movl $0xc, %edx
movq 0xff33(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0xa240(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0x1032d(%rip), %rax     # 0x153e0
shlq $0x5, %r14
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x1f, %edx
movq %rax, %rdi
leaq 0xa0af(%rip), %rsi      # 0xf189
callq 0x4370
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa02b(%rip), %rsi      # 0xf127
callq 0x4370
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0xa014(%rip), %rsi      # 0xf132
callq 0x4370
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0xa001(%rip), %rsi      # 0xf141
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, 0x10291(%rip)     # 0x15404
jne 0x5181
movl $0x1, %edi
callq 0x4450
jmp 0x516c
movl $0x1, 0x10279(%rip)     # 0x15404
movl 0x1026b(%rip), %edi     # 0x153fc
movl $0x2f, %edx
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x10249(%rip)     # 0x15404
cmpl $0x0, -0x2c(%rbp)
jne 0x493d
movq 0x10204(%rip), %rax     # 0x153d0
xorl %ecx, %ecx
movl %ecx, 0x38(%rax,%r15)
movl %ecx, 0x28(%rax,%r15)
movq $0x0, 0x4c(%rax,%r15)
jmp 0x493d
movl $0x1, 0x10214(%rip)     # 0x15404
movl 0x10206(%rip), %edi     # 0x153fc
movl %r12d, %edx
andl $0x3f, %edx
leaq -0x90(%rbp), %r13
movq %r13, %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0x101e0(%rip)     # 0x15404
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x595d
cmpl $0x2b, %r12d
jne 0x493d
movq 0x10188(%rip), %rax     # 0x153d0
movslq %ebx, %r13
leaq (,%r13,8), %r14
addq %r13, %r14
shlq $0x4, %r14
cmpl $0x1, 0x7c(%rax,%r14)
je 0x493d
leaq (%rax,%r14), %rcx
cmpl $0x1, 0x88(%rcx)
jne 0x493d
movzwl -0x77(%rbp), %r12d
movzwl -0x79(%rbp), %edx
movzbl -0x7c(%rbp), %esi
cmpb 0x49(%rcx), %sil
movl %esi, -0x2c(%rbp)
jne 0x565e
cmpb $0x6, -0x7f(%rbp)
movq 0xfd34(%rip), %r14      # 0x14fd0
jne 0x53bb
cmpb $0x18, -0x7e(%rbp)
jne 0x53bb
cmpb $0x20, -0x7b(%rbp)
jne 0x53bb
movl $0x1, 0x38(%rcx)
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %r15
movl %r12d, 0x4c(%rax,%r15)
movl %r12d, 0x40(%rax,%r15)
movl %edx, 0x68(%rax,%r15)
movl %edx, -0x38(%rbp)
callq 0x479c
movl $0xc, %edx
movq %r14, %rdi
leaq 0x9ff9(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0x100e6(%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 0x9f13(%rip), %rsi      # 0xf237
callq 0x4370
movq %r14, %rdi
movl -0x38(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9de1(%rip), %rsi      # 0xf127
callq 0x4370
movq %r14, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0x9e17(%rip), %rsi      # 0xf17f
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), %edx
movq 0x10024(%rip), %rax     # 0x153d0
movl $0x0, 0x28(%rax,%r15)
movl $0x1, %r15d
cmpb $0x1, -0x7f(%rbp)
jne 0x54e2
cmpb $0x18, -0x7e(%rbp)
jne 0x54e2
movq 0xfffa(%rip), %rax      # 0x153d0
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,8), %rdx
movq %rdx, -0x38(%rbp)
movl $0x1, 0x38(%rax,%rdx)
movl 0x4c(%rax,%rdx), %ecx
movl %ecx, -0x30(%rbp)
movl 0x68(%rax,%rdx), %r12d
callq 0x479c
movl $0xc, %edx
movq 0xfbc6(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0x9ed3(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0xffc0(%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 0x9e14(%rip), %rsi      # 0xf25e
callq 0x4370
movq %r14, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9cbb(%rip), %rsi      # 0xf127
callq 0x4370
movq %r14, %rdi
movl -0x30(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0x9, %edx
movq %rax, %rdi
leaq 0x9cf1(%rip), %rsi      # 0xf17f
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 %r12d, %edx
movq 0xfefe(%rip), %rax      # 0x153d0
movq -0x38(%rbp), %rcx
movl $0x0, 0x28(%rax,%rcx)
movl -0x30(%rbp), %r12d
cmpb $0x6, -0x7f(%rbp)
jne 0x55fe
cmpb $0x18, -0x7e(%rbp)
jne 0x55fe
cmpb $0x10, -0x7b(%rbp)
je 0x5506
cmpb $0x8, -0x7d(%rbp)
jne 0x55fe
movq 0xfec3(%rip), %rax      # 0x153d0
movq %r13, %rcx
shlq $0x4, %rcx
movl %r12d, -0x30(%rbp)
leaq (%rcx,%rcx,8), %r12
xorl %esi, %esi
movl %esi, 0x38(%rax,%r12)
movl 0x4c(%rax,%r12), %ecx
movl %ecx, 0x50(%rax,%r12)
movl %esi, 0x28(%rax,%r12)
movl %edx, -0x38(%rbp)
callq 0x479c
movl $0xc, %edx
movq 0xfa8a(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0x9d97(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0xfe84(%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 0x9d01(%rip), %rsi      # 0xf284
callq 0x4370
movq %r14, %rdi
movl -0x38(%rbp), %esi
callq 0x4520
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9b82(%rip), %rsi      # 0xf127
callq 0x4370
movq %r14, %rdi
movl -0x30(%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 0xfdea(%rip), %rax      # 0x153d0
xorl %ecx, %ecx
movl %ecx, 0x28(%rax,%r12)
movl 0x4c(%rax,%r12), %r12d
jmp 0x55fe
movl $0x1, %edi
callq 0x4450
cmpl $0x1, 0xfdff(%rip)      # 0x15404
je 0x55f4
movl $0x1, 0xfdf3(%rip)      # 0x15404
movl 0xfde5(%rip), %edi      # 0x153fc
movl $0x2b, %edx
leaq -0x90(%rbp), %r14
movq %r14, %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl $0x0, 0xfdc0(%rip)      # 0x15404
movq %r14, %rdi
movl $0x2b, %esi
movl %r12d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x595d
jmp 0x493d
movl %edx, %r15d
callq 0x479c
movl $0xc, %edx
movq 0xf95e(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9c6b(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0xfd58(%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 0x9b5a(%rip), %rsi      # 0xf209
callq 0x4370
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9a56(%rip), %rsi      # 0xf127
callq 0x4370
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9a3f(%rip), %rsi      # 0xf132
callq 0x4370
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0x9a2c(%rip), %rsi      # 0xf141
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, 0xfcbc(%rip)      # 0x15404
jne 0x5756
movl $0x1, %edi
callq 0x4450
jmp 0x5741
movl $0x1, 0xfca4(%rip)      # 0x15404
movl 0xfc96(%rip), %edi      # 0x153fc
movl $0x2b, %edx
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
xorl %ecx, %ecx
movl %ecx, 0xfc76(%rip)      # 0x15404
movq 0xfc3b(%rip), %rax      # 0x153d0
movl %ecx, 0x38(%rax,%r14)
jmp 0x493d
movl %edi, %r12d
callq 0x479c
movl $0xc, %edx
movq 0xf81d(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9b2a(%rip), %rsi      # 0xf2e7
callq 0x4370
movq 0xfc17(%rip), %rax      # 0x153e0
shlq $0x5, %r15
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %rbx, %rdi
callq 0x4370
movq %rax, %rbx
movl $0x20, %edx
movq %rax, %rdi
leaq 0x9916(%rip), %rsi      # 0xf106
callq 0x4370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9915(%rip), %rsi      # 0xf127
callq 0x4370
movq %rbx, %rdi
movl %r12d, %r14d
movl %r12d, %esi
callq 0x4520
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x98fb(%rip), %rsi      # 0xf132
callq 0x4370
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x4520
movq %rax, %rbx
movl $0x1e, %edx
movq %rax, %rdi
leaq 0x98e8(%rip), %rsi      # 0xf141
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, 0xfb78(%rip)      # 0x15404
jne 0x589a
movl $0x1, %edi
callq 0x4450
jmp 0x5885
movl $0x1, %ebx
movl %ebx, 0xfb5f(%rip)      # 0x15404
movl 0xfb51(%rip), %edi      # 0x153fc
movl $0x2f, %edx
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xb0(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
xorl %ecx, %ecx
movl %ecx, 0xfb31(%rip)      # 0x15404
movq 0xfaf6(%rip), %rax      # 0x153d0
movl %ebx, 0x38(%rax,%r13)
movl %ecx, 0x28(%rax,%r13)
movl %r14d, 0x4c(%rax,%r13)
movl %r14d, 0x50(%rax,%r13)
jmp 0x493d
cmpl $0x0, 0xfae2(%rip)      # 0x153dc
je 0x493d
callq 0x479c
movl $0x29, %edx
movq 0xf6bf(%rip), %r14      # 0x14fd0
movq %r14, %rdi
leaq 0x98ac(%rip), %rsi      # 0xf1c7
callq 0x4370
movq %r14, %rdi
movl %ebx, %esi
callq 0x4520
movq %rax, %rbx
movl $0x17, %edx
movq %rax, %rdi
leaq 0x98b5(%rip), %rsi      # 0xf1f1
jmp 0x49c1
movq %rbx, %rdi
callq 0x42b0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq