// File: /workspace/github_cpp_makefile_star2_O3/dramninjasUMD[P]BOBSim/RandomStreamSim.cpp
// Function: main
int main(int argc, char **argv)
{
	while (1)
	{
		static struct option long_options[] =
		{
			{"pwd", required_argument, 0, 'p'},
			{"numcycles",  required_argument,	0, 'c'},
			{"quiet",  no_argument, &BOBSim::SHOW_SIM_OUTPUT, 'q'},
			{"help", no_argument, 0, 'h'},
			{0, 0, 0, 0}
		};
		int option_index=0; //for getopt
		c = getopt_long (argc, argv, "c:n:p:bkq", long_options, &option_index);
		if (c == -1)
		{
			break;
		}
		switch (c)
		{
		case 0: //TODO: figure out what the hell this does, cuz it never seems to get called
			if (long_options[option_index].flag != 0) //do nothing on a flag
			{
				printf("setting flag\n");
				break;
			}
			printf("option %s",long_options[option_index].name);
			if (optarg)
			{
				printf(" with arg %s", optarg);
			}
			printf("\n");
			break;
		case 'h':
		case '?':
			usage();
			exit(0);
			break;
		case 'c':
			numCycles = atol(optarg);
			break;
		case 'n':
			BOBSim::NUM_PORTS = atoi(optarg);
		case 'p':
			pwdString = string(optarg);
			break;
		case 'q':
			BOBSim::SHOW_SIM_OUTPUT=0;
			break;
		}
	}

	//open up verification file
	if(VERIFICATION_OUTPUT)
	{
		verificationOutput.open("sim_out_DDR3_micron_64M_8B_x4_sg187E.ini.tmp");
	}

	BOBWrapper bobWrapper(0);
	transactionBuffer = vector< vector<Transaction *> >(NUM_PORTS,vector<Transaction *>());

	waitCounters = vector<unsigned>(NUM_PORTS,0);
	useCounters = vector<unsigned>(NUM_PORTS,0);

	randomSeeds = vector<unsigned>(NUM_PORTS,0);
	for(unsigned i=0; i<NUM_PORTS; i++)
	{
		randomSeeds[i]=i*SEED_CONSTANT + SEED_CONSTANT;
	}

	//iterate over total number of cycles
	//  "main loop"
	//   numCycles is the number of CPU cycles to simulate
	for (int cpuCycle=0; cpuCycle<numCycles; cpuCycle++)
	{
		DEBUG("\n=========================["<<currentClockCycle<<"]==========================");

		//adding new stuff
		for(unsigned l=0; l<NUM_PORTS; l++)
		{
			if(transactionBuffer[l].size()>0)
			{
				if(DEBUG_PORTS) DEBUG("== TraceBasedSim trying to send : port "<<l<<" : "<<*transactionBuffer[l][0]);

				if(bobWrapper.AddTransaction(transactionBuffer[l][0],l))
				{
					transactionBuffer[l].erase(transactionBuffer[l].begin());
				}
			}
			else
			{
				if(waitCounters[l]>0) waitCounters[l]--;

				//make sure we are not waiting during idle time
				if(waitCounters[l]==0)
				{
					FillTransactionBuffer(l);
				}
			}
		}


		//
		//Update bobWrapper
		//
		bobWrapper.Update();
		currentClockCycle++;
	}

	//
	//Debug output
	//
	bobWrapper.PrintStats(true);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x718, %rsp            # imm = 0x718
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x5908(%rip), %r14      # 0x147a3
leaq 0xa33e(%rip), %r15      # 0x191e0
movq %rsp, %r12
movl $0x0, (%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x3310
movl %eax, 0xa40b(%rip)      # 0x192d0
cmpl $0x62, %eax
jle 0xeefc
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
ja 0xef22
leaq 0x5873(%rip), %rdx      # 0x1474c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0xa0c7(%rip), %rax      # 0x18fb0
movq (%rax), %r13
movq %r13, %rdi
callq 0x32b0
movl %eax, 0xa2d6(%rip)      # 0x191d0
jmp 0xef76
testl %eax, %eax
jne 0xef46
movslq (%rsp), %rax
shlq $0x5, %rax
cmpq $0x0, 0x10(%rax,%r15)
je 0xefc2
leaq 0x590b(%rip), %rdi      # 0x14826
callq 0x32a0
jmp 0xeea5
cmpl $0x63, %eax
jne 0xeea5
movq 0xa07e(%rip), %rax      # 0x18fb0
movq (%rax), %rdi
callq 0x3210
movq %rax, 0xa297(%rip)      # 0x191d8
jmp 0xeea5
cmpl $-0x1, %eax
je 0xf002
cmpl $0x3f, %eax
jne 0xeea5
jmp 0xf398
movl $0x0, 0xa26d(%rip)      # 0x191d4
jmp 0xeea5
movq 0xa03d(%rip), %rax      # 0x18fb0
movq (%rax), %r13
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x40(%rsp), %rdx
callq 0xf3e0
leaq 0xa366(%rip), %rdi      # 0x192f8
movq %r14, %rsi
callq 0x3240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xefb6
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x31f0
leaq 0x57e6(%rip), %r14      # 0x147a3
jmp 0xeea5
addq %r15, %rax
movq (%rax), %rsi
leaq 0x57de(%rip), %rdi      # 0x147ad
xorl %eax, %eax
callq 0x3040
movq 0x9fd3(%rip), %rax      # 0x18fb0
movq (%rax), %rsi
testq %rsi, %rsi
je 0xeff3
leaq 0x57cb(%rip), %rdi      # 0x147b7
xorl %eax, %eax
callq 0x3040
movl $0xa, %edi
callq 0x3270
jmp 0xeea5
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x7c6c
movl 0xa1bc(%rip), %esi      # 0x191d0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x40(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0xf48a
movq 0xa573(%rip), %rax      # 0x195b0
leaq 0x40(%rsp), %rbx
movaps (%rbx), %xmm0
movq 0x10(%rbx), %rcx
movq %rcx, 0xa560(%rip)      # 0x195b0
movaps 0xa549(%rip), %xmm1     # 0x195a0
movaps %xmm0, 0xa542(%rip)     # 0x195a0
movq %rsp, %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0xf436
movq %rbx, %rdi
callq 0xf436
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf09a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0xa130(%rip), %esi      # 0x191d0
leaq 0x40(%rsp), %rdx
movl $0x0, (%rdx)
movq %rsp, %rdi
leaq 0x20(%rsp), %rcx
callq 0x6d56
movq 0xa4a1(%rip), %rdi      # 0x19560
movq 0xa4aa(%rip), %rsi      # 0x19570
movaps (%rsp), %xmm0
movaps %xmm0, 0xa48f(%rip)     # 0x19560
movq 0x10(%rsp), %rax
movq %rax, 0xa493(%rip)      # 0x19570
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0xf110
subq %rdi, %rsi
callq 0x31f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xf110
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0xa0ba(%rip), %esi      # 0x191d0
leaq 0x40(%rsp), %rdx
movl $0x0, (%rdx)
movq %rsp, %rdi
leaq 0x20(%rsp), %rcx
callq 0x6d56
movq 0xa44b(%rip), %rdi      # 0x19580
movq 0xa454(%rip), %rsi      # 0x19590
movaps (%rsp), %xmm0
movaps %xmm0, 0xa439(%rip)     # 0x19580
movq 0x10(%rsp), %rax
movq %rax, 0xa43d(%rip)      # 0x19590
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0xf186
subq %rdi, %rsi
callq 0x31f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xf186
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0xa044(%rip), %esi      # 0x191d0
leaq 0x40(%rsp), %rdx
movl $0x0, (%rdx)
movq %rsp, %rdi
leaq 0x20(%rsp), %rcx
callq 0x6d56
movq 0xa395(%rip), %rdi      # 0x19540
movq 0xa39e(%rip), %rsi      # 0x19550
movaps (%rsp), %xmm0
movaps %xmm0, 0xa383(%rip)     # 0x19540
movq 0x10(%rsp), %rax
movq %rax, 0xa387(%rip)      # 0x19550
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0xf1fc
subq %rdi, %rsi
callq 0x31f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xf1fc
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
cmpl $0x0, 0x9fcd(%rip)      # 0x191d0
je 0xf227
movl $0xb, %eax
movq 0xa32f(%rip), %rcx      # 0x19540
xorl %edx, %edx
movl %eax, (%rcx,%rdx,4)
incq %rdx
movl 0x9fb1(%rip), %esi      # 0x191d0
addl $0xb, %eax
cmpq %rsi, %rdx
jb 0xf213
cmpq $0x0, 0x9fa9(%rip)      # 0x191d8
jle 0xf36b
xorl %ebp, %ebp
leaq 0x60(%rsp), %rbx
movq 0x9d85(%rip), %r14      # 0x18fc8
cmpl $0x0, 0x9f8a(%rip)      # 0x191d4
je 0xf2ae
movl $0x1b, %edx
movq %r14, %rdi
leaq 0x5569(%rip), %rsi      # 0x147c4
callq 0x3200
movq 0xa061(%rip), %rsi      # 0x192c8
movq %r14, %rdi
callq 0x3120
movq %rax, %r13
movl $0x1b, %edx
movq %rax, %rdi
leaq 0x555f(%rip), %rsi      # 0x147e0
callq 0x3200
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
cmpl $0x0, 0x9f1b(%rip)      # 0x191d0
je 0xf34c
movl $0x2, %r15d
xorl %r13d, %r13d
movq 0xa2d5(%rip), %rcx      # 0x195a0
movq -0x8(%rcx,%r15,4), %rax
cmpq %rax, (%rcx,%r15,4)
je 0xf317
movq (%rax), %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x9ea4
testb %al, %al
je 0xf336
movq 0xa2b1(%rip), %r12      # 0x195a0
movq -0x8(%r12,%r15,4), %rdi
movq (%r12,%r15,4), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0xf30d
subq %rsi, %rdx
callq 0x32f0
movq (%r12,%r15,4), %rdx
addq $-0x8, %rdx
movq %rdx, (%r12,%r15,4)
jmp 0xf336
movq 0xa242(%rip), %rax      # 0x19560
movl (%rax,%r13,4), %ecx
testl %ecx, %ecx
je 0xf32e
decl %ecx
movl %ecx, (%rax,%r13,4)
jne 0xf336
movl %r13d, %edi
callq 0xecf8
incq %r13
movl 0x9e91(%rip), %eax      # 0x191d0
addq $0x6, %r15
cmpq %rax, %r13
jb 0xf2c4
movq %rbx, %rdi
callq 0xa0ca
incq 0x9f6d(%rip)            # 0x192c8
incq %rbp
cmpq %rbp, 0x9e73(%rip)      # 0x191d8
jg 0xf243
leaq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0xa978
leaq 0x60(%rsp), %rdi
callq 0xf522
xorl %eax, %eax
addq $0x718, %rsp            # imm = 0x718
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xecb4
xorl %edi, %edi
callq 0x3220
jmp 0xf3ca
jmp 0xf3ca
jmp 0xf3ca
jmp 0xf3ca
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf3cd
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
jmp 0xf3cd
jmp 0xf3ca
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xf522
movq %rbx, %rdi
callq 0x3340
nop