// File: SaadBazaz[P]RIP-Protocol-Simulation/ProxyRouter.cpp
// Function: handlePacket(int const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void handlePacket(const int &client, string packet)
{
	auto vec = tokenizeData(packet, '&');
	// for (int i=0; i<vec.size(); i++){
	// 		std::cout<<vec[i]<<std::endl;
	// }


	if (vec[0] == "OK"){
		std::cout<<"Something good happened!"<<std::endl;
		return;
	}
	else if (vec[0] == "BAD"){
		std::cout<<"Oops, something went wrong..."<<std::endl;
		return;
	}


	switch (stoi(vec[0]))
	{
	case UPDATE:
	{
		// cout<<"In UPDATE..."<<endl;
		TableRow table_row(vec[3]);
		// cout<<"Made table_row..."<<endl;
		int index = findRowByFDAndID(client, table_row.identifier);

		if (index < 0)
		{

			// if match not found
			// remove all id = -1 values from table and add new table_row
			for (int i=0; i<table.size(); i++){
				if (table[i].identifier == -1){
					table.erase (table.begin() + i);
					i--;
				}
			} 

			table_row.fd = client;
			if (table_row.hop_count < 0)
			{
				table_row.hop_count = 0;
			}
			
			table.push_back(table_row);
			printTable();
			break;
		}


		if (table_row.identifier >= 0)
		{
			table[index].identifier = table_row.identifier;
		}

		// if (table_row.client_name >= 0){
		// 	table[index].client_name = table_row.client_name;
		// }

		if (table_row.status >= 0)
		{
			table[index].status = table_row.status;
		}

		if (table_row.hop_count >= 0)
		{
			table[index].hop_count = table_row.hop_count;
		}

		if (table_row.type != "")
		{
			table[index].type = table_row.type;
		}

		// if (table_row.in_use >= 0){
		table[index].in_use = table_row.in_use;
		// }

		if (table_row.send_port >= 0)
		{
			table[index].send_port = table_row.send_port;
		}

		if (table_row.receive_port >= 0)
		{
			table[index].receive_port = table_row.receive_port;
		}

		printTable();
		sendTableToAllRouters();

		break;
	}
	case ADD:
		break;

	case DELETE:
		break;

	case TABLE:{

		// auto index_vec = findAllRowsByFD(client);

		auto new_rows = deserialize(vec[3]);		


		// cout<<"New Rows - - - - - "<<endl;
		for (int i=0; i<new_rows.size(); i++){


			new_rows[i].fd = client;

			// cout<<new_rows[i].identifier<<endl;

		}
		// cout<<"- - - - - - - - - - "<<endl;



		// Clean useless data out of new_rows vector
		for (int i=0; i<table.size(); i++)
		{
			for (int j=0; j<new_rows.size(); j++){
				if (table[i] == new_rows[j] 
				or (table[i].fd == client and table[i].identifier == new_rows[j].identifier)
				or (table[i].identifier == new_rows[j].identifier and table[i].hop_count == 0)
				or (new_rows[j].hop_count >= 15)
				//  or new_rows[j].identifier == -1 or new_rows[j].identifier == port
				)

				{
					new_rows.erase(new_rows.begin() + j);
					j--;	
				}
			}
		}

		for (int j=0; j<new_rows.size(); j++){
			if (new_rows[j].identifier == -1 or new_rows[j].identifier == port){
				new_rows.erase(new_rows.begin() + j);
				j--;
			}
		}


		// cout<<"New Rows [CLEANED] - - - - - "<<endl;
		// for (int i=0; i<new_rows.size(); i++){
		// 	cout<<new_rows[i].identifier<<endl;
		// }
		// cout<<"- - - - - - - - - - "<<endl;



		// Add data from new_rows into table
		for (int i=0; i<new_rows.size(); i++){
				new_rows[i].hop_count ++;
				new_rows[i].fd = client;
				table.push_back(new_rows[i]);
		}

		// for (int i=0; i<new_rows.size(); i++){
		// 	if (new_rows[i].identifier != port)
		// 		table.push_back(new_rows[i]);
		// }

		printTable();
		sendTableToAllRouters(client);  //ignore this client when sending table to routers
		break;
	}

	case MESSAGE:
	{
        vector<string> Command = tokenizeData(vec[3],' ');
        if (Command[0]=="DNS")
        {
            if(Command[1]=="REQ"){
                while (Command[2].back() == '\n')
                {
                    Command[2].pop_back();
                }
                for (size_t i = 0; i < List.size(); i++)
                {
                    if (Command[2]==List[i].DomainName)
                    {
                        string Response = "DNS RES " + List[i].DomainName + " " + List[i].IPAddress;
                        string message = constructNewMessage(MESSAGE, port,stoi(vec[1]),(void*)Response.c_str());
                        cout << "Proxy Intervenes ...\n";

						if (vec.size() == 4){
							message += '&';
							message += to_string(port);
						}
						else {
							message += ',';
							message += to_string(port);			
						}

                        send(client, message.c_str(), strlen(message.c_str()), 0);
                        return;
                    }
                    
                }
                
            }
            else if (Command[1] == "RES"){
                cout << "Checking Response ... \n";
                int index = SearchDomain(Command[2],List);
                
                if (index < 0)
                {
                    Directory Entry ;
                    Entry.DomainName = Command[2] ;
                    for (size_t i = 0; i < 128; i++)
                    {
                        Entry.IPAddress[i] = Command[3][i];
                    }
                    List.push_back(Entry);
                    cout << "Saved the Entry in Cache ... \n";
                }
                else{
                    for (size_t i = 0; i < 128; i++)
                    {
                        List[index].IPAddress[i] = Command[3][i];
                    }
                }
                
            }
        }
        
		int index = findRowByID_MinHopCount(stoi(vec[2]));

		if (index < 0)
		{
			break;
		}

		if (vec.size() == 4){
			packet += '&';
			packet += to_string(port);
		}
		else {
			packet += ',';
			packet += to_string(port);			
		}
		// Forward packet to appropriate socket
		send(table[index].fd, packet.c_str(), strlen(packet.c_str()), 0);
		break;
	}
	default:
		break;
	}
	// if (vec[0] == UPDATE){
	// 	if ()

	// }
	// send(client, "OK", 2, 0); //Reply message to client
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movq %rsi, -0x3c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x3140
movq -0x3b8(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movl $0x26, %edx
callq 0x3730
jmp 0x4c51
leaq -0x48(%rbp), %rdi
callq 0x31e0
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x7500
movq %rax, %rdi
leaq 0x743e(%rip), %rsi      # 0xc0af
callq 0x7c90
movb %al, -0x3c1(%rbp)
jmp 0x4c7e
movb -0x3c1(%rbp), %al
testb $0x1, %al
jne 0x4c8a
jmp 0x4cf2
movq 0xc337(%rip), %rdi      # 0x10fc8
leaq 0x741a(%rip), %rsi      # 0xc0b2
callq 0x3310
movq %rax, -0x3d0(%rbp)
jmp 0x4ca6
movq -0x3d0(%rbp), %rdi
movq 0xc304(%rip), %rsi      # 0x10fb8
callq 0x3350
jmp 0x4cbb
movl $0x1, -0x58(%rbp)
jmp 0x5f13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x31e0
jmp 0x5f2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5f25
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x7500
movq %rax, %rdi
leaq 0x73c2(%rip), %rsi      # 0xc0cb
callq 0x7c90
movb %al, -0x3d1(%rbp)
jmp 0x4d16
movb -0x3d1(%rbp), %al
testb $0x1, %al
jne 0x4d22
jmp 0x4d5f
movq 0xc29f(%rip), %rdi      # 0x10fc8
leaq 0x739f(%rip), %rsi      # 0xc0cf
callq 0x3310
movq %rax, -0x3e0(%rbp)
jmp 0x4d3e
movq -0x3e0(%rbp), %rdi
movq 0xc26c(%rip), %rsi      # 0x10fb8
callq 0x3350
jmp 0x4d53
movl $0x1, -0x58(%rbp)
jmp 0x5f13
jmp 0x4d61
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x3f0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x7500
movq -0x3f0(%rbp), %rsi
movq %rax, %rdi
movl $0xa, %edx
callq 0x7cc0
movl %eax, -0x3e4(%rbp)
jmp 0x4d91
movl -0x3e4(%rbp), %eax
movl %eax, %ecx
movq %rcx, -0x3f8(%rbp)
subl $0x4, %eax
ja 0x5f0a
movq -0x3f8(%rbp), %rax
leaq 0x7261(%rip), %rcx      # 0xc018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x7500
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3140
jmp 0x4ddf
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movl $0x2c, %edx
callq 0x7520
jmp 0x4df9
leaq -0xb8(%rbp), %rdi
callq 0x31e0
movq -0x8(%rbp), %rax
movl (%rax), %edi
movl -0x98(%rbp), %esi
callq 0x4630
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
jge 0x4f95
movl $0x0, -0xc0(%rbp)
movslq -0xc0(%rbp), %rax
movq %rax, -0x400(%rbp)
leaq 0xc4a0(%rip), %rdi      # 0x112e8
callq 0x6e90
movq %rax, %rcx
movq -0x400(%rbp), %rax
cmpq %rcx, %rax
jae 0x4f4e
movslq -0xc0(%rbp), %rsi
leaq 0xc47a(%rip), %rdi      # 0x112e8
callq 0x6eb0
cmpl $-0x1, (%rax)
jne 0x4f38
leaq 0xc465(%rip), %rdi      # 0x112e8
movq %rdi, -0x410(%rbp)
callq 0x7d70
movq %rax, -0xd8(%rbp)
movslq -0xc0(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x7da0
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x7de0
movq -0x410(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x7d00
movq %rax, -0x408(%rbp)
jmp 0x4edf
movq -0x408(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl -0xc0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x4f38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x31e0
jmp 0x5f25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x77e0
jmp 0x5f25
jmp 0x4f3a
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x4e33
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x8c(%rbp)
jge 0x4f6d
movl $0x0, -0x8c(%rbp)
leaq 0xc374(%rip), %rdi      # 0x112e8
leaq -0x98(%rbp), %rsi
callq 0x7770
jmp 0x4f82
callq 0x4320
jmp 0x4f89
movl $0x2, -0x58(%rbp)
jmp 0x5125
cmpl $0x0, -0x98(%rbp)
jl 0x4fc5
movl -0x98(%rbp), %eax
movl %eax, -0x414(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc330(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl -0x414(%rbp), %ecx
movl %ecx, (%rax)
movswl -0x90(%rbp), %eax
cmpl $0x0, %eax
jl 0x4ffd
movw -0x90(%rbp), %ax
movw %ax, -0x416(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc2fb(%rip), %rdi      # 0x112e8
callq 0x6eb0
movw -0x416(%rbp), %cx
movw %cx, 0x8(%rax)
cmpl $0x0, -0x8c(%rbp)
jl 0x502e
movl -0x8c(%rbp), %eax
movl %eax, -0x41c(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc2c8(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl -0x41c(%rbp), %ecx
movl %ecx, 0xc(%rax)
leaq -0x88(%rbp), %rdi
leaq 0x7047(%rip), %rsi      # 0xc083
callq 0x7e20
movb %al, -0x41d(%rbp)
jmp 0x5049
movb -0x41d(%rbp), %al
testb $0x1, %al
jne 0x5055
jmp 0x508d
leaq -0x88(%rbp), %rax
movq %rax, -0x428(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc277(%rip), %rdi      # 0x112e8
callq 0x6eb0
movq -0x428(%rbp), %rsi
movq %rax, %rdi
addq $0x10, %rdi
callq 0x3040
jmp 0x508b
jmp 0x508d
movb -0x68(%rbp), %al
movb %al, -0x429(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc244(%rip), %rdi      # 0x112e8
callq 0x6eb0
movb -0x429(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x30(%rax)
cmpl $0x0, -0x64(%rbp)
jl 0x50e0
movl -0x64(%rbp), %eax
movl %eax, -0x430(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc216(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl -0x430(%rbp), %ecx
movl %ecx, 0x34(%rax)
cmpl $0x0, -0x60(%rbp)
jl 0x510b
movl -0x60(%rbp), %eax
movl %eax, -0x434(%rbp)
movslq -0xbc(%rbp), %rsi
leaq 0xc1eb(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl -0x434(%rbp), %ecx
movl %ecx, 0x38(%rax)
callq 0x4320
jmp 0x5112
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4870
jmp 0x511e
movl $0x2, -0x58(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x77e0
jmp 0x5f0c
jmp 0x5f0c
jmp 0x5f0c
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x7500
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x3140
jmp 0x515f
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x3ac0
jmp 0x5174
leaq -0x118(%rbp), %rdi
callq 0x31e0
movl $0x0, -0x11c(%rbp)
movslq -0x11c(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x6e90
movq %rax, %rcx
movq -0x440(%rbp), %rax
cmpq %rcx, %rax
jae 0x5209
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x444(%rbp)
movslq -0x11c(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
movl -0x444(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x518a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x31e0
jmp 0x5f25
movl $0x0, -0x120(%rbp)
movslq -0x120(%rbp), %rax
movq %rax, -0x450(%rbp)
leaq 0xc0c0(%rip), %rdi      # 0x112e8
callq 0x6e90
movq %rax, %rcx
movq -0x450(%rbp), %rax
cmpq %rcx, %rax
jae 0x5450
movl $0x0, -0x124(%rbp)
movslq -0x124(%rbp), %rax
movq %rax, -0x458(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x6e90
movq %rax, %rcx
movq -0x458(%rbp), %rax
cmpq %rcx, %rax
jae 0x543a
movslq -0x120(%rbp), %rsi
leaq 0xc063(%rip), %rdi      # 0x112e8
callq 0x6eb0
movq %rax, -0x460(%rbp)
movslq -0x124(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
movq -0x460(%rbp), %rdi
movq %rax, %rsi
callq 0x38b0
testb $0x1, %al
jne 0x5385
movslq -0x120(%rbp), %rsi
leaq 0xc01f(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x5314
movslq -0x120(%rbp), %rsi
leaq 0xc001(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl (%rax), %eax
movl %eax, -0x464(%rbp)
movslq -0x124(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
movq %rax, %rcx
movl -0x464(%rbp), %eax
cmpl (%rcx), %eax
je 0x5385
movslq -0x120(%rbp), %rsi
leaq 0xbfc6(%rip), %rdi      # 0x112e8
callq 0x6eb0
movl (%rax), %eax
movl %eax, -0x468(%rbp)
movslq -0x124(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
movq %rax, %rcx
movl -0x468(%rbp), %eax
cmpl (%rcx), %eax
jne 0x5368
movslq -0x120(%rbp), %rsi
leaq 0xbf8b(%rip), %rdi      # 0x112e8
callq 0x6eb0
cmpl $0x0, 0xc(%rax)
je 0x5385
movslq -0x124(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
cmpl $0xf, 0xc(%rax)
jl 0x5424
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x7d70
movq %rax, -0x140(%rbp)
movslq -0x124(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x7da0
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x7de0
movq -0x478(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x7d00
movq %rax, -0x470(%rbp)
jmp 0x53e8
movq -0x470(%rbp), %rax
movq %rax, -0x148(%rbp)
movl -0x124(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x5424
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7800
jmp 0x5f25
jmp 0x5426
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x524a
jmp 0x543c
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x5213
movl $0x0, -0x14c(%rbp)
movslq -0x14c(%rbp), %rax
movq %rax, -0x480(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x6e90
movq %rax, %rcx
movq -0x480(%rbp), %rax
cmpq %rcx, %rax
jae 0x5556
movslq -0x14c(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
cmpl $-0x1, (%rax)
je 0x54c0
movslq -0x14c(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6eb0
movl (%rax), %eax
cmpl 0xbe46(%rip), %eax      # 0x11300
jne 0x5540
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x7d70
movq %rax, -0x168(%rbp)
movslq -0x14c(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x7da0
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x7de0
movq -0x490(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x7d00
movq %rax, -0x488(%rbp)
jmp 0x5523
movq -0x488(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x14c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x5542
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x545a
movl $0x0, -0x174(%rbp)
movslq -0x174(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x6e90
movq %rax, %rcx
movq -0x498(%rbp), %rax
cmpq %rcx, %rax
jae 0x5611
movslq -0x174(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x6eb0
movq -0x4a0(%rbp), %rdi
movl 0xc(%rax), %ecx
incl %ecx
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4a4(%rbp)
movslq -0x174(%rbp), %rsi
callq 0x6eb0
movl -0x4a4(%rbp), %ecx
movq -0x4a0(%rbp), %rdi
movl %ecx, 0x4(%rax)
movslq -0x174(%rbp), %rsi
callq 0x6eb0
movq %rax, %rsi
leaq 0xbcf4(%rip), %rdi      # 0x112e8
callq 0x7770
jmp 0x55fb
jmp 0x55fd
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x5560
callq 0x4320
jmp 0x5618
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x4870
jmp 0x5625
movl $0x2, -0x58(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7800
jmp 0x5f0c
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x7500
movq %rax, %rsi
leaq -0x1b0(%rbp), %rdi
callq 0x3140
jmp 0x565c
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
movl $0x20, %edx
callq 0x3730
jmp 0x5676
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
xorl %eax, %eax
movl %eax, %esi
leaq -0x190(%rbp), %rdi
callq 0x7500
movq %rax, %rdi
leaq 0x6a51(%rip), %rsi      # 0xc0ed
callq 0x7c90
movb %al, -0x4a5(%rbp)
jmp 0x56a9
movb -0x4a5(%rbp), %al
testb $0x1, %al
jne 0x56b8
jmp 0x5d59
leaq -0x190(%rbp), %rdi
movl $0x1, %esi
callq 0x7500
movq %rax, %rdi
leaq 0x6a1e(%rip), %rsi      # 0xc0f1
callq 0x7c90
movb %al, -0x4a6(%rbp)
jmp 0x56e0
movb -0x4a6(%rbp), %al
testb $0x1, %al
jne 0x56ef
jmp 0x5ac6
jmp 0x56f1
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq %rax, %rdi
callq 0x3240
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x575b
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq %rax, %rdi
callq 0x33d0
jmp 0x56f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
jmp 0x5f25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5efc
movq $0x0, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq 0xbb8d(%rip), %rdi      # 0x11308
callq 0x7c40
movq %rax, %rcx
movq -0x4b0(%rbp), %rax
cmpq %rcx, %rax
jae 0x5ac1
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq %rax, -0x4b8(%rbp)
movq -0x1b8(%rbp), %rsi
leaq 0xbb4f(%rip), %rdi      # 0x11308
callq 0x7c70
movq -0x4b8(%rbp), %rdi
movq %rax, %rsi
callq 0x6e00
testb $0x1, %al
jne 0x57d6
jmp 0x5aa8
movq -0x1b8(%rbp), %rsi
leaq 0xbb24(%rip), %rdi      # 0x11308
callq 0x7c70
movq %rax, %rdx
leaq 0x6902(%rip), %rsi      # 0xc0f5
leaq -0x218(%rbp), %rdi
callq 0x7ea0
jmp 0x5801
leaq 0x6a13(%rip), %rdx      # 0xc21b
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x7e50
jmp 0x581d
movq -0x1b8(%rbp), %rsi
leaq 0xbadd(%rip), %rdi      # 0x11308
callq 0x7c70
movq %rax, %rdx
addq $0x20, %rdx
leaq -0x1d8(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x7e50
jmp 0x584c
leaq -0x1f8(%rbp), %rdi
callq 0x31e0
leaq -0x218(%rbp), %rdi
callq 0x31e0
movl 0xba96(%rip), %eax      # 0x11300
movl %eax, -0x4c0(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x7500
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x7cc0
movl %eax, -0x4bc(%rbp)
jmp 0x5897
leaq -0x1d8(%rbp), %rdi
callq 0x3130
movl -0x4c0(%rbp), %edx
movl -0x4bc(%rbp), %ecx
movq %rax, %r8
leaq -0x238(%rbp), %rdi
movl $0x4, %esi
callq 0x3c70
jmp 0x58c5
movq 0xb6fc(%rip), %rdi      # 0x10fc8
leaq 0x682b(%rip), %rsi      # 0xc0fe
callq 0x3310
jmp 0x58da
leaq -0x28(%rbp), %rdi
callq 0x74e0
cmpq $0x4, %rax
jne 0x59b0
leaq -0x238(%rbp), %rdi
movl $0x26, %esi
callq 0x31f0
jmp 0x5900
movl 0xb9fa(%rip), %esi      # 0x11300
leaq -0x258(%rbp), %rdi
callq 0x7860
jmp 0x5914
leaq -0x238(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3400
jmp 0x5929
leaq -0x258(%rbp), %rdi
callq 0x31e0
jmp 0x5a14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x31e0
leaq -0x218(%rbp), %rdi
callq 0x31e0
jmp 0x5efc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5a97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5a8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x31e0
jmp 0x5a8b
leaq -0x238(%rbp), %rdi
movl $0x2c, %esi
callq 0x31f0
jmp 0x59c3
movl 0xb937(%rip), %esi      # 0x11300
leaq -0x278(%rbp), %rdi
callq 0x7860
jmp 0x59d7
leaq -0x238(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x3400
jmp 0x59ec
leaq -0x278(%rbp), %rdi
callq 0x31e0
jmp 0x5a14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x31e0
jmp 0x5a8b
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4cc(%rbp)
leaq -0x238(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x3130
movq -0x4d8(%rbp), %rdi
movq %rax, -0x4c8(%rbp)
callq 0x3130
movq %rax, %rdi
callq 0x3150
movl -0x4cc(%rbp), %edi
movq -0x4c8(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x3170
jmp 0x5a67
movl $0x1, -0x58(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x31e0
leaq -0x1d8(%rbp), %rdi
callq 0x31e0
jmp 0x5ee6
leaq -0x238(%rbp), %rdi
callq 0x31e0
leaq -0x1d8(%rbp), %rdi
callq 0x31e0
jmp 0x5efc
jmp 0x5aaa
movq -0x1b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1b8(%rbp)
jmp 0x5766
jmp 0x5d57
leaq -0x190(%rbp), %rdi
movl $0x1, %esi
callq 0x7500
movq %rax, %rdi
leaq 0x6633(%rip), %rsi      # 0xc114
callq 0x7c90
movb %al, -0x4d9(%rbp)
jmp 0x5aee
movb -0x4d9(%rbp), %al
testb $0x1, %al
jne 0x5afd
jmp 0x5d55
movq 0xb4c4(%rip), %rdi      # 0x10fc8
leaq 0x660d(%rip), %rsi      # 0xc118
callq 0x3310
jmp 0x5b12
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq %rax, %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x3140
jmp 0x5b34
leaq 0xb7cd(%rip), %rsi      # 0x11308
leaq -0x2b8(%rbp), %rdi
callq 0x7fb0
jmp 0x5b49
leaq -0x2a0(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x4b20
movl %eax, -0x4e0(%rbp)
jmp 0x5b64
leaq -0x2b8(%rbp), %rdi
callq 0x7a50
leaq -0x2a0(%rbp), %rdi
callq 0x31e0
movl -0x4e0(%rbp), %eax
movl %eax, -0x27c(%rbp)
cmpl $0x0, -0x27c(%rbp)
jge 0x5cc9
leaq -0x358(%rbp), %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x80a0
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq -0x4e8(%rbp), %rdi
movq %rax, %rsi
callq 0x3040
jmp 0x5bca
movq $0x0, -0x360(%rbp)
cmpq $0x80, -0x360(%rbp)
jae 0x5c8e
leaq -0x190(%rbp), %rdi
movl $0x3, %esi
callq 0x7500
movq %rax, %rdi
movq -0x360(%rbp), %rsi
callq 0x3570
movq %rax, -0x4f0(%rbp)
jmp 0x5c0f
movq -0x4f0(%rbp), %rax
movb (%rax), %cl
movq -0x360(%rbp), %rax
movb %cl, -0x338(%rbp,%rax)
movq -0x360(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x360(%rbp)
jmp 0x5bd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5c60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x7a50
leaq -0x2a0(%rbp), %rdi
callq 0x31e0
jmp 0x5efc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x8130
jmp 0x5efc
leaq 0xb673(%rip), %rdi      # 0x11308
leaq -0x358(%rbp), %rsi
callq 0x80c0
jmp 0x5ca3
movq 0xb31e(%rip), %rdi      # 0x10fc8
leaq 0x647f(%rip), %rsi      # 0xc130
callq 0x3310
jmp 0x5cb8
leaq -0x358(%rbp), %rdi
callq 0x8130
jmp 0x5d53
movq $0x0, -0x368(%rbp)
cmpq $0x80, -0x368(%rbp)
jae 0x5d51
leaq -0x190(%rbp), %rdi
movl $0x3, %esi
callq 0x7500
movq %rax, %rdi
movq -0x368(%rbp), %rsi
callq 0x3570
movq %rax, -0x4f8(%rbp)
jmp 0x5d0a
movq -0x4f8(%rbp), %rax
movb (%rax), %al
movb %al, -0x4f9(%rbp)
movslq -0x27c(%rbp), %rsi
leaq 0xb5e1(%rip), %rdi      # 0x11308
callq 0x7c70
movb -0x4f9(%rbp), %dl
movq -0x368(%rbp), %rcx
movb %dl, 0x20(%rax,%rcx)
movq -0x368(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x368(%rbp)
jmp 0x5cd4
jmp 0x5d53
jmp 0x5d55
jmp 0x5d57
jmp 0x5d59
leaq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x7500
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x7cc0
movl %eax, -0x500(%rbp)
jmp 0x5d80
movl -0x500(%rbp), %edi
callq 0x4500
movl %eax, -0x36c(%rbp)
cmpl $0x0, -0x36c(%rbp)
jge 0x5da6
movl $0x2, -0x58(%rbp)
jmp 0x5ee6
leaq -0x28(%rbp), %rdi
callq 0x74e0
cmpq $0x4, %rax
jne 0x5e1f
movq -0x3c0(%rbp), %rdi
movl $0x26, %esi
callq 0x31f0
jmp 0x5dc8
movl 0xb532(%rip), %esi      # 0x11300
leaq -0x390(%rbp), %rdi
callq 0x7860
jmp 0x5ddc
movq -0x3c0(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0x3400
jmp 0x5df1
leaq -0x390(%rbp), %rdi
callq 0x31e0
jmp 0x5e83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x390(%rbp), %rdi
callq 0x31e0
jmp 0x5efc
movq -0x3c0(%rbp), %rdi
movl $0x2c, %esi
callq 0x31f0
jmp 0x5e32
movl 0xb4c8(%rip), %esi      # 0x11300
leaq -0x3b0(%rbp), %rdi
callq 0x7860
jmp 0x5e46
movq -0x3c0(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x3400
jmp 0x5e5b
leaq -0x3b0(%rbp), %rdi
callq 0x31e0
jmp 0x5e83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0x31e0
jmp 0x5efc
movslq -0x36c(%rbp), %rsi
leaq 0xb457(%rip), %rdi      # 0x112e8
callq 0x6eb0
movq -0x3c0(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x50c(%rbp)
callq 0x3130
movq -0x3c0(%rbp), %rdi
movq %rax, -0x508(%rbp)
callq 0x3130
movq %rax, %rdi
callq 0x3150
movl -0x50c(%rbp), %edi
movq -0x508(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x3170
jmp 0x5edf
movl $0x2, -0x58(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x6da0
movl -0x58(%rbp), %eax
subl $0x2, %eax
je 0x5f0c
jmp 0x5f13
leaq -0x190(%rbp), %rdi
callq 0x6da0
jmp 0x5f25
jmp 0x5f0c
movl $0x0, -0x58(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6da0
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x6da0
movq -0x50(%rbp), %rdi
callq 0x34f0
nopw (%rax,%rax)