// File: /workspace/github_cpp_makefile_star2_O3/dramninjasUMD[P]BOBSim/RandomStreamSim.cpp
// Function: FillTransactionBuffer(int)
void FillTransactionBuffer(int port)
{
	useCounters[port] = 0;

	//Fill with a random number of requests between 2 and 5 or 6
	unsigned randomCount = rand_r(&randomSeeds[port]) % 5 + 2;
	//cout<<"port "<<port<<" - random count is "<<randomCount<<endl;
	for(unsigned i=0; i<randomCount; i++)
	{
		unsigned long temp = rand();
		unsigned long physicalAddress = (temp<<32)|rand_r(&randomSeeds[port]);
		Transaction *newTrans;
		
		if(physicalAddress%1000<READ_WRITE_RATIO*10)
		{
			newTrans = new Transaction(DATA_READ,TRANSACTION_SIZE,physicalAddress);
			//cout<<*newTrans<<endl;
			useCounters[port]+= RD_REQUEST_PACKET_OVERHEAD/PORT_WIDTH+!!(RD_REQUEST_PACKET_OVERHEAD%PORT_WIDTH);
		}
		else
		{
			newTrans = new Transaction(DATA_WRITE,TRANSACTION_SIZE,physicalAddress);
			//cout<<*newTrans<<endl;
			useCounters[port]+=(WR_REQUEST_PACKET_OVERHEAD + TRANSACTION_SIZE)/PORT_WIDTH +
				!!((WR_REQUEST_PACKET_OVERHEAD + TRANSACTION_SIZE)%PORT_WIDTH);
		}
		
		transactionBuffer[port].push_back(newTrans);
	}
	
	//cout<<"use for "<<port<<" is "<<useCounters[port]<<endl;
	//figure out how much idle time between requests
	waitCounters[port] = ceil(useCounters[port]/PORT_UTILIZATION) - useCounters[port];
	//cout<<"wait for "<<port<<" is "<<waitCounters[port]<<endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq %edi, %r12
movq 0xa870(%rip), %rax      # 0x19580
leaq (,%r12,4), %rcx
movl $0x0, (%rax,%r12,4)
movq 0xa819(%rip), %rdi      # 0x19540
movq %rcx, 0x8(%rsp)
addq %rcx, %rdi
callq 0x31e0
movslq %eax, %rbp
imulq $0x66666667, %rbp, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
leal (%rax,%rax,4), %eax
subl %eax, %ebp
addl $0x2, %ebp
je 0xee31
leaq (%r12,%r12,2), %rbx
callq 0x3070
movl %eax, %r14d
shlq $0x20, %r14
movq 0xa7d0(%rip), %rdi      # 0x19540
addq 0x8(%rsp), %rdi
callq 0x31e0
movslq %eax, %r15
orq %r14, %r15
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
movq %r15, %r13
subq %rax, %r13
movl $0x90, %edi
callq 0x31d0
movq %rax, %r14
cmpq $0x299, %r13            # imm = 0x299
ja 0xedd5
movl $0x1, %r13d
movq %r14, %rdi
xorl %esi, %esi
movl $0x40, %edx
movq %r15, %rcx
callq 0x122bc
jmp 0xedf0
movl $0x5, %r13d
movq %r14, %rdi
movl $0x1, %esi
movl $0x40, %edx
movq %r15, %rcx
callq 0x122bc
movq %r14, 0x10(%rsp)
movq 0xa784(%rip), %rax      # 0x19580
addl %r13d, (%rax,%r12,4)
movq 0xa799(%rip), %rax      # 0x195a0
leaq (%rax,%rbx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xee1f
movq %r14, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xee29
leaq 0x10(%rsp), %rdx
callq 0x7b4c
decl %ebp
jne 0xed5d
movq 0xa748(%rip), %rax      # 0x19580
movl (%rax,%r12,4), %eax
cvtsi2ss %rax, %xmm0
subss %xmm0, %xmm0
cvttss2si %xmm0, %rax
movq 0xa70f(%rip), %rcx      # 0x19560
movl %eax, (%rcx,%r12,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xee66
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3340