// File: /workspace/github_cpp_makefile_star2_O1/dramninjasUMD[P]BOBSim/SimpleController.cpp
// Function: BOBSim::SimpleController::Update()
void SimpleController::Update()
{
	//
	//Stats
	//
	unsigned currentCount = 0;
	//count all the ACTIVATES waiting in the queue
	for(unsigned i=0; i<commandQueue.size(); i++)
	{
		if(commandQueue[i]->busPacketType==ACTIVATE)
		{
			currentCount++;
		}
	}
	if(currentCount>commandQueueMax) commandQueueMax = currentCount;

	//cumulative rolling average
	commandQueueAverage += currentCount;

	//count the number of idle banks
	unsigned num=0;
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned b=0; b<NUM_BANKS; b++)
		{
			if(bankStates[r][b].currentBankState==IDLE)
			{
				num++;
			}
		}
	}
	numIdleBanksAverage += num;

	//count the number of active banks
	unsigned numActive=0;
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned b=0; b<NUM_BANKS; b++)
		{
			if(bankStates[r][b].currentBankState==ROW_ACTIVE)
			{
				numActive++;
			}
		}
	}
	numActBanksAverage += numActive;

	//count the number of precharging banks
	unsigned numPre=0;
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned b=0; b<NUM_BANKS; b++)
		{
			if(bankStates[r][b].currentBankState==PRECHARGING)
			{
				numPre++;
			}
		}
	}
	numPreBanksAverage += numPre;

	//count the number of refreshing banks
	unsigned numRef=0;
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned b=0; b<NUM_BANKS; b++)
		{
			if(bankStates[r][b].currentBankState==REFRESHING)
			{
				numRef++;
			}
		}
	}
	numRefBanksAverage += numRef;

	//
	//Power
	//
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		bool bankOpen = false;
		for(unsigned b=0; b<NUM_RANKS; b++)
		{
			if(bankStates[r][b].currentBankState == ROW_ACTIVE ||
			        bankStates[r][b].currentBankState == REFRESHING)
			{
				bankOpen = true;
				break;
			}
		}

		if(bankOpen)
		{
			//DRAM_BUS_WIDTH/2 because value accounts for DDR
			backgroundEnergy[r] += IDD3N * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);
		}
		else
		{
			//DRAM_BUS_WIDTH/2 because value accounts for DDR
			idd2nCount[r]++;
			backgroundEnergy[r] += IDD2N * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);
		}
	}


	//
	//Update
	//
	//Updates the sliding window for tFAW
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned i=0; i<tFAWWindow[r].size(); i++)
		{
			tFAWWindow[r][i]--;
			if(tFAWWindow[r][i]==0) tFAWWindow[r].erase(tFAWWindow[r].begin());
		}
	}

	//Updates the bank states for each rank
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		for(unsigned b=0; b<NUM_BANKS; b++)
		{
			bankStates[r][b].UpdateStateChange();
		}
	}

	//Handle refresh counters
	for(unsigned i=0; i<NUM_RANKS; i++)
	{
		if(refreshCounters[i]>0)
		{
			refreshCounters[i]--;
		}
	}

	//Send write data to data bus
	for(unsigned i=0; i<writeBurstCountdown.size(); i++)
	{
		writeBurstCountdown[i]--;
	}
	if(writeBurstCountdown.size()>0&&writeBurstCountdown[0]==0)
	{
		if(DEBUG_CHANNEL) DEBUG("     == Sending Write Data : "<<*writeBurstQueue[0]);
		(*DataCallback)(writeBurstQueue[0],0);
		writeBurstQueue.erase(writeBurstQueue.begin());
		writeBurstCountdown.erase(writeBurstCountdown.begin());
	}

	bool issuingRefresh = false;
	bool canIssueRefresh = true;

	//Figure out if everyone who needs a refresh can actually receive one
	for(unsigned r=0; r<NUM_RANKS; r++)
	{
		if(refreshCounters[r]==0)
		{
			if(DEBUG_CHANNEL) DEBUG("      !! -- Rank "<<r<<" needs refresh");
			//Check to be sure we can issue a refresh
			for(unsigned b=0; b<NUM_BANKS; b++)
			{
				if(bankStates[r][b].nextActivate > currentClockCycle ||
				        bankStates[r][b].currentBankState != IDLE)
				{
					canIssueRefresh = false;

				}
			}

			//Once all counters have reached 0 and everyone is either idle or ready to accept refresh-CAS
			if(canIssueRefresh)
			{
				if(DEBUG_CHANNEL) DEBUGN("-- !! Refresh is issuable - Sending : ");

				//BusPacketType packtype, unsigned transactionID, unsigned col, unsigned rw, unsigned r, unsigned b, unsigned prt, unsigned bl
				BusPacket *refreshPacket = new BusPacket(REFRESH, -1, 0, 0, r, 0, 0, 0, 0, 0, false);
				refreshPacket->channel = channel->channelID;

				//Send to command bus
				(*CommandCallback)(refreshPacket,0);

				//make sure we don't send anythign else
				issuingRefresh = true;

				refreshEnergy[r] += (IDD5B-IDD3N) * tRFC * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);

				for(unsigned b=0; b<NUM_BANKS; b++)
				{
					bankStates[r][b].currentBankState = REFRESHING;
					bankStates[r][b].stateChangeCountdown = tRFC;
					bankStates[r][b].nextActivate = currentClockCycle + tRFC;
					bankStates[r][b].lastCommand = REFRESH;
				}

				//reset refresh counters
				for(unsigned i=0; i<NUM_RANKS; i++)
				{
					if(refreshCounters[r]==0)
					{
						refreshCounters[r] = 7800/tCK;
					}
				}

				//only issue one
				break;
			}
		}
	}

	//If no refresh is being issued then do this block
	if(!issuingRefresh)
	{
		for(unsigned i=0; i<commandQueue.size(); i++)
		{
			//Checks to see if this particular request can be issued
			if(IsIssuable(commandQueue[i]))
			{
				//make sure we don't send a command ahead of its own ACTIVATE
				if(i>0 && commandQueue[i]->transactionID == commandQueue[i-1]->transactionID)
					continue;

				//send to channel
				(*CommandCallback)(commandQueue[i],0);

				//update channel controllers bank state bookkeeping
				unsigned rank = commandQueue[i]->rank;
				unsigned bank = commandQueue[i]->bank;
				BusPacket *writeData;

				//
				//Main block for determining what to do with each type of command
				//
				switch(commandQueue[i]->busPacketType)
				{
				case READ_P:
					outstandingReads++;
					waitingACTS--;
					if(waitingACTS<0)
					{
						ERROR("#@)($J@)#(RJ");
						exit(0);
					}

					//keep track of energy
					burstEnergy[rank] += (IDD4R - IDD3N) * BL/2 * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);

					bankStates[rank][bank].lastCommand = READ_P;
					bankStates[rank][bank].stateChangeCountdown = (4*tCK>7.5)?tRTP:ceil(7.5/tCK); //4 clk or 7.5ns
					bankStates[rank][bank].nextActivate = max(bankStates[rank][bank].nextActivate, currentClockCycle + tRTP + tRP);
					bankStates[rank][bank].nextRefresh = currentClockCycle + tRTP + tRP;

					for(unsigned r=0; r<NUM_RANKS; r++)
					{
						if(r==rank)
						{
							for(unsigned b=0; b<NUM_BANKS; b++)
							{
								bankStates[r][b].nextRead = max(bankStates[r][b].nextRead,
								                                currentClockCycle + max(tCCD, TRANSACTION_SIZE/DRAM_BUS_WIDTH));
								bankStates[r][b].nextWrite = max(bankStates[r][b].nextWrite,
								                                 currentClockCycle + (tCL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tRTRS - tCWL));
							}
						}
						else
						{
							for(unsigned b=0; b<NUM_BANKS; b++)
							{
								bankStates[r][b].nextRead = max(bankStates[r][b].nextRead,
								                                currentClockCycle + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tRTRS);
								bankStates[r][b].nextWrite = max(bankStates[r][b].nextWrite,
								                                 currentClockCycle + (tCL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tRTRS - tCWL));
							}
						}
					}

					//prevents read or write being issued while waiting for auto-precharge to close page
					bankStates[rank][bank].nextRead = bankStates[rank][bank].nextActivate;
					bankStates[rank][bank].nextWrite = bankStates[rank][bank].nextActivate;

					break;
				case WRITE_P:
					waitingACTS--;
					if(waitingACTS<0)
					{
						ERROR(")(JWE)(FJEWF");
						exit(0);
					}

					//keep track of energy
					burstEnergy[rank] += (IDD4W - IDD3N) * BL/2 * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);

					writeData = new BusPacket(*commandQueue[i]);
					writeData->busPacketType = WRITE_DATA;
					writeBurstQueue.push_back(writeData);
					writeBurstCountdown.push_back(tCWL);
					if(DEBUG_CHANNEL) DEBUG("     !!! After Issuing WRITE_P, burstQueue is :"<<writeBurstQueue.size()<<" "<<writeBurstCountdown.size()<<" with head : "<<writeBurstCountdown[0]);

					bankStates[rank][bank].lastCommand = WRITE_P;
					bankStates[rank][bank].stateChangeCountdown = tCWL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tWR;
					bankStates[rank][bank].nextActivate = currentClockCycle + tCWL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tWR + tRP;
					bankStates[rank][bank].nextRefresh = currentClockCycle + tCWL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tWR + tRP;

					for(unsigned r=0; r<NUM_RANKS; r++)
					{
						if(r==rank)
						{
							for(unsigned b=0; b<NUM_BANKS; b++)
							{
								bankStates[r][b].nextRead = max(bankStates[r][b].nextRead, currentClockCycle + tCWL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tWTR);
								bankStates[r][b].nextWrite = max(bankStates[r][b].nextWrite, currentClockCycle+(uint64_t)max(tCCD, TRANSACTION_SIZE/DRAM_BUS_WIDTH));
							}
						}
						else
						{
							for(unsigned b=0; b<NUM_BANKS; b++)
							{
								bankStates[r][b].nextRead = max(bankStates[r][b].nextRead, currentClockCycle + tCWL + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tRTRS - tCL);
								bankStates[r][b].nextWrite = max(bankStates[r][b].nextWrite, currentClockCycle + TRANSACTION_SIZE/DRAM_BUS_WIDTH + tRTRS);
							}
						}
					}

					//prevents read or write being issued while waiting for auto-precharge to close page
					bankStates[rank][bank].nextRead = bankStates[rank][bank].nextActivate;
					bankStates[rank][bank].nextWrite = bankStates[rank][bank].nextActivate;

					break;
				case ACTIVATE:
					for(unsigned b=0; b<NUM_BANKS; b++)
					{
						if(b!=bank)
						{
							bankStates[rank][b].nextActivate = max(currentClockCycle + tRRD, bankStates[rank][b].nextActivate);
						}
					}

					actpreEnergy[rank] += ((IDD0 * tRC) - ((IDD3N * tRAS) + (IDD2N * (tRC - tRAS)))) * ((DRAM_BUS_WIDTH/2 * 8) / DEVICE_WIDTH);

					bankStates[rank][bank].lastCommand = ACTIVATE;
					bankStates[rank][bank].currentBankState = ROW_ACTIVE;
					bankStates[rank][bank].openRowAddress = commandQueue[i]->row;
					bankStates[rank][bank].nextActivate = currentClockCycle + tRC;
					bankStates[rank][bank].nextRead = max(currentClockCycle + tRCD, bankStates[rank][bank].nextRead);
					bankStates[rank][bank].nextWrite = max(currentClockCycle + tRCD, bankStates[rank][bank].nextWrite);

					//keep track of sliding window
					tFAWWindow[rank].push_back(tFAW);

					break;
				default:
					ERROR("Unexpected packet type" << *commandQueue[i]);
					abort();


				}

				//erase
				commandQueue.erase(commandQueue.begin()+i);

				break;
			}
		}
	}
	
	//
	//Debug output
	//
	if(DEBUG_CHANNEL)
	{
		if(commandQueue.size()>0)
		{
			DEBUG("     == Command queue");
			for(unsigned i=0; i<commandQueue.size(); i++)
			{
				DEBUG("       "<<i<<"] " << *commandQueue[i]);
			}
		}

		DEBUG("     == Bank states");

		for(unsigned i=0; i<NUM_RANKS; i++)
		{
			for(unsigned j=0; j<NUM_BANKS; j++)
			{
				DEBUGN("       ");
				if(bankStates[i][j].currentBankState == ROW_ACTIVE)
				{
					DEBUGN("[" << hex << bankStates[i][j].openRowAddress << dec << "] ");
				}
				else if(bankStates[i][j].currentBankState == IDLE)
				{
					DEBUGN("[idle]");
				}
				else if(bankStates[i][j].currentBankState == PRECHARGING)
				{
					DEBUGN("[pre] ");
				}
				else if(bankStates[i][j].currentBankState == REFRESHING)
				{
					DEBUGN("[ref] ");
				}
				else
				{
					ERROR("== Error - unknown state");
					exit(0);
				}
			}
			DEBUG("");
		}
	}

	//increment clock cycle
	currentClockCycle++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x70(%rdi), %rcx
movq 0x50(%rdi), %rax
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcq $-0x1, %rdx
movabsq $-0x400000000000000, %r13 # imm = 0xFC00000000000000
movq 0x58(%rdi), %rsi
subq 0x60(%rdi), %rsi
shlq $0x6, %rdx
sarq $0x3, %rsi
addq %rdx, %rsi
movq 0x38(%rdi), %rcx
movq 0x48(%rdi), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
addq %rsi, %rdx
je 0x10ba3
movq %rcx, %rdi
subq 0x40(%rbx), %rdi
movq %rdi, %r8
sarq $0x3, %r8
xorl %r10d, %r10d
movl $0x1, %r9d
xorl %esi, %esi
cmpq $0x3f, %r8
ja 0x10b5b
leaq (%rcx,%r10,8), %r10
jmp 0x10b7d
movq %r8, %r10
shrq $0x6, %r10
movq %r10, %r11
orq %r13, %r11
testq %r8, %r8
cmovgq %r10, %r11
movq (%rax,%r11,8), %r10
shlq $0x9, %r11
subq %r11, %r10
addq %rdi, %r10
movq (%r10), %r10
xorl %r11d, %r11d
cmpl $0x4, 0x4(%r10)
sete %r11b
addl %r11d, %esi
movl %r9d, %r10d
addq $0x8, %rdi
incq %r8
incl %r9d
cmpq %r10, %rdx
ja 0x10b4f
jmp 0x10ba5
xorl %esi, %esi
cmpl 0x10(%rbx), %esi
jbe 0x10bad
movl %esi, 0x10(%rbx)
addl %esi, 0x14(%rbx)
leaq 0x28(%rbx), %r10
movq 0x78(%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rcx,8), %rsi
xorl %edi, %edi
cmpl $0x1, (%rsi,%rdi)
adcl $0x0, %edx
addq $0x40, %rdi
cmpq $0x200, %rdi            # imm = 0x200
jne 0x10bc2
incq %rcx
cmpq $0x4, %rcx
jne 0x10bbc
addl %edx, 0x18(%rbx)
movq 0x78(%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rcx,8), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x1, (%rsi,%rdi)
sete %r8b
addl %r8d, %edx
addq $0x40, %rdi
cmpq $0x200, %rdi            # imm = 0x200
jne 0x10bf0
incq %rcx
cmpq $0x4, %rcx
jne 0x10bea
addl %edx, 0x1c(%rbx)
movq 0x78(%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rcx,8), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x2, (%rsi,%rdi)
sete %r8b
addl %r8d, %edx
addq $0x40, %rdi
cmpq $0x200, %rdi            # imm = 0x200
jne 0x10c25
incq %rcx
cmpq $0x4, %rcx
jne 0x10c1f
addl %edx, 0x20(%rbx)
movq 0x78(%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rcx,8), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x3, (%rsi,%rdi)
sete %r8b
addl %r8d, %edx
addq $0x40, %rdi
cmpq $0x200, %rdi            # imm = 0x200
jne 0x10c5a
incq %rcx
cmpq $0x4, %rcx
jne 0x10c54
addl %edx, 0x24(%rbx)
movq 0x78(%rbx), %rax
movq 0xf8(%rbx), %rcx
movq 0x158(%rbx), %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
xorl %r8d, %r8d
movl (%rdi,%r8), %r9d
orl $0x2, %r9d
cmpl $0x3, %r9d
je 0x10cc1
addq $0x40, %r8
cmpq $0x100, %r8             # imm = 0x100
jne 0x10c9c
incl (%rdx,%rsi,4)
movl $0x280, %edi            # imm = 0x280
jmp 0x10cc6
movl $0x2d0, %edi            # imm = 0x2D0
addq %rdi, (%rcx,%rsi,8)
incq %rsi
cmpq $0x4, %rsi
jne 0x10c95
movq %r10, 0x8(%rsp)
xorl %r14d, %r14d
movq 0xb0(%rbx), %rax
leaq (%r14,%r14,2), %r15
movq (%rax,%r15,8), %rdi
movq 0x8(%rax,%r15,8), %rdx
cmpq %rdi, %rdx
je 0x10d49
leaq (%rax,%r15,8), %r12
addq $0x8, %r12
movl $0x1, %ebp
xorl %eax, %eax
decl (%rdi,%rax,4)
jne 0x10d1e
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x10d19
subq %rsi, %rdx
callq 0x32f0
addq $-0x4, (%r12)
movl %ebp, %eax
movq 0xb0(%rbx), %rcx
leaq (%rcx,%r15,8), %r12
addq $0x8, %r12
movq -0x8(%r12), %rdi
movq (%r12), %rdx
movq %rdx, %rcx
subq %rdi, %rcx
sarq $0x2, %rcx
incl %ebp
cmpq %rax, %rcx
ja 0x10d03
incq %r14
cmpq $0x4, %r14
jne 0x10cdb
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x78(%rbx), %rax
movq (%rax,%r14,8), %rdi
addq %r15, %rdi
callq 0xc57a
addq $0x40, %r15
cmpq $0x200, %r15            # imm = 0x200
jne 0x10d58
incq %r14
cmpq $0x4, %r14
jne 0x10d55
movq 0xc8(%rbx), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
testl %edx, %edx
je 0x10d93
decl %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq $0x4, %rcx
jne 0x10d87
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
je 0x10dc5
sarq $0x2, %rdx
xorl %esi, %esi
decl (%rax,%rsi,4)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rdx
ja 0x10db8
cmpq %rax, %rcx
je 0x10e36
cmpl $0x0, (%rax)
jne 0x10e36
movq 0x98(%rbx), %rax
movq 0x1b0(%rbx), %rdi
movq (%rax), %rsi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x10(%rax)
movq 0x98(%rbx), %rdi
movq 0xa0(%rbx), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x10e07
subq %rsi, %rdx
callq 0x32f0
addq $-0x8, 0xa0(%rbx)
movq 0x80(%rbx), %rdi
movq 0x88(%rbx), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x10e2e
subq %rsi, %rdx
callq 0x32f0
addq $-0x4, 0x88(%rbx)
leaq 0x80(%rbx), %r14
movq 0xc8(%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x78(%rbx), %rdx
movb $0x1, %sil
xorl %r15d, %r15d
cmpl $0x0, (%rax,%r15,4)
jne 0x10e87
movq (%rdx,%r15,8), %rdi
xorl %r8d, %r8d
cmpq %rcx, 0x8(%rdi,%r8)
ja 0x10e6e
cmpl $0x0, (%rdi,%r8)
je 0x10e70
xorl %esi, %esi
addq $0x40, %r8
cmpq $0x200, %r8             # imm = 0x200
jne 0x10e60
testb $0x1, %sil
jne 0x11002
incq %r15
cmpq $0x4, %r15
jne 0x10e52
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x70(%rbx), %rcx
movq 0x50(%rbx), %rax
movq %rcx, %rsi
subq %rax, %rsi
shrq $0x3, %rsi
cmpq $0x1, %rcx
adcq $-0x1, %rsi
shlq $0x6, %rsi
movq 0x58(%rbx), %rcx
subq 0x60(%rbx), %rcx
sarq $0x3, %rcx
movq 0x38(%rbx), %rdx
movq 0x48(%rbx), %rdi
subq %rdx, %rdi
sarq $0x3, %rdi
addq %rcx, %rdi
addq %rsi, %rdi
cmpq %r15, %rdi
jbe 0x11678
movq %rdx, %rcx
subq 0x40(%rbx), %rcx
sarq $0x3, %rcx
addq %r15, %rcx
cmpq $0x3f, %rcx
ja 0x10ef8
leaq (%rdx,%r15,8), %rcx
jmp 0x10f1e
movq %rcx, %rdx
shrq $0x6, %rdx
movq %rdx, %rsi
orq %r13, %rsi
testq %rcx, %rcx
cmovgq %rdx, %rsi
movq %rsi, %rdx
shlq $0x6, %rdx
subq %rdx, %rcx
shlq $0x3, %rcx
addq (%rax,%rsi,8), %rcx
movq (%rcx), %rsi
movq %rbx, %rdi
callq 0x117e8
testb %al, %al
je 0x10fce
testq %r15, %r15
je 0x10fd6
movq 0x38(%rbx), %rdx
movq %rdx, %rax
subq 0x40(%rbx), %rax
sarq $0x3, %rax
leaq (%rax,%r15), %rcx
cmpq $0x3f, %rcx
ja 0x10f59
leaq (%rdx,%r15,8), %rcx
jmp 0x10f83
movq 0x50(%rbx), %rsi
movq %rcx, %rdi
shrq $0x6, %rdi
movq %rdi, %r8
orq %r13, %r8
testq %rcx, %rcx
cmovgq %rdi, %r8
movq %r8, %rdi
shlq $0x6, %rdi
subq %rdi, %rcx
shlq $0x3, %rcx
addq (%rsi,%r8,8), %rcx
leal -0x1(%r15), %esi
addq %rsi, %rax
cmpq $0x3f, %rax
ja 0x10f96
leaq (%rdx,%rsi,8), %rax
jmp 0x10fc0
movq 0x50(%rbx), %rdx
movq %rax, %rsi
shrq $0x6, %rsi
movq %rsi, %rdi
orq %r13, %rdi
testq %rax, %rax
cmovgq %rsi, %rdi
movq %rdi, %rsi
shlq $0x6, %rsi
subq %rsi, %rax
shlq $0x3, %rax
addq (%rdx,%rdi,8), %rax
movq (%rcx), %rcx
movl 0x18(%rcx), %ecx
movq (%rax), %rax
cmpl 0x18(%rax), %ecx
jne 0x10fd6
incl %r15d
jmp 0x10e93
movq 0x38(%rbx), %rcx
movq %rcx, %rax
subq 0x40(%rbx), %rax
movq 0x1a8(%rbx), %rdi
sarq $0x3, %rax
addq %r15, %rax
cmpq $0x3f, %rax
ja 0x110ce
leaq (%rcx,%r15,8), %rax
jmp 0x110f8
movl $0x38, %edi
callq 0x31d0
movq %rax, %r14
xorl %eax, %eax
movq %r14, %rdi
movl $0x5, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r15d, %r9d
pushq %rax
pushq $0x0
pushq %rax
pushq %rax
pushq %rax
pushq %rax
callq 0xc6d8
addq $0x30, %rsp
movq 0x170(%rbx), %rax
movl 0x1e0(%rax), %eax
movl %eax, 0x28(%r14)
movq 0x1a8(%rbx), %rdi
movq (%rdi), %rax
xorl %r12d, %r12d
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rax)
movq 0x140(%rbx), %rax
addq $0x4d530, (%rax,%r15,8) # imm = 0x4D530
movq 0x8(%rbx), %rax
movq 0x78(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
addq $0x6b, %rax
movabsq $0x6b00000005, %rdx     # imm = 0x6B00000005
movl $0x3, (%rcx,%r12)
movq %rax, 0x8(%rcx,%r12)
movq %rdx, 0x38(%rcx,%r12)
addq $0x40, %r12
cmpq $0x200, %r12            # imm = 0x200
jne 0x11085
movq 0xc8(%rbx), %rax
movl (%rax,%r15,4), %edx
movl $0x4, %ecx
testl %edx, %edx
jne 0x110c5
movl $0x1450, (%rax,%r15,4)  # imm = 0x1450
movl $0x1450, %edx           # imm = 0x1450
decl %ecx
jne 0x110b4
jmp 0x11678
movq 0x50(%rbx), %rcx
movq %rax, %rdx
shrq $0x6, %rdx
movq %rdx, %rsi
orq %r13, %rsi
testq %rax, %rax
cmovgq %rdx, %rsi
movq %rsi, %rdx
shlq $0x6, %rdx
subq %rdx, %rax
shlq $0x3, %rax
addq (%rcx,%rsi,8), %rax
movq (%rax), %rsi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x10(%rax)
movq 0x38(%rbx), %r8
movq %r8, %r12
subq 0x40(%rbx), %r12
sarq $0x3, %r12
addq %r15, %r12
cmpq $0x3f, %r12
ja 0x11121
leaq (%r8,%r15,8), %rax
jmp 0x1114e
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %r13, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq 0x50(%rbx), %rdx
movq %rcx, %rsi
shlq $0x6, %rsi
movq %r12, %rax
subq %rsi, %rax
shlq $0x3, %rax
addq (%rdx,%rcx,8), %rax
movq (%rax), %rax
movl 0x14(%rax), %ebp
cmpq $0x3f, %r12
movq %r14, 0x10(%rsp)
ja 0x11165
leaq (%r8,%r15,8), %rax
jmp 0x11192
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %r13, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq 0x50(%rbx), %rdx
movq %rcx, %rsi
shlq $0x6, %rsi
movq %r12, %rax
subq %rsi, %rax
shlq $0x3, %rax
addq (%rdx,%rcx,8), %rax
movq (%rax), %rax
movl 0x10(%rax), %r14d
cmpq $0x3f, %r12
ja 0x111a5
leaq (%r8,%r15,8), %rax
jmp 0x111d2
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %r13, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq 0x50(%rbx), %rdx
movq %rcx, %rsi
shlq $0x6, %rsi
movq %r12, %rax
subq %rsi, %rax
shlq $0x3, %rax
addq (%rdx,%rcx,8), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
cmpl $0x1, %eax
je 0x112b0
cmpl $0x3, %eax
je 0x11263
cmpl $0x4, %eax
jne 0x1168b
movq 0x8(%rbx), %rax
movq 0x78(%rbx), %rcx
addq $0x4, %rax
shlq $0x6, %r14
xorl %edx, %edx
cmpq %rdx, %r14
je 0x1121b
movq (%rcx,%rbp,8), %rsi
movq 0x8(%rsi,%rdx), %rdi
cmpq %rdi, %rax
cmovaq %rax, %rdi
movq %rdi, 0x8(%rsi,%rdx)
addq $0x40, %rdx
cmpq $0x200, %rdx            # imm = 0x200
jne 0x11201
movq 0x128(%rbx), %rax
addq $0x40b0, (%rax,%rbp,8)  # imm = 0x40B0
movq 0x78(%rbx), %rax
movq (%rax,%rbp,8), %rax
movl $0x4, 0x38(%rax,%r14)
movl $0x1, (%rax,%r14)
cmpq $0x3f, %r12
ja 0x113af
leaq (%r8,%r15,8), %r12
jmp 0x113d9
movq %r8, 0x18(%rsp)
movl 0xf4(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xf4(%rbx)
testl %eax, %eax
jle 0x1170f
movq 0x110(%rbx), %rax
addq $0x1b80, (%rax,%rbp,8)  # imm = 0x1B80
movl $0x38, %edi
callq 0x31d0
cmpq $0x3f, %r12
ja 0x11451
movq 0x18(%rsp), %rcx
leaq (%rcx,%r15,8), %r12
jmp 0x1147b
incl 0xf0(%rbx)
movl 0xf4(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xf4(%rbx)
testl %eax, %eax
jle 0x11765
movq 0x110(%rbx), %rax
addq $0x1a40, (%rax,%rbp,8)  # imm = 0x1A40
movq 0x78(%rbx), %rcx
movq (%rcx,%rbp,8), %rax
movq %r14, %rsi
shlq $0x6, %rsi
movabsq $0x500000001, %rdx      # imm = 0x500000001
movq %rdx, 0x38(%rax,%rsi)
movq 0x8(%rbx), %rdx
leaq 0xe(%rdx), %rdi
movq 0x8(%rax,%rsi), %r8
cmpq %rdi, %r8
cmovbeq %rdi, %r8
movq %r8, 0x8(%rax,%rsi)
movq %rdi, 0x30(%rax,%rsi)
movl $0xf, %esi
subl 0x7f61(%rip), %esi      # 0x19284
leaq 0x6(%rdx), %rdi
addq %rdx, %rsi
addq $0x4, %rdx
xorl %r8d, %r8d
movq (%rcx,%r8,8), %r9
xorl %r10d, %r10d
cmpq %rbp, %r8
jne 0x1136e
movq 0x10(%r9,%r10), %r11
movq 0x18(%r9,%r10), %r12
cmpq %rdx, %r11
cmovbeq %rdx, %r11
cmpq %rsi, %r12
cmovbeq %rsi, %r12
movq %r11, 0x10(%r9,%r10)
movq %r12, 0x18(%r9,%r10)
addq $0x40, %r10
cmpq $0x200, %r10            # imm = 0x200
jne 0x1133d
jmp 0x1139d
movq 0x10(%r9,%r10), %r11
movq 0x18(%r9,%r10), %r12
cmpq %rdi, %r11
cmovbeq %rdi, %r11
cmpq %rsi, %r12
cmovbeq %rsi, %r12
movq %r11, 0x10(%r9,%r10)
movq %r12, 0x18(%r9,%r10)
addq $0x40, %r10
cmpq $0x200, %r10            # imm = 0x200
jne 0x1136e
incq %r8
cmpq $0x4, %r8
jne 0x11331
shlq $0x6, %r14
jmp 0x115f7
movq 0x50(%rbx), %rcx
movq %r12, %rdx
shrq $0x6, %rdx
movq %rdx, %rsi
orq %r13, %rsi
testq %r12, %r12
cmovgq %rdx, %rsi
movq %rsi, %rdx
shlq $0x6, %rdx
subq %rdx, %r12
shlq $0x3, %r12
addq (%rcx,%rsi,8), %r12
movq (%r12), %rcx
movl 0xc(%rcx), %ecx
movl %ecx, 0x4(%rax,%r14)
movq 0x8(%rbx), %rcx
leaq 0x21(%rcx), %rdx
movq %rdx, 0x8(%rax,%r14)
addq $0x9, %rcx
movq 0x10(%rax,%r14), %rdx
movq 0x18(%rax,%r14), %rsi
cmpq %rdx, %rcx
cmovaq %rcx, %rdx
cmpq %rsi, %rcx
cmovbeq %rsi, %rcx
movq %rdx, 0x10(%rax,%r14)
movq %rcx, 0x18(%rax,%r14)
movq 0xb0(%rbx), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x114c6
movl 0x7e46(%rip), %eax      # 0x19288
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x11606
movq 0x50(%rbx), %rcx
movq %r12, %rdx
shrq $0x6, %rdx
movq %rdx, %rsi
orq %r13, %rsi
testq %r12, %r12
cmovgq %rdx, %rsi
movq %rsi, %rdx
shlq $0x6, %rdx
subq %rdx, %r12
shlq $0x3, %r12
addq (%rcx,%rsi,8), %r12
movq (%r12), %rcx
movq 0x30(%rcx), %rdx
movq %rdx, 0x30(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movq %rax, 0x20(%rsp)
movl $0x8, 0x4(%rax)
movq 0xa0(%rbx), %rsi
cmpq 0xa8(%rbx), %rsi
je 0x114d7
movq %rax, (%rsi)
addq $0x8, 0xa0(%rbx)
jmp 0x114e8
leaq 0x7dbb(%rip), %rdx      # 0x19288
callq 0xc480
jmp 0x11606
leaq 0x98(%rbx), %rdi
leaq 0x20(%rsp), %rdx
callq 0x10494
movq 0x88(%rbx), %rsi
cmpq 0x90(%rbx), %rsi
je 0x1150d
movl 0x7d86(%rip), %eax      # 0x19284
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x88(%rbx)
jmp 0x1151e
leaq 0x7d70(%rip), %rdx      # 0x19284
movq 0x10(%rsp), %rdi
callq 0xc480
movq 0x78(%rbx), %rcx
movq (%rcx,%rbp,8), %rax
shlq $0x6, %r14
movl $0x3, 0x38(%rax,%r14)
movl 0x7d4b(%rip), %edx      # 0x19284
addl $0xe, %edx
movl %edx, 0x3c(%rax,%r14)
movq 0x8(%rbx), %rdx
movl 0x7d38(%rip), %r8d      # 0x19284
leaq (%rdx,%r8), %rsi
addq $0x17, %rsi
movq %rsi, 0x8(%rax,%r14)
movq %rax, 0x10(%rsp)
movq %rsi, 0x30(%rax,%r14)
leaq (%rdx,%r8), %rsi
addq $-0x3, %rsi
leaq 0x6(%rdx), %rdi
addq %rdx, %r8
addq $0x9, %r8
addq $0x4, %rdx
xorl %r9d, %r9d
movq (%rcx,%r9,8), %r10
xorl %r11d, %r11d
cmpq %rbp, %r9
jne 0x115ba
movq 0x10(%r10,%r11), %r12
movq 0x18(%r10,%r11), %rax
cmpq %r8, %r12
cmovbeq %r8, %r12
cmpq %rdx, %rax
cmovbeq %rdx, %rax
movq %r12, 0x10(%r10,%r11)
movq %rax, 0x18(%r10,%r11)
addq $0x40, %r11
cmpq $0x200, %r11            # imm = 0x200
jne 0x11589
jmp 0x115e9
movq 0x10(%r10,%r11), %rax
movq 0x18(%r10,%r11), %r12
cmpq %rsi, %rax
cmovbeq %rsi, %rax
cmpq %rdi, %r12
cmovbeq %rdi, %r12
movq %rax, 0x10(%r10,%r11)
movq %r12, 0x18(%r10,%r11)
addq $0x40, %r11
cmpq $0x200, %r11            # imm = 0x200
jne 0x115ba
incq %r9
cmpq $0x4, %r9
jne 0x1157d
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14), %rcx
movq %rcx, 0x10(%rax,%r14)
movq %rcx, 0x18(%rax,%r14)
movq 0x8(%rsp), %rsi
movq 0x38(%rbx), %rdx
movq %rdx, %rcx
subq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rax
sarq $0x3, %rcx
addq %r15, %rcx
cmpq $0x3f, %rcx
ja 0x1162d
leaq (%rdx,%r15,8), %rcx
jmp 0x11650
movq %rcx, %rdx
shrq $0x6, %rdx
orq %rdx, %r13
testq %rcx, %rcx
cmovgq %rdx, %r13
leaq (%rax,%r13,8), %rax
shlq $0x6, %r13
subq %r13, %rcx
shlq $0x3, %rcx
addq (%rax), %rcx
leaq 0x48(%rsp), %rdx
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, 0x8(%rdx)
addq $0x200, %rcx            # imm = 0x200
movq %rcx, 0x10(%rdx)
movq %rax, 0x18(%rdx)
leaq 0x28(%rsp), %rdi
callq 0x76fc
incq 0x8(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x795e(%rip), %rdi      # 0x18ff0
leaq 0x1adf(%rip), %rsi      # 0x13178
callq 0x31c0
leaq 0x32e3(%rip), %rsi      # 0x14988
movq %rax, %rdi
callq 0x31c0
leaq 0x1a6d(%rip), %rsi      # 0x13121
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x1d6, %esi            # imm = 0x1D6
callq 0x3330
leaq 0x1ab9(%rip), %rsi      # 0x13189
movq %rax, %rdi
callq 0x31c0
leaq 0x32d8(%rip), %rsi      # 0x149b7
movq %rax, %rdi
callq 0x31c0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x11fd6
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xc9a7
movq %rax, %rdi
callq 0x30d0
callq 0x3100
movq 0x78da(%rip), %rdi      # 0x18ff0
leaq 0x1a5b(%rip), %rsi      # 0x13178
callq 0x31c0
leaq 0x325f(%rip), %rsi      # 0x14988
movq %rax, %rdi
callq 0x31c0
leaq 0x19e9(%rip), %rsi      # 0x13121
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x194, %esi            # imm = 0x194
callq 0x3330
leaq 0x1a35(%rip), %rsi      # 0x13189
movq %rax, %rdi
callq 0x31c0
leaq 0x3247(%rip), %rsi      # 0x149aa
jmp 0x117b9
movq 0x7884(%rip), %rdi      # 0x18ff0
leaq 0x1a05(%rip), %rsi      # 0x13178
callq 0x31c0
leaq 0x3209(%rip), %rsi      # 0x14988
movq %rax, %rdi
callq 0x31c0
leaq 0x1993(%rip), %rsi      # 0x13121
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x167, %esi            # imm = 0x167
callq 0x3330
leaq 0x19df(%rip), %rsi      # 0x13189
movq %rax, %rdi
callq 0x31c0
leaq 0x31e4(%rip), %rsi      # 0x1499d
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x30d0
xorl %edi, %edi
callq 0x3220
movq %rax, %rbx
movl $0x38, %esi
movq %r14, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3340