// File: estwings57[P]CasHMC/sources/RunSim.cpp
// Function: main
int main(int argc, char **argv)
{
	//
	//parse command-line options setting
	//
	numSimCycles = 100000;
	memUtil = 0.1;
	rwRatio = 80;
	traceType = "";
	traceFileName = "";
	
	int opt;
	string pwdString = "";
	ifstream traceFile;
	string line;
	bool pendingTran = false;
	while(1) {
		static struct option long_options[] = {
			{"pwd", required_argument, 0, 'p'},
			{"cycle",  required_argument, 0, 'c'},
			{"trace",  required_argument, 0, 't'},
			{"util",  required_argument, 0, 'u'},
			{"rwratio",  required_argument, 0, 'r'},
			{"file",  required_argument, 0, 'f'},
			{"help", no_argument, 0, 'h'},
			{0, 0, 0, 0}
		};
		int option_index=0;
		opt = getopt_long (argc, argv, "p:c:t:u:r:f:h", long_options, &option_index);
		if(opt == -1) {
			break;
		}
		switch(opt) {
			case 0:
				if (long_options[option_index].flag != 0) {
					cout<<"setting flag"<<endl;
					break;
				}
				cout<<"option "<<long_options[option_index].name<<endl;
				if (optarg) {
					cout<<" with arg"<<optarg<<endl;
				}
				cout<<""<<endl;
				break;
			case 'p':
				pwdString = string(optarg);
				break;
			case 'c':
				numSimCycles = atol(optarg);
				break;
			case 't':
				traceType = string(optarg);
				if(traceType != "random" && traceType != "file") {
					cout<<endl<<" == -t (--trace) ERROR ==";
					cout<<endl<<"  This option must be selected by one of 'random' and 'file'"<<endl<<endl;
					exit(0);
				}
				break;
			case 'u':
				memUtil = atof(optarg);
				if(memUtil < 0 || memUtil > 1) {
					cout<<endl<<" == -u (--util) ERROR ==";
					cout<<endl<<"  This value must be in the between '0' and '1'"<<endl<<endl;
					exit(0);
				}
				break;
			case 'r':
				rwRatio = atof(optarg);
				if(rwRatio < 0 || rwRatio > 100) {
					cout<<endl<<" == -r (--rwratio) ERROR ==";
					cout<<endl<<"  This value is the percentage of reads in request stream"<<endl<<endl;
					exit(0);
				}
				break;
			case 'f':
				traceFileName = string(optarg);
				if(access(traceFileName.c_str(), 0) == -1) {
					cout<<endl<<" == -f (--file) ERROR ==";
					cout<<endl<<"  There is no trace file ["<<traceFileName<<"]"<<endl<<endl;
					exit(0);
				}
				break;
			case 'h':
			case '?':
				Help();
				exit(0);
				break;
		}
	}
	
	srand((unsigned)time(NULL));
	casHMCWrapper = new CasHMCWrapper("ConfigSim.ini", "ConfigDRAM.ini");
	
#ifdef CALLBACKTRANS
	//Register callback function (ReadComplete, WriteComplete)
	CallbackTrans callbackTrans;
	TransCompCB* read_cb = new Callback<CallbackTrans, void, uint64_t, uint64_t>(&callbackTrans, &CallbackTrans::ReadComplete);
    TransCompCB* write_cb = new Callback<CallbackTrans, void, uint64_t, uint64_t>(&callbackTrans, &CallbackTrans::WriteComplete);
	casHMCWrapper->RegisterCallbacks(read_cb, write_cb);
#endif
	
	if(traceType == "random") {
		for(uint64_t cpuCycle=0; cpuCycle<numSimCycles; cpuCycle++) {
			MakeRandomTransaction();
			if(!transactionBuffers.empty()) {
				if(casHMCWrapper->ReceiveTran(transactionBuffers[0])) {
					transactionBuffers.erase(transactionBuffers.begin());
				}
			}
			casHMCWrapper->Update();
		}
	}
	else if(traceType == "file") {
		uint64_t issueClock = 0;
		traceFile.open(traceFileName.c_str());
		if(!traceFile.is_open()) {
			ERROR(" == Error - Could not open trace file ["<<traceFileName<<"]");
			exit(0);
		}
		for(uint64_t cpuCycle=0; cpuCycle<numSimCycles; cpuCycle++) {
			if(!pendingTran) {
				if(!traceFile.eof()) {
					getline(traceFile, line);
					if(line.size() > 0) {
						uint64_t addr;
						TransactionType tranType;
						unsigned dataSize;
						ParseTraceFileLine(line, issueClock, addr, tranType, dataSize);
						Transaction *newTran = new Transaction(tranType, addr, dataSize, casHMCWrapper);
						
						if(cpuCycle >= issueClock) {
							if(!casHMCWrapper->ReceiveTran(newTran)) {
								pendingTran = true;
								transactionBuffers.push_back(newTran);
							}
						}
						else {
							pendingTran = true;
							transactionBuffers.push_back(newTran);
						}
					}
					else {
						cout<<" ## WARNING ## Skipping line ("<<lineNumber<<") in tracefile  (CurrentClock : "<<cpuCycle<<")"<<endl;
					}
					lineNumber++;
				}
			}
			else {
				if(cpuCycle >= issueClock) {
					if(casHMCWrapper->ReceiveTran(transactionBuffers[0])) {
						pendingTran = false;
						transactionBuffers.erase(transactionBuffers.begin());
					}
				}					
			}
			casHMCWrapper->Update();
		}
	}

	transactionBuffers.clear();
	delete casHMCWrapper;
	casHMCWrapper = NULL;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5c0, %rsp            # imm = 0x5C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x1d3b0(%rip), %rax     # 0x664b0
movq $0x186a0, (%rax)        # imm = 0x186A0
leaq 0x1d3aa(%rip), %rax     # 0x664b8
movabsq $0x3fb999999999999a, %rcx # imm = 0x3FB999999999999A
movq %rcx, (%rax)
leaq 0x1d39e(%rip), %rax     # 0x664c0
movabsq $0x4054000000000000, %rcx # imm = 0x4054000000000000
movq %rcx, (%rax)
leaq 0x1d392(%rip), %rdi     # 0x664c8
leaq 0x98d8(%rip), %rsi      # 0x52a15
movq %rsi, -0x3b8(%rbp)
callq 0x44e0
movq -0x3b8(%rbp), %rsi
leaq 0x1d391(%rip), %rdi     # 0x664e8
callq 0x44e0
leaq -0x39(%rbp), %rdi
movq %rdi, -0x3b0(%rbp)
callq 0x4640
movq -0x3b8(%rbp), %rsi
movq -0x3b0(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x15fa0
jmp 0x49185
leaq -0x39(%rbp), %rdi
callq 0x43f0
leaq -0x258(%rbp), %rdi
callq 0x4420
jmp 0x4919c
leaq -0x278(%rbp), %rdi
callq 0x44f0
movb $0x0, -0x279(%rbp)
jmp 0x491b1
movl $0x0, -0x280(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xb3b1(%rip), %rdx      # 0x5457a
leaq 0x1d1d0(%rip), %rcx     # 0x663a0
leaq -0x280(%rbp), %r8
callq 0x45a0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x49215
jmp 0x499b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x43f0
jmp 0x4a17c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4a173
movl -0x14(%rbp), %eax
movl %eax, -0x3bc(%rbp)
testl %eax, %eax
je 0x492b3
jmp 0x49228
movl -0x3bc(%rbp), %eax
subl $0x3f, %eax
je 0x4999e
jmp 0x49239
movl -0x3bc(%rbp), %eax
subl $0x63, %eax
je 0x49491
jmp 0x4924a
movl -0x3bc(%rbp), %eax
subl $0x66, %eax
je 0x4981c
jmp 0x4925b
movl -0x3bc(%rbp), %eax
subl $0x68, %eax
je 0x4999e
jmp 0x4926c
movl -0x3bc(%rbp), %eax
subl $0x70, %eax
je 0x49407
jmp 0x4927d
movl -0x3bc(%rbp), %eax
subl $0x72, %eax
je 0x4972f
jmp 0x4928e
movl -0x3bc(%rbp), %eax
subl $0x74, %eax
je 0x494b2
jmp 0x4929f
movl -0x3bc(%rbp), %eax
subl $0x75, %eax
je 0x49642
jmp 0x499ac
movslq -0x280(%rbp), %rcx
leaq 0x1d0df(%rip), %rax     # 0x663a0
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
je 0x49316
movq 0x1ccfa(%rip), %rdi     # 0x65fd0
leaq 0xb2ab(%rip), %rsi      # 0x54588
callq 0x4380
movq %rax, -0x3c8(%rbp)
jmp 0x492eb
movq -0x3c8(%rbp), %rdi
movq 0x1ccb7(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49300
jmp 0x499ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4a15b
movq 0x1ccb3(%rip), %rdi     # 0x65fd0
leaq 0xb271(%rip), %rsi      # 0x54595
callq 0x4380
movq %rax, -0x3d0(%rbp)
jmp 0x49332
movq -0x3d0(%rbp), %rdi
movslq -0x280(%rbp), %rax
shlq $0x5, %rax
leaq 0x1d055(%rip), %rcx     # 0x663a0
movq (%rax,%rcx), %rsi
callq 0x4380
movq %rax, -0x3d8(%rbp)
jmp 0x4935d
movq -0x3d8(%rbp), %rdi
movq 0x1cc45(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49372
movq 0x1cc3f(%rip), %rax     # 0x65fb8
cmpq $0x0, (%rax)
je 0x493d1
movq 0x1cc4a(%rip), %rdi     # 0x65fd0
leaq 0xb210(%rip), %rsi      # 0x5459d
callq 0x4380
movq %rax, -0x3e0(%rbp)
jmp 0x4939b
movq -0x3e0(%rbp), %rdi
movq 0x1cc0f(%rip), %rax     # 0x65fb8
movq (%rax), %rsi
callq 0x4380
movq %rax, -0x3e8(%rbp)
jmp 0x493ba
movq -0x3e8(%rbp), %rdi
movq 0x1cbe8(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x493cf
jmp 0x493d1
movq 0x1cbf8(%rip), %rdi     # 0x65fd0
leaq 0x9636(%rip), %rsi      # 0x52a15
callq 0x4380
movq %rax, -0x3f0(%rbp)
jmp 0x493ed
movq -0x3f0(%rbp), %rdi
movq 0x1cbb5(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49402
jmp 0x499ac
movq 0x1cbaa(%rip), %rax     # 0x65fb8
movq (%rax), %rax
movq %rax, -0x400(%rbp)
leaq -0x2a1(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x4640
movq -0x400(%rbp), %rsi
movq -0x3f8(%rbp), %rdx
leaq -0x2a0(%rbp), %rdi
callq 0x15fa0
jmp 0x49447
leaq -0x38(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x4470
leaq -0x2a0(%rbp), %rdi
callq 0x46e8
leaq -0x2a1(%rbp), %rdi
callq 0x43f0
jmp 0x499ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2a1(%rbp), %rdi
callq 0x43f0
jmp 0x4a15b
movq 0x1cb20(%rip), %rax     # 0x65fb8
movq (%rax), %rdi
callq 0x4450
movq %rax, %rcx
leaq 0x1d006(%rip), %rax     # 0x664b0
movq %rcx, (%rax)
jmp 0x499ac
movq 0x1caff(%rip), %rax     # 0x65fb8
movq (%rax), %rax
movq %rax, -0x410(%rbp)
leaq -0x2c9(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x4640
movq -0x410(%rbp), %rsi
movq -0x408(%rbp), %rdx
leaq -0x2c8(%rbp), %rdi
callq 0x15fa0
jmp 0x494f2
leaq 0x1cfcf(%rip), %rdi     # 0x664c8
movq %rdi, -0x420(%rbp)
leaq -0x2c8(%rbp), %rsi
movq %rsi, -0x428(%rbp)
callq 0x4470
movq -0x428(%rbp), %rdi
callq 0x46e8
leaq -0x2c9(%rbp), %rdi
callq 0x43f0
movq -0x420(%rbp), %rdi
leaq 0x84e6(%rip), %rsi      # 0x51a1f
callq 0x4a190
movb %al, -0x411(%rbp)
jmp 0x49546
movb -0x411(%rbp), %al
testb $0x1, %al
jne 0x49555
jmp 0x4963d
leaq 0x1cf6c(%rip), %rdi     # 0x664c8
leaq 0x9806(%rip), %rsi      # 0x52d69
callq 0x4a190
movb %al, -0x429(%rbp)
jmp 0x49570
movb -0x429(%rbp), %al
testb $0x1, %al
jne 0x4957f
jmp 0x4963d
movq 0x1ca4a(%rip), %rdi     # 0x65fd0
movq 0x1ca23(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x438(%rbp)
jmp 0x4959b
movq -0x438(%rbp), %rdi
leaq 0xaffe(%rip), %rsi      # 0x545a7
callq 0x4380
jmp 0x495b0
movq 0x1ca19(%rip), %rdi     # 0x65fd0
movq 0x1c9f2(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x440(%rbp)
jmp 0x495cc
movq -0x440(%rbp), %rdi
leaq 0xafe7(%rip), %rsi      # 0x545c1
callq 0x4380
movq %rax, -0x448(%rbp)
jmp 0x495e8
movq -0x448(%rbp), %rdi
movq 0x1c9ba(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x450(%rbp)
jmp 0x49604
movq -0x450(%rbp), %rdi
movq 0x1c99e(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49619
xorl %edi, %edi
callq 0x4460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2c9(%rbp), %rdi
callq 0x43f0
jmp 0x4a15b
jmp 0x499ac
movq 0x1c96f(%rip), %rax     # 0x65fb8
movq (%rax), %rdi
callq 0x4490
leaq 0x1ce60(%rip), %rax     # 0x664b8
movsd %xmm0, (%rax)
xorps %xmm0, %xmm0
leaq 0x1ce52(%rip), %rax     # 0x664b8
ucomisd (%rax), %xmm0
ja 0x49689
leaq 0x1ce45(%rip), %rax     # 0x664b8
movsd (%rax), %xmm0
movsd 0x7a31(%rip), %xmm1     # 0x510b0
ucomisd %xmm1, %xmm0
jbe 0x4972a
movq 0x1c940(%rip), %rdi     # 0x65fd0
movq 0x1c919(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x458(%rbp)
jmp 0x496a5
movq -0x458(%rbp), %rdi
leaq 0xaf4b(%rip), %rsi      # 0x545fe
callq 0x4380
jmp 0x496ba
movq 0x1c90f(%rip), %rdi     # 0x65fd0
movq 0x1c8e8(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x460(%rbp)
jmp 0x496d6
movq -0x460(%rbp), %rdi
leaq 0xaf33(%rip), %rsi      # 0x54617
callq 0x4380
movq %rax, -0x468(%rbp)
jmp 0x496f2
movq -0x468(%rbp), %rdi
movq 0x1c8b0(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x470(%rbp)
jmp 0x4970e
movq -0x470(%rbp), %rdi
movq 0x1c894(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49723
xorl %edi, %edi
callq 0x4460
jmp 0x499ac
movq 0x1c882(%rip), %rax     # 0x65fb8
movq (%rax), %rdi
callq 0x4490
leaq 0x1cd7b(%rip), %rax     # 0x664c0
movsd %xmm0, (%rax)
xorps %xmm0, %xmm0
leaq 0x1cd6d(%rip), %rax     # 0x664c0
ucomisd (%rax), %xmm0
ja 0x49776
leaq 0x1cd60(%rip), %rax     # 0x664c0
movsd (%rax), %xmm0
movsd 0x795c(%rip), %xmm1     # 0x510c8
ucomisd %xmm1, %xmm0
jbe 0x49817
movq 0x1c853(%rip), %rdi     # 0x65fd0
movq 0x1c82c(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x478(%rbp)
jmp 0x49792
movq -0x478(%rbp), %rdi
leaq 0xaea7(%rip), %rsi      # 0x54647
callq 0x4380
jmp 0x497a7
movq 0x1c822(%rip), %rdi     # 0x65fd0
movq 0x1c7fb(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x480(%rbp)
jmp 0x497c3
movq -0x480(%rbp), %rdi
leaq 0xae92(%rip), %rsi      # 0x54663
callq 0x4380
movq %rax, -0x488(%rbp)
jmp 0x497df
movq -0x488(%rbp), %rdi
movq 0x1c7c3(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x490(%rbp)
jmp 0x497fb
movq -0x490(%rbp), %rdi
movq 0x1c7a7(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49810
xorl %edi, %edi
callq 0x4460
jmp 0x499ac
movq 0x1c795(%rip), %rax     # 0x65fb8
movq (%rax), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x2f1(%rbp), %rdi
movq %rdi, -0x498(%rbp)
callq 0x4640
movq -0x4a0(%rbp), %rsi
movq -0x498(%rbp), %rdx
leaq -0x2f0(%rbp), %rdi
callq 0x15fa0
jmp 0x4985c
leaq 0x1cc85(%rip), %rdi     # 0x664e8
leaq -0x2f0(%rbp), %rsi
callq 0x4470
leaq -0x2f0(%rbp), %rdi
callq 0x46e8
leaq -0x2f1(%rbp), %rdi
callq 0x43f0
leaq 0x1cc5a(%rip), %rdi     # 0x664e8
callq 0x4180
movq %rax, %rdi
xorl %esi, %esi
callq 0x45b0
cmpl $-0x1, %eax
jne 0x4999c
movq 0x1c723(%rip), %rdi     # 0x65fd0
movq 0x1c6fc(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x4a8(%rbp)
jmp 0x498c2
movq -0x4a8(%rbp), %rdi
leaq 0xadcd(%rip), %rsi      # 0x5469d
callq 0x4380
jmp 0x498d7
movq 0x1c6f2(%rip), %rdi     # 0x65fd0
movq 0x1c6cb(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x4b0(%rbp)
jmp 0x498f3
movq -0x4b0(%rbp), %rdi
leaq 0xadb5(%rip), %rsi      # 0x546b6
callq 0x4380
movq %rax, -0x4b8(%rbp)
jmp 0x4990f
movq -0x4b8(%rbp), %rdi
leaq 0x1cbcb(%rip), %rsi     # 0x664e8
callq 0x4320
movq %rax, -0x4c0(%rbp)
jmp 0x4992b
movq -0x4c0(%rbp), %rdi
leaq 0x90e1(%rip), %rsi      # 0x52a1a
callq 0x4380
movq %rax, -0x4c8(%rbp)
jmp 0x49947
movq -0x4c8(%rbp), %rdi
movq 0x1c65b(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq %rax, -0x4d0(%rbp)
jmp 0x49963
movq -0x4d0(%rbp), %rdi
movq 0x1c63f(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49978
xorl %edi, %edi
callq 0x4460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2f1(%rbp), %rdi
callq 0x43f0
jmp 0x4a15b
jmp 0x499ac
callq 0x482c0
jmp 0x499a5
xorl %edi, %edi
callq 0x4460
jmp 0x491af
xorl %eax, %eax
movl %eax, %edi
callq 0x4330
movl %eax, %edi
callq 0x4360
movl $0x1018, %edi           # imm = 0x1018
callq 0x4390
movq %rax, -0x4d8(%rbp)
jmp 0x499d4
movb $0x1, -0x342(%rbp)
leaq -0x319(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x4640
movq -0x4e0(%rbp), %rdx
leaq 0xacd5(%rip), %rsi      # 0x546d1
leaq -0x318(%rbp), %rdi
callq 0x15fa0
jmp 0x49a0a
leaq -0x341(%rbp), %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x4640
movq -0x4e8(%rbp), %rdx
leaq 0xacb4(%rip), %rsi      # 0x546df
leaq -0x340(%rbp), %rdi
callq 0x15fa0
jmp 0x49a39
movq -0x4d8(%rbp), %rdi
leaq -0x318(%rbp), %rsi
leaq -0x340(%rbp), %rdx
callq 0x7480
jmp 0x49a55
movq -0x4d8(%rbp), %rax
movb $0x0, -0x342(%rbp)
movq %rax, 0x1da06(%rip)     # 0x67470
leaq -0x340(%rbp), %rdi
callq 0x46e8
leaq -0x341(%rbp), %rdi
callq 0x43f0
leaq -0x318(%rbp), %rdi
callq 0x46e8
leaq -0x319(%rbp), %rdi
callq 0x43f0
leaq 0x1ca27(%rip), %rdi     # 0x664c8
leaq 0x7f77(%rip), %rsi      # 0x51a1f
callq 0x17d00
movb %al, -0x4e9(%rbp)
jmp 0x49ab5
movb -0x4e9(%rbp), %al
testb $0x1, %al
jne 0x49ac4
jmp 0x49c45
movq $0x0, -0x350(%rbp)
movq -0x350(%rbp), %rax
leaq 0x1c9d3(%rip), %rcx     # 0x664b0
cmpq (%rcx), %rax
jae 0x49c40
callq 0x483b0
jmp 0x49aed
leaq 0x1d964(%rip), %rdi     # 0x67458
callq 0x4a1c0
testb $0x1, %al
jne 0x49c19
movq 0x1d968(%rip), %rax     # 0x67470
movq %rax, -0x4f8(%rbp)
leaq 0x1d942(%rip), %rdi     # 0x67458
xorl %eax, %eax
movl %eax, %esi
callq 0x3a790
movq -0x4f8(%rbp), %rdi
movq (%rax), %rsi
callq 0x14b40
movb %al, -0x4ea(%rbp)
jmp 0x49b36
movb -0x4ea(%rbp), %al
testb $0x1, %al
jne 0x49b45
jmp 0x49c17
leaq 0x1d90c(%rip), %rdi     # 0x67458
movq %rdi, -0x508(%rbp)
callq 0x1b8a0
movq %rax, -0x360(%rbp)
leaq -0x358(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x3a820
movq -0x508(%rbp), %rdi
movq -0x358(%rbp), %rsi
callq 0x3a7b0
movq %rax, -0x500(%rbp)
jmp 0x49b8e
movq -0x500(%rbp), %rax
movq %rax, -0x368(%rbp)
jmp 0x49c17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x49bea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x49bd2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x46e8
leaq -0x341(%rbp), %rdi
callq 0x43f0
leaq -0x318(%rbp), %rdi
callq 0x46e8
leaq -0x319(%rbp), %rdi
callq 0x43f0
testb $0x1, -0x342(%rbp)
jne 0x49c01
jmp 0x49c12
movq -0x4d8(%rbp), %rdi
movl $0x1018, %esi           # imm = 0x1018
callq 0x43a0
jmp 0x4a15b
jmp 0x49c19
movq 0x1d850(%rip), %rdi     # 0x67470
callq 0x14ca0
jmp 0x49c27
jmp 0x49c29
movq -0x350(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x350(%rbp)
jmp 0x49acf
jmp 0x4a0ef
leaq 0x1c87c(%rip), %rdi     # 0x664c8
leaq 0x9116(%rip), %rsi      # 0x52d69
callq 0x17d00
movb %al, -0x509(%rbp)
jmp 0x49c60
movb -0x509(%rbp), %al
testb $0x1, %al
jne 0x49c6f
jmp 0x4a0ed
movq $0x0, -0x370(%rbp)
leaq 0x1c867(%rip), %rdi     # 0x664e8
callq 0x4180
movq %rax, %rsi
leaq -0x258(%rbp), %rdi
movl $0x8, %edx
callq 0x4230
jmp 0x49c9c
leaq -0x258(%rbp), %rdi
callq 0x4570
movb %al, -0x50a(%rbp)
jmp 0x49cb0
movb -0x50a(%rbp), %al
testb $0x1, %al
jne 0x49dba
jmp 0x49cc0
movq 0x1c329(%rip), %rdi     # 0x65ff0
leaq 0x736c(%rip), %rsi      # 0x5103a
callq 0x4380
movq %rax, -0x518(%rbp)
jmp 0x49cdc
movq -0x518(%rbp), %rdi
leaq 0xa783(%rip), %rsi      # 0x5446d
callq 0x4380
movq %rax, -0x520(%rbp)
jmp 0x49cf8
movq -0x520(%rbp), %rdi
leaq 0x7b2f(%rip), %rsi      # 0x51835
callq 0x4380
movq %rax, -0x528(%rbp)
jmp 0x49d14
movq -0x528(%rbp), %rdi
movl $0x105, %esi            # imm = 0x105
callq 0x4610
movq %rax, -0x530(%rbp)
jmp 0x49d2e
movq -0x530(%rbp), %rdi
leaq 0x731d(%rip), %rsi      # 0x51059
callq 0x4380
movq %rax, -0x538(%rbp)
jmp 0x49d4a
movq -0x538(%rbp), %rdi
leaq 0xa996(%rip), %rsi      # 0x546ee
callq 0x4380
movq %rax, -0x540(%rbp)
jmp 0x49d66
movq -0x540(%rbp), %rdi
leaq 0x1c774(%rip), %rsi     # 0x664e8
callq 0x4320
movq %rax, -0x548(%rbp)
jmp 0x49d82
movq -0x548(%rbp), %rdi
leaq 0x8c8a(%rip), %rsi      # 0x52a1a
callq 0x4380
movq %rax, -0x550(%rbp)
jmp 0x49d9e
movq -0x550(%rbp), %rdi
movq 0x1c204(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49db3
xorl %edi, %edi
callq 0x4460
movq $0x0, -0x378(%rbp)
movq -0x378(%rbp), %rax
leaq 0x1c6dd(%rip), %rcx     # 0x664b0
cmpq (%rcx), %rax
jae 0x4a0eb
testb $0x1, -0x279(%rbp)
jne 0x4a00d
movq -0x258(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x258(%rbp,%rax), %rdi
callq 0x4680
movb %al, -0x551(%rbp)
jmp 0x49e09
movb -0x551(%rbp), %al
testb $0x1, %al
jne 0x4a008
jmp 0x49e19
leaq -0x258(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x40c0
jmp 0x49e2e
leaq -0x278(%rbp), %rdi
callq 0x4260
cmpq $0x0, %rax
jbe 0x49f53
leaq -0x278(%rbp), %rdi
leaq -0x370(%rbp), %rsi
leaq -0x380(%rbp), %rdx
leaq -0x384(%rbp), %rcx
leaq -0x388(%rbp), %r8
callq 0x48510
jmp 0x49e6e
movl $0x30, %edi
callq 0x4390
movq %rax, -0x560(%rbp)
jmp 0x49e81
movq -0x560(%rbp), %rdi
movl -0x384(%rbp), %esi
movq -0x380(%rbp), %rdx
movl -0x388(%rbp), %ecx
movq 0x1d5ce(%rip), %r8      # 0x67470
callq 0x4a2a0
jmp 0x49ea9
movq -0x560(%rbp), %rax
movq %rax, -0x390(%rbp)
movq -0x378(%rbp), %rax
cmpq -0x370(%rbp), %rax
jb 0x49f30
movq 0x1d5a2(%rip), %rdi     # 0x67470
movq -0x390(%rbp), %rsi
callq 0x14b40
movb %al, -0x561(%rbp)
jmp 0x49ee2
movb -0x561(%rbp), %al
testb $0x1, %al
jne 0x49f2e
jmp 0x49eee
movb $0x1, -0x279(%rbp)
leaq 0x1d55c(%rip), %rdi     # 0x67458
leaq -0x390(%rbp), %rsi
callq 0x1b510
jmp 0x49f0a
jmp 0x49f2e
movq -0x560(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x30, %esi
callq 0x43a0
jmp 0x4a15b
jmp 0x49f4e
movb $0x1, -0x279(%rbp)
leaq 0x1d51a(%rip), %rdi     # 0x67458
leaq -0x390(%rbp), %rsi
callq 0x1b510
jmp 0x49f4c
jmp 0x49f4e
jmp 0x49ff6
movq 0x1c076(%rip), %rdi     # 0x65fd0
leaq 0xa7b5(%rip), %rsi      # 0x54716
callq 0x4380
movq %rax, -0x570(%rbp)
jmp 0x49f6f
movq -0x570(%rbp), %rdi
movq 0x1c413(%rip), %rsi     # 0x66390
callq 0x40f0
movq %rax, -0x578(%rbp)
jmp 0x49f8b
movq -0x578(%rbp), %rdi
leaq 0xa79c(%rip), %rsi      # 0x54735
callq 0x4380
movq %rax, -0x580(%rbp)
jmp 0x49fa7
movq -0x580(%rbp), %rdi
movq -0x378(%rbp), %rsi
callq 0x40f0
movq %rax, -0x588(%rbp)
jmp 0x49fc3
movq -0x588(%rbp), %rdi
leaq 0xa3a8(%rip), %rsi      # 0x54379
callq 0x4380
movq %rax, -0x590(%rbp)
jmp 0x49fdf
movq -0x590(%rbp), %rdi
movq 0x1bfc3(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x49ff4
jmp 0x49ff6
movq 0x1c393(%rip), %rax     # 0x66390
addq $0x1, %rax
movq %rax, 0x1c388(%rip)     # 0x66390
jmp 0x4a0c4
movq -0x378(%rbp), %rax
cmpq -0x370(%rbp), %rax
jb 0x4a0c2
movq 0x1d448(%rip), %rax     # 0x67470
movq %rax, -0x5a0(%rbp)
leaq 0x1d422(%rip), %rdi     # 0x67458
xorl %eax, %eax
movl %eax, %esi
callq 0x3a790
movq -0x5a0(%rbp), %rdi
movq (%rax), %rsi
callq 0x14b40
movb %al, -0x591(%rbp)
jmp 0x4a056
movb -0x591(%rbp), %al
testb $0x1, %al
jne 0x4a062
jmp 0x4a0c0
movb $0x0, -0x279(%rbp)
leaq 0x1d3e8(%rip), %rdi     # 0x67458
movq %rdi, -0x5b0(%rbp)
callq 0x1b8a0
movq %rax, -0x3a0(%rbp)
leaq -0x398(%rbp), %rdi
leaq -0x3a0(%rbp), %rsi
callq 0x3a820
movq -0x5b0(%rbp), %rdi
movq -0x398(%rbp), %rsi
callq 0x3a7b0
movq %rax, -0x5a8(%rbp)
jmp 0x4a0b2
movq -0x5a8(%rbp), %rax
movq %rax, -0x3a8(%rbp)
jmp 0x4a0c2
jmp 0x4a0c4
movq 0x1d3a5(%rip), %rdi     # 0x67470
callq 0x14ca0
jmp 0x4a0d2
jmp 0x4a0d4
movq -0x378(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x378(%rbp)
jmp 0x49dc5
jmp 0x4a0ed
jmp 0x4a0ef
leaq 0x1d362(%rip), %rdi     # 0x67458
callq 0x3ac80
movq 0x1d36e(%rip), %rax     # 0x67470
movq %rax, -0x5b8(%rbp)
cmpq $0x0, %rax
je 0x4a11c
movq -0x5b8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x1d349(%rip) # 0x67470
movl $0x0, -0x4(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x46e8
leaq -0x258(%rbp), %rdi
callq 0x4110
leaq -0x38(%rbp), %rdi
callq 0x46e8
movl -0x4(%rbp), %eax
addq $0x5c0, %rsp            # imm = 0x5C0
popq %rbp
retq
leaq -0x278(%rbp), %rdi
callq 0x46e8
leaq -0x258(%rbp), %rdi
callq 0x4110
leaq -0x38(%rbp), %rdi
callq 0x46e8
movq -0x48(%rbp), %rdi
callq 0x4630
nopw %cs:(%rax,%rax)
nop