// File: /workspace/github_cpp_makefile_star2_O2/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 $0x6f8, %rsp            # imm = 0x6F8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x4b6d(%rip), %r14      # 0x10713
leaq 0xa613(%rip), %r15      # 0x161c0
leaq 0x4b08(%rip), %r12      # 0x106bc
leaq 0x40(%rsp), %r13
andl $0x0, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
leaq 0x8(%rsp), %r8
callq 0x22c0
movl %eax, 0xa6d7(%rip)      # 0x162b0
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
ja 0xbc04
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq 0xa3c7(%rip), %rax      # 0x15fb8
movq (%rax), %r14
movq %r14, %rdi
callq 0x2260
movl %eax, 0xa5ae(%rip)      # 0x161b0
jmp 0xbc33
testl %eax, %eax
je 0xbc81
cmpl $0x63, %eax
je 0xbc66
cmpl $-0x1, %eax
je 0xbce1
cmpl $0x3f, %eax
jne 0xbbb9
jmp 0xbf18
andl $0x0, 0xa58d(%rip)      # 0x161b4
jmp 0xbbb9
movq 0xa388(%rip), %rax      # 0x15fb8
movq (%rax), %r14
movq %r13, %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq 0xbf54
leaq 0xa68e(%rip), %rdi      # 0x162d8
movq %r13, %rsi
callq 0x21f0
movq %r13, %rdi
callq 0x2318
leaq 0x4ab2(%rip), %r14      # 0x10713
jmp 0xbbb9
movq 0xa34b(%rip), %rax      # 0x15fb8
movq (%rax), %rdi
callq 0x21c0
movq %rax, 0xa53c(%rip)      # 0x161b8
jmp 0xbbb9
movslq 0x8(%rsp), %rax
shlq $0x5, %rax
cmpq $0x0, 0x10(%rax,%r15)
je 0xbca3
leaq 0x4afd(%rip), %rdi      # 0x10796
callq 0x2250
jmp 0xbbb9
addq %r15, %rax
movq (%rax), %rsi
leaq 0x4a6d(%rip), %rdi      # 0x1071d
xorl %eax, %eax
callq 0x2030
movq 0xa2fa(%rip), %rax      # 0x15fb8
movq (%rax), %rsi
testq %rsi, %rsi
je 0xbcd4
leaq 0x4a5a(%rip), %rdi      # 0x10727
xorl %eax, %eax
callq 0x2030
pushq $0xa
popq %rdi
callq 0x2220
jmp 0xbbb9
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x65c0
movl 0xa4bd(%rip), %esi      # 0x161b0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0xbfb8
leaq 0xa84f(%rip), %rdi      # 0x16568
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0xc396
movq %rbx, %rdi
callq 0xbf96
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x5504
movl 0xa46f(%rip), %esi      # 0x161b0
andl $0x0, (%rbx)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0x51aa
leaq 0xa7d9(%rip), %rdi      # 0x16538
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x57f6
movq %rbx, %rdi
callq 0x549c
movl 0xa436(%rip), %esi      # 0x161b0
leaq 0x20(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x51aa
leaq 0xa7b8(%rip), %rdi      # 0x16550
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x57f6
movq %rbx, %rdi
callq 0x549c
movl 0xa3fd(%rip), %esi      # 0x161b0
leaq 0x20(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x51aa
leaq 0xa74f(%rip), %rdi      # 0x16520
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x57f6
movq %rbx, %rdi
callq 0x549c
pushq $0xb
popq %rax
xorl %ecx, %ecx
movq 0xa72e(%rip), %rdx      # 0x16520
movl 0xa3b8(%rip), %esi      # 0x161b0
cmpq %rsi, %rcx
jae 0xbe08
movl %eax, (%rdx,%rcx,4)
incq %rcx
addl $0xb, %eax
jmp 0xbdf2
xorl %ebp, %ebp
leaq 0x40(%rsp), %rbx
leaq 0x491e(%rip), %r15      # 0x10734
leaq 0x4933(%rip), %r12      # 0x10750
cmpq %rbp, 0xa394(%rip)      # 0x161b8
jle 0xbeed
cmpl $0x0, 0xa383(%rip)      # 0x161b4
je 0xbe64
movq 0xa18e(%rip), %rdi      # 0x15fc8
movq %r15, %rsi
callq 0x2180
movq 0xa45f(%rip), %rsi      # 0x162a8
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
movq %r12, %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20b0
xorl %r14d, %r14d
xorl %r13d, %r13d
movl 0xa340(%rip), %eax      # 0x161b0
cmpq %rax, %r13
jae 0xbed6
movq 0xa6ec(%rip), %rcx      # 0x16568
movq (%rcx,%r14), %rax
cmpq %rax, 0x8(%rcx,%r14)
je 0xbeae
movq (%rax), %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x788e
testb %al, %al
je 0xbecd
movq 0xa6c8(%rip), %rdi      # 0x16568
movq (%rdi,%r14), %rsi
addq %r14, %rdi
callq 0x53ca
jmp 0xbecd
movq 0xa683(%rip), %rax      # 0x16538
movl (%rax,%r13,4), %ecx
testl %ecx, %ecx
je 0xbec5
decl %ecx
movl %ecx, (%rax,%r13,4)
jne 0xbecd
movl %r13d, %edi
callq 0xba51
incq %r13
addq $0x18, %r14
jmp 0xbe6a
movq %rbx, %rdi
callq 0x7a3e
incq 0xa3c3(%rip)            # 0x162a8
incq %rbp
jmp 0xbe1d
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x810a
leaq 0x40(%rsp), %rdi
callq 0xc00e
xorl %eax, %eax
addq $0x6f8, %rsp            # imm = 0x6F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xba34
xorl %edi, %edi
callq 0x21d0
jmp 0xbf3f
jmp 0xbf3f
jmp 0xbf3f
jmp 0xbf3f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5504
jmp 0xbf42
jmp 0xbf3f
jmp 0xbf3f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xc00e
movq %rbx, %rdi
callq 0x22f0