// File: /workspace/github_cpp_makefile_star2_O3/rthoelen[P]NXCore_Icom/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[105];     /* receive buffer */
        unsigned char tempbuf[105];     /* receive buffer for test port packet */
	struct hostent *he;
	int rpt_id;
	int strt_packet;

	struct sockaddr_in tport;
	int GID, UID, RAN;
	int i;

        /* create UDP socket for repeaters */

        if ((socket_00 = 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 = inet_addr("10.44.0.1");
        myaddr_00.sin_addr.s_addr = htonl(INADDR_ANY);
        myaddr_00.sin_port = htons(41300);

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

	// Add a debug 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(50001);

        /* now loop, receiving data and printing what we received */
        for (;;) {

		recvlen = recvfrom(socket_00, buf, 103, 0, (struct sockaddr *)&remaddr, &addrlen);	

		// Look for I in Icom 
		if (buf[0] != 0x49)
			continue;


		// Linkup to connect Icom repeater
		if ((buf[4] == 0x01) && (buf[5] == 0x61))
		{
			buf[5]++;
			buf[37] = 0x02;
			buf[38] = 0x4f;
			buf[39] = 0x4b;
			std::cout << "Sending connect string to Repeater at IP:" << inet_ntoa(remaddr.sin_addr) << std::endl;
			
        		remaddr.sin_port = htons(41300);
			sendto(socket_00, buf, recvlen, 0, (struct sockaddr *)&remaddr,
		 		sizeof(remaddr));
			continue;
		}

	
		// Don't know what these are, but probably don't matter
		// if ((buf[38] == 0x00) && (buf[39] == 0x21))
	//		continue;
	
		if (recvlen != 102)
			continue;

		rpt_id = get_repeater_id(&remaddr);
		if (rpt_id == -1)
		{
			std::cout << "Unauthorized repeater, " << inet_ntoa(remaddr.sin_addr) << ", dropping packet" << std::endl;
			continue;  // Throw out packet, not in our list
		}

		memcpy(tempbuf,buf,102);

		tempbuf[97] = (repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 24;
                tempbuf[98] = ((repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 16) & 0xff;
                tempbuf[99] = ((repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) >> 8) & 0xff;
                tempbuf[100] = (repeater[rpt_id].rpt_addr_00.sin_addr.s_addr) & 0xff;

                if ((buf[38] == 0x1c) && (buf[39] == 0x21) && ((buf[40] == 0x81)||(buf[40] == 0x83))) {
                        buf[recvlen] = 0;


			if(buf[45] == (char)1) // Beginning of packets
			{
				GID = (buf[50] << 8) + buf[51];
				UID = (buf[48] << 8) + buf[49];
				RAN = buf[41];

				repeater[rpt_id].rx_activity = 1;

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

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

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

					sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 				sizeof(tport));

					repeater[rpt_id].rx_activity = 0;

					// Handle special case of alternate RAN for local communications
					// and block network activity
					if (GID == 0)
                                        {
                                                repeater[rpt_id].rx_activity = 1;
                                                repeater[rpt_id].time_since_rx = 0;
                                                repeater[rpt_id].active_tg = GID;
                                        }

                                        continue;
                                }

				repeater[rpt_id].uid = UID;
				repeater[rpt_id].active_tg = GID;
				repeater[rpt_id].busy_tg = GID;
				strt_packet=1;
				std::cout << "Repeater  ->" << r_list[rpt_id]
					<< "<-  receiving start from UID: " << UID
					<< " from TG: " << GID 
					<< " on RAN: " << RAN << std::endl;
			}
		
			if(buf[45] == (char)8) // End, sent shutdown on 64001	
			{
				GID = (buf[50] << 8) + buf[51];
				UID = (buf[48] << 8) + buf[49];
				RAN = buf[41];


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

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

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

					sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 				sizeof(tport));

					// Handle special case of alternate RAN for local communications
					// and block network activity
                                	if (GID == 0)
                                	{ 
						repeater[rpt_id].rx_activity = 0;
						repeater[rpt_id].time_since_rx = 0;
						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;
 
				std::cout << "Repeater  ->" << r_list[rpt_id] << "<-  receiving stop from UID: " << UID << " from TG: " << GID << std::endl;	
			}	
				
			if((buf[45] != 8)&&(repeater[rpt_id].rx_activity == 0))
				continue;

			if(repeater[rpt_id].disable)
				continue;

			repeater[rpt_id].time_since_rx = 0;
			// send packet to repeaters
			snd_packet(buf, recvlen, GID, rpt_id, strt_packet);
			strt_packet = 0;
			sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));
				
		}
               else
		if (((buf[38] == 0x00)||(buf[38] == 0x10)) && (buf[39] == 0x21)) { 


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

			GID = repeater[rpt_id].active_tg;

			repeater[rpt_id].time_since_rx = 0;

			// send packet to repeaters that can receive it
			snd_packet(buf, recvlen, GID, rpt_id, 0);

			sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));
		}

	       // Code for group call + SDM
	       //
	       // start packet
	       if ((buf[39]==0x18)&&((buf[42]==0x0f)||(buf[42]==0x09))&&(repeater[rpt_id].disable==0))
	       {

			GID = (buf[47] << 8) + buf[48];
			UID = (buf[45] << 8) + buf[46];
			RAN = buf[41];
			repeater[rpt_id].uid = UID;
			repeater[rpt_id].active_tg = GID;
			repeater[rpt_id].busy_tg = GID;
			repeater[rpt_id].rx_activity = 1;
			strt_packet=1;
			std::cout << "Repeater  ->" << r_list[rpt_id]
				<< "<-  receiving message start from UID: " << UID
				<< " from TG: " << GID 
				<< " on RAN: " << RAN << std::endl;

			// send packet to repeaters that can receive it
			snd_packet(buf, recvlen, GID, rpt_id, 0);

			sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));
	       }


	       // stop packet for group SDM
		
	       if ((buf[39]==0x18)&&(buf[42]==0x08)&&(repeater[rpt_id].disable==0))
	       {

			GID = (buf[47] << 8) + buf[48];
			UID = (buf[45] << 8) + buf[46];
			repeater[rpt_id].uid = UID;
			repeater[rpt_id].active_tg = GID;
			repeater[rpt_id].busy_tg = GID;

			repeater[rpt_id].rx_activity = 0;    // Activity on channel is over
			repeater[rpt_id].last_tg = repeater[rpt_id].active_tg;

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


			// send packet to repeaters that can receive it
			snd_packet(buf, recvlen, GID, rpt_id, 0);

			sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));

	       }

	       // datagram

		if ((buf[39] == 0x18)&&(buf[40]==0x9c)&&(buf[42]==0x0b)) { 

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

			GID = repeater[rpt_id].active_tg;

			repeater[rpt_id].time_since_rx = 0;

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



			// send packet to repeaters that can receive it
			snd_packet(buf, recvlen, GID, rpt_id, 0);

			sendto(socket_00, tempbuf, recvlen, 0, (struct sockaddr *)&tport,
		 		sizeof(tport));


		}

	}
        	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl $0x10, -0x54(%rbp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4080
movl %eax, 0x10bc7(%rip)     # 0x15380
testl %eax, %eax
js 0x567e
movq $0x0, 0x10bc4(%rip) # 0x15390
leaq 0x10bb5(%rip), %rsi     # 0x15388
movq $0x54a10002, 0x10baa(%rip) # imm = 0x54A10002
movl %eax, %edi
movl $0x10, %edx
callq 0x4070
testl %eax, %eax
js 0x5687
leaq -0x64(%rbp), %rbx
movq $0x0, 0x8(%rbx)
movw $0x2, (%rbx)
leaq 0xa82c(%rip), %rdi      # 0xf036
callq 0x42d0
movl %eax, 0x4(%rbx)
movw $0x51c3, 0x2(%rbx)      # imm = 0x51C3
leaq -0xd0(%rbp), %r12
leaq -0x48(%rbp), %r13
movl 0x10b57(%rip), %edi     # 0x15380
movl $0x67, %edx
movq %r12, %rsi
xorl %ecx, %ecx
movq %r13, %r8
leaq -0x54(%rbp), %r9
callq 0x4250
cmpb $0x49, -0xd0(%rbp)
jne 0x4823
movq %rax, %rbx
cmpb $0x1, -0xcc(%rbp)
jne 0x48be
cmpb $0x61, -0xcb(%rbp)
jne 0x48be
movb $0x62, -0xcb(%rbp)
movw $0x4f02, -0xab(%rbp)    # imm = 0x4F02
movb $0x4b, -0xa9(%rbp)
movl $0x29, %edx
movq 0x10750(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa7b6(%rip), %rsi      # 0xf040
callq 0x4330
movl -0x44(%rbp), %edi
callq 0x4120
testq %rax, %rax
je 0x4954
movq %rax, %r12
movq %rax, %rdi
callq 0x4110
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0x496c
cmpl $0x66, %ebx
leaq -0x48(%rbp), %r13
jne 0x4823
movslq 0x10aa6(%rip), %rdx     # 0x15378
testq %rdx, %rdx
jle 0x490a
movl -0x44(%rbp), %ecx
movq 0x10a77(%rip), %rax     # 0x15358
imulq $0x70, %rdx, %rdx
movl $0x8, %r14d
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpl 0x4(%rax,%r15), %ecx
je 0x49c5
addq $0x70, %r15
addq $0x20, %r14
incl %ebx
cmpq %r15, %rdx
jne 0x48f0
movl $0x17, %edx
movq 0x106ba(%rip), %r14     # 0x14fd0
movq %r14, %rdi
leaq 0xa74a(%rip), %rsi      # 0xf06a
callq 0x4330
movl -0x44(%rbp), %edi
callq 0x4120
testq %rax, %rax
je 0x4e4c
movq %rax, %rbx
movq %rax, %rdi
callq 0x4110
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0x4e64
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x44a0
leaq -0x48(%rbp), %r13
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movw $0x54a1, -0x46(%rbp)    # imm = 0x54A1
movl 0x109dd(%rip), %edi     # 0x15380
movslq %ebx, %rdx
leaq -0xd0(%rbp), %r12
movq %r12, %rsi
xorl %ecx, %ecx
movq %r13, %r8
movl $0x10, %r9d
callq 0x4060
jmp 0x4823
movl $0xc, %ecx
leaq -0x140(%rbp), %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movzwl -0x6c(%rbp), %ecx
movw %cx, -0xdc(%rbp)
movl -0x70(%rbp), %ecx
movl %ecx, -0xe0(%rbp)
movb 0x7(%rax,%r15), %cl
movb %cl, -0xdf(%rbp)
movb 0x6(%rax,%r15), %cl
movb %cl, -0xde(%rbp)
movb 0x5(%rax,%r15), %cl
movb %cl, -0xdd(%rbp)
movb 0x4(%rax,%r15), %cl
movb %cl, -0xdc(%rbp)
movb -0xaa(%rbp), %cl
movb -0xa9(%rbp), %dl
movl %ecx, %esi
xorb $0x1c, %sil
xorb $0x21, %dl
orb %dl, %sil
jne 0x4ea8
movb -0xa8(%rbp), %cl
andb $-0x3, %cl
cmpb $-0x7f, %cl
jne 0x4f6c
movb $0x0, -0x6a(%rbp)
movb -0xa3(%rbp), %cl
cmpb $0x1, %cl
jne 0x4ce7
movzwl -0xa0(%rbp), %ecx
movw %cx, -0x30(%rbp)
movzwl -0x9e(%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %esi
movzbl -0xa7(%rbp), %r13d
movl $0x1, 0x28(%rax,%r15)
movl 0x68(%rax,%r15), %ecx
cmpl %esi, %ecx
setne %dl
testl %ecx, %ecx
sete %cl
orb %dl, %cl
movl %r13d, -0x34(%rbp)
movl %esi, -0x2c(%rbp)
jne 0x4b38
movl $0x1, 0x60(%rax,%r15)
movl $0xc, %edx
movq 0x10519(%rip), %r12     # 0x14fd0
movq %r12, %rdi
leaq 0xa71d(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x10893(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x14, %edx
movq %rax, %rdi
leaq 0xa5a4(%rip), %rsi      # 0xf094
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %r13d
movq 0x10820(%rip), %rax     # 0x15358
movl 0x64(%rax,%r15), %ecx
cmpl %esi, %ecx
setne %dl
testl %ecx, %ecx
sete %cl
orb %dl, %cl
jne 0x4be2
movl $0x0, 0x60(%rax,%r15)
movl $0xc, %edx
movq 0x1046c(%rip), %r12     # 0x14fd0
movq %r12, %rdi
leaq 0xa670(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x107e6(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x13, %edx
movq %rax, %rdi
leaq 0xa50c(%rip), %rsi      # 0xf0a9
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl -0x34(%rbp), %r13d
movq 0x10776(%rip), %rax     # 0x15358
movzwl -0x30(%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
cmpb 0x35(%rax,%r15), %r13b
movl %ecx, -0x30(%rbp)
jne 0x53da
movl %ecx, 0x50(%rax,%r15)
movl -0x2c(%rbp), %edx
movl %edx, 0x38(%rax,%r15)
movl %edx, 0x30(%rax,%r15)
movl $0xc, %edx
movq 0x103b7(%rip), %r12     # 0x14fd0
movq %r12, %rdi
movl %ecx, %r13d
leaq 0xa5b8(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x1072e(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x1e, %edx
movq %rax, %rdi
leaq 0xa4ba(%rip), %rsi      # 0xf10f
callq 0x4330
movq %r12, %rdi
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa467(%rip), %rsi      # 0xf0de
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa495(%rip), %rsi      # 0xf12e
callq 0x4330
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl $0x1, -0x4c(%rbp)
movb -0xa3(%rbp), %cl
leaq -0xd0(%rbp), %r12
cmpb $0x8, %cl
jne 0x4ef4
movzwl -0xa0(%rbp), %eax
movzwl -0x9e(%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
rolw $0x8, %ax
movzwl %ax, %ecx
movzbl -0xa7(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl %ecx, %eax
orl %edx, %eax
movl $0x0, -0x2c(%rbp)
leaq -0x48(%rbp), %r13
je 0x4823
movq 0x1061f(%rip), %rax     # 0x15358
cmpl $0x0, 0x28(%rax,%r15)
movl %ecx, -0x30(%rbp)
movl %edx, -0x2c(%rbp)
je 0x4823
movl %edx, -0x50(%rbp)
movl %ecx, %r13d
movl -0x34(%rbp), %ecx
cmpb 0x35(%rax,%r15), %cl
jne 0x552a
movl $0x0, 0x28(%rax,%r15)
movl 0x38(%rax,%r15), %ecx
movl %ecx, 0x3c(%rax,%r15)
movl $0xc, %edx
movq 0x10252(%rip), %r12     # 0x14fd0
movq %r12, %rdi
leaq 0xa456(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x105cc(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x1d, %edx
movq %rax, %rdi
leaq 0xa381(%rip), %rsi      # 0xf138
callq 0x4330
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, -0x38(%rbp)
callq 0x44c0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa301(%rip), %rsi      # 0xf0de
callq 0x4330
movq %r12, %rdi
movl -0x50(%rbp), %r13d
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
leaq -0xd0(%rbp), %r12
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl %r13d, %edx
movl -0x38(%rbp), %ecx
cmpb $0x8, -0xa3(%rbp)
movq 0x10522(%rip), %rax     # 0x15358
movl %r13d, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
leaq -0x48(%rbp), %r13
jne 0x4f05
jmp 0x4f17
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x44a0
movl $0x11, %edx
movq %r14, %rdi
leaq 0xa20f(%rip), %rsi      # 0xf082
callq 0x4330
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
leaq -0x48(%rbp), %r13
jmp 0x4823
andb $-0x11, %cl
orb %dl, %cl
jne 0x4f6c
cmpl $0x0, 0x60(%rax,%r15)
leaq -0x48(%rbp), %r13
jne 0x4823
cmpl $0x0, 0x28(%rax,%r15)
je 0x4823
movl 0x38(%rax,%r15), %edx
movl $0x0, 0x18(%rax,%r15)
movq %r12, %rdi
movl $0x66, %esi
movl %edx, -0x2c(%rbp)
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x56a7
jmp 0x4f49
movq 0x1045d(%rip), %rax     # 0x15358
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq -0x48(%rbp), %r13
cmpl $0x0, 0x28(%rax,%r15)
movl %ecx, -0x30(%rbp)
movl %edx, -0x2c(%rbp)
je 0x4823
cmpl $0x0, 0x60(%rax,%r15)
jne 0x4823
movl $0x0, 0x18(%rax,%r15)
movq %r12, %rdi
movl $0x66, %esi
movl -0x2c(%rbp), %edx
movl %ebx, %ecx
movl -0x4c(%rbp), %r8d
callq 0x56a7
movl $0x0, -0x4c(%rbp)
movl 0x10431(%rip), %edi     # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
cmpb $0x18, -0xa9(%rbp)
leaq -0x48(%rbp), %r13
jne 0x4823
movb -0xa6(%rbp), %al
movzbl %al, %edx
cmpl $0xf, %edx
je 0x4f96
movb $0x18, %cl
cmpl $0x9, %edx
jne 0x510a
movq 0x103bb(%rip), %rdx     # 0x15358
movb $0x18, %cl
cmpl $0x0, 0x60(%rdx,%r15)
jne 0x5288
movzwl -0xa3(%rbp), %eax
movzwl -0xa1(%rbp), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
rolw $0x8, %ax
movzwl %ax, %r13d
movzbl -0xa7(%rbp), %eax
movl %eax, -0x34(%rbp)
movl %r13d, 0x50(%rdx,%r15)
movl %ecx, -0x2c(%rbp)
movl %ecx, 0x38(%rdx,%r15)
movl %ecx, 0x30(%rdx,%r15)
movl $0x1, 0x28(%rdx,%r15)
movl $0xc, %edx
movq 0xffd7(%rip), %r12      # 0x14fd0
movq %r12, %rdi
leaq 0xa1db(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x10351(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x26, %edx
movq %rax, %rdi
leaq 0xa124(%rip), %rsi      # 0xf156
callq 0x4330
movq %r12, %rdi
movl %r13d, -0x30(%rbp)
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0xa086(%rip), %rsi      # 0xf0de
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %r13d
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa0b0(%rip), %rsi      # 0xf12e
callq 0x4330
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
leaq -0xd0(%rbp), %r12
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %r12, %rdi
movl $0x66, %esi
movl %r13d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x56a7
movl 0x102a6(%rip), %edi     # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movb -0xa9(%rbp), %cl
movb -0xa6(%rbp), %al
movl $0x1, -0x4c(%rbp)
movl %ecx, %edx
xorb $0x18, %dl
movl %eax, %esi
xorb $0x8, %sil
orb %dl, %sil
jne 0x5288
movq 0x10233(%rip), %rax     # 0x15358
cmpl $0x0, 0x60(%rax,%r15)
leaq -0x48(%rbp), %r13
jne 0x4823
movzwl -0xa3(%rbp), %ecx
movzwl -0xa1(%rbp), %edx
rolw $0x8, %dx
movzwl %dx, %edx
rolw $0x8, %cx
movzwl %cx, %r13d
movl %r13d, 0x50(%rax,%r15)
movl %edx, -0x2c(%rbp)
movl %edx, 0x38(%rax,%r15)
movl %edx, 0x30(%rax,%r15)
movl $0x0, 0x28(%rax,%r15)
movl %edx, 0x3c(%rax,%r15)
movl $0xc, %edx
movq 0xfe52(%rip), %r12      # 0x14fd0
movq %r12, %rdi
leaq 0xa056(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x101cc(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x4330
movq %rax, %r12
movl $0x25, %edx
movq %rax, %rdi
leaq 0x9fc6(%rip), %rsi      # 0xf17d
callq 0x4330
movq %r12, %rdi
movl %r13d, -0x30(%rbp)
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9f01(%rip), %rsi      # 0xf0de
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %r13d
movl %r13d, %esi
callq 0x44c0
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0x9f2b(%rip), %rsi      # 0xf12e
callq 0x4330
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
leaq -0xd0(%rbp), %r12
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %r12, %rdi
movl $0x66, %esi
movl %r13d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x56a7
movl 0x10121(%rip), %edi     # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movb -0xa9(%rbp), %cl
movb -0xa6(%rbp), %al
cmpb $0x18, %cl
leaq -0x48(%rbp), %r13
jne 0x4823
cmpb $-0x64, -0xa8(%rbp)
jne 0x4823
cmpb $0xb, %al
jne 0x4823
movq 0x100a7(%rip), %rax     # 0x15358
cmpl $0x0, 0x60(%rax,%r15)
jne 0x4823
cmpl $0x0, 0x28(%rax,%r15)
je 0x4823
movl 0x38(%rax,%r15), %ecx
movl %ecx, -0x2c(%rbp)
movl $0x0, 0x18(%rax,%r15)
movl $0xc, %edx
movq 0xfcea(%rip), %r15      # 0x14fd0
movq %r15, %rdi
leaq 0x9eee(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0x10064(%rip), %rax     # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r15, %rdi
callq 0x4330
movq %rax, %r12
movl $0x23, %edx
movq %rax, %rdi
leaq 0x9e84(%rip), %rsi      # 0xf1a3
callq 0x4330
movq %r12, %rdi
movl -0x30(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9d9d(%rip), %rsi      # 0xf0de
callq 0x4330
movq %r12, %rdi
movl -0x2c(%rbp), %r14d
movl %r14d, %esi
callq 0x44c0
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0x9dc7(%rip), %rsi      # 0xf12e
callq 0x4330
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %r12, %rdi
leaq -0xd0(%rbp), %r12
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %r12, %rdi
movl $0x66, %esi
movl %r14d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x56a7
movl 0xffbd(%rip), %edi      # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
jmp 0x49b5
cmpl $0x0, 0xff9b(%rip)      # 0x1537c
leaq -0xd0(%rbp), %r12
movl -0x2c(%rbp), %r13d
je 0x54c9
movl $0xc, %edx
movq 0xfbd2(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9dd6(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0xff4c(%rip), %rax      # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rbx
movl $0x20, %edx
movq %rax, %rdi
leaq 0x9c86(%rip), %rsi      # 0xf0bd
callq 0x4330
movq %rbx, %rdi
movl -0x30(%rbp), %esi
callq 0x44c0
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9c85(%rip), %rsi      # 0xf0de
callq 0x4330
movq %rbx, %rdi
movl %r13d, %esi
callq 0x44c0
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9c6e(%rip), %rsi      # 0xf0e9
callq 0x4330
movq %rbx, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %rbx
movl $0x16, %edx
movq %rax, %rdi
leaq 0x9c5b(%rip), %rsi      # 0xf0f8
callq 0x4330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl 0xfeb1(%rip), %edi      # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movq 0xfe65(%rip), %rax      # 0x15358
movl $0x0, 0x28(%rax,%r15)
testl %r13d, %r13d
leaq -0x48(%rbp), %r13
jne 0x4823
movl $0x1, 0x28(%rax,%r15)
xorl %ecx, %ecx
movl %ecx, 0x18(%rax,%r15)
movl $0x0, -0x2c(%rbp)
movl %ecx, 0x38(%rax,%r15)
jmp 0x4823
cmpl $0x0, 0xfe4b(%rip)      # 0x1537c
movl %r13d, %ebx
movl -0x50(%rbp), %r13d
je 0x561b
movl $0xc, %edx
movl %ebx, -0x38(%rbp)
movq 0xfa83(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x9c87(%rip), %rsi      # 0xf1de
callq 0x4330
movq 0xfdfd(%rip), %rax      # 0x15360
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rbx
movl $0x20, %edx
movq %rax, %rdi
leaq 0x9b37(%rip), %rsi      # 0xf0bd
callq 0x4330
movq %rbx, %rdi
movl -0x38(%rbp), %esi
callq 0x44c0
movq %rax, %rbx
movl $0xa, %edx
movq %rax, %rdi
leaq 0x9b36(%rip), %rsi      # 0xf0de
callq 0x4330
movq %rbx, %rdi
movl %r13d, %esi
callq 0x44c0
movq %rax, %rbx
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9b1f(%rip), %rsi      # 0xf0e9
callq 0x4330
movq %rbx, %rdi
movl -0x34(%rbp), %esi
callq 0x44c0
movq %rax, %rbx
movl $0x16, %edx
movq %rax, %rdi
leaq 0x9b0c(%rip), %rsi      # 0xf0f8
callq 0x4330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42b0
movsbl %al, %esi
movq %rbx, %rdi
movl -0x38(%rbp), %ebx
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl 0xfd5f(%rip), %edi      # 0x15380
movl $0x66, %edx
leaq -0x140(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x64(%rbp), %r8
movl $0x10, %r9d
callq 0x4060
movl %ebx, -0x30(%rbp)
movl %r13d, -0x2c(%rbp)
testl %r13d, %r13d
leaq -0x48(%rbp), %r13
jne 0x4823
movq 0xfcff(%rip), %rax      # 0x15358
xorl %ecx, %ecx
movl %ecx, 0x28(%rax,%r15)
movl $0x0, -0x2c(%rbp)
movl %ecx, 0x18(%rax,%r15)
movl 0x38(%rax,%r15), %ecx
movl %ecx, 0x3c(%rax,%r15)
movl %ebx, -0x30(%rbp)
jmp 0x4823
leaq 0x998f(%rip), %rdi      # 0xf014
jmp 0x568e
leaq 0x999c(%rip), %rdi      # 0xf02a
callq 0x4280
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq