// File: /workspace/github_cpp_makefile_star2_O1/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 0x565b(%rip), %r14      # 0x14703
leaq 0xa131(%rip), %r15      # 0x191e0
leaq 0x10(%rsp), %r12
movl $0x0, 0x10(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x3310
movl %eax, 0xa1fb(%rip)      # 0x192d0
cmpl $0x62, %eax
jle 0xf15f
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
ja 0xf185
leaq 0x55bb(%rip), %rdx      # 0x146ac
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x9eaf(%rip), %rax      # 0x18fb0
movq (%rax), %rdi
callq 0x32b0
movl %eax, 0xa0c1(%rip)      # 0x191d0
movq 0x9e9a(%rip), %rax      # 0x18fb0
movq (%rax), %rsi
leaq 0x60(%rsp), %r13
movq %r13, %rdi
leaq 0x48(%rsp), %rdx
callq 0xf568
leaq 0xa1c6(%rip), %rdi      # 0x192f8
movq %r13, %rsi
callq 0x3240
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xf0b4
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0xf0b4
testl %eax, %eax
jne 0xf1a9
movslq 0x10(%rsp), %rax
shlq $0x5, %rax
cmpq $0x0, 0x10(%rax,%r15)
je 0xf1cb
leaq 0x560b(%rip), %rdi      # 0x14786
callq 0x32a0
jmp 0xf0b4
cmpl $0x63, %eax
jne 0xf0b4
movq 0x9e1b(%rip), %rax      # 0x18fb0
movq (%rax), %rdi
callq 0x3210
movq %rax, 0xa034(%rip)      # 0x191d8
jmp 0xf0b4
cmpl $-0x1, %eax
je 0xf20b
cmpl $0x3f, %eax
jne 0xf0b4
jmp 0xf520
movl $0x0, 0xa00e(%rip)      # 0x191d4
jmp 0xf0b4
addq %r15, %rax
movq (%rax), %rsi
leaq 0x5535(%rip), %rdi      # 0x1470d
xorl %eax, %eax
callq 0x3040
movq 0x9dca(%rip), %rax      # 0x18fb0
movq (%rax), %rsi
testq %rsi, %rsi
je 0xf1fc
leaq 0x5522(%rip), %rdi      # 0x14717
xorl %eax, %eax
callq 0x3040
movl $0xa, %edi
callq 0x3270
jmp 0xf0b4
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x7f78
movl 0x9fb3(%rip), %esi      # 0x191d0
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0xf60c
leaq 0x10(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movups 0xa337(%rip), %xmm0     # 0x19588
movq 0xa340(%rip), %rax      # 0x19598
leaq 0x48(%rsp), %rbx
movups (%rbx), %xmm1
movups %xmm1, 0xa321(%rip)     # 0x19588
movq 0x10(%rbx), %rcx
movq %rcx, 0xa326(%rip)      # 0x19598
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0xf5be
movq %rbx, %rdi
callq 0xf5be
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xf2ab
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0x9f1f(%rip), %esi      # 0x191d0
leaq 0x48(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rcx
callq 0x6f9c
leaq 0xa286(%rip), %rdi      # 0x19558
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x7422
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xf2f4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0x9ed6(%rip), %esi      # 0x191d0
leaq 0x48(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rcx
callq 0x6f9c
leaq 0xa255(%rip), %rdi      # 0x19570
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x7422
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xf33d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movl 0x9e8d(%rip), %esi      # 0x191d0
leaq 0x48(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rcx
callq 0x6f9c
leaq 0xa1dc(%rip), %rdi      # 0x19540
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x7422
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xf386
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
cmpl $0x0, 0x9e43(%rip)      # 0x191d0
je 0xf3b1
movl $0xb, %eax
movq 0xa1a5(%rip), %rcx      # 0x19540
xorl %edx, %edx
movl %eax, (%rcx,%rdx,4)
incq %rdx
movl 0x9e27(%rip), %esi      # 0x191d0
addl $0xb, %eax
cmpq %rsi, %rdx
jb 0xf39d
cmpq $0x0, 0x9e1f(%rip)      # 0x191d8
jle 0xf4f3
xorl %ebp, %ebp
leaq 0x60(%rsp), %rbx
movq 0x9bfb(%rip), %r14      # 0x18fc8
cmpl $0x0, 0x9e00(%rip)      # 0x191d4
je 0xf438
movl $0x1b, %edx
movq %r14, %rdi
leaq 0x533f(%rip), %rsi      # 0x14724
callq 0x3200
movq 0x9ed7(%rip), %rsi      # 0x192c8
movq %r14, %rdi
callq 0x3120
movq %rax, %r13
movl $0x1b, %edx
movq %rax, %rdi
leaq 0x5335(%rip), %rsi      # 0x14740
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, 0x9d91(%rip)      # 0x191d0
je 0xf4d4
movl $0x2, %r15d
xorl %r13d, %r13d
movq 0xa133(%rip), %rcx      # 0x19588
movq -0x8(%rcx,%r15,4), %rax
cmpq %rax, (%rcx,%r15,4)
je 0xf49a
movq (%rax), %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0xa178
testb %al, %al
je 0xf4be
movq 0xa10f(%rip), %r12      # 0x19588
movq -0x8(%r12,%r15,4), %rdi
movq (%r12,%r15,4), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0xf493
subq %rsi, %rdx
callq 0x32f0
addq $-0x8, (%r12,%r15,4)
jmp 0xf4be
movq 0xa0b7(%rip), %rax      # 0x19558
movl (%rax,%r13,4), %ecx
testl %ecx, %ecx
je 0xf4af
decl %ecx
movl %ecx, (%rax,%r13,4)
cmpl $0x0, (%rax,%r13,4)
jne 0xf4be
movl %r13d, %edi
callq 0xef00
incq %r13
movl 0x9d09(%rip), %eax      # 0x191d0
addq $0x6, %r15
cmpq %rax, %r13
jb 0xf44e
movq %rbx, %rdi
callq 0xa39e
incq 0x9de5(%rip)            # 0x192c8
incq %rbp
cmpq %rbp, 0x9ceb(%rip)      # 0x191d8
jg 0xf3cd
leaq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0xac06
leaq 0x60(%rsp), %rdi
callq 0xf6a4
xorl %eax, %eax
addq $0x718, %rsp            # imm = 0x718
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xeebc
xorl %edi, %edi
callq 0x3220
jmp 0xf552
jmp 0xf552
jmp 0xf552
jmp 0xf552
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xf555
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
jmp 0xf555
jmp 0xf552
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xf6a4
movq %rbx, %rdi
callq 0x3340
nop