// File: /workspace/github_cpp_makefile_star2_O1/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 0xa658(%rip), %rax      # 0x19570
leaq (,%r12,4), %rcx
movl $0x0, (%rax,%r12,4)
movq 0xa611(%rip), %rdi      # 0x19540
movq %rcx, 0x10(%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 0xf03e
leaq (%r12,%r12,2), %rbx
callq 0x3070
movl %eax, %r14d
shlq $0x20, %r14
movq 0xa5c8(%rip), %rdi      # 0x19540
addq 0x10(%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 0xefdd
movl $0x1, %r13d
movq %r14, %rdi
xorl %esi, %esi
movl $0x40, %edx
movq %r15, %rcx
callq 0x123f0
jmp 0xeff8
movl $0x5, %r13d
movq %r14, %rdi
movl $0x1, %esi
movl $0x40, %edx
movq %r15, %rcx
callq 0x123f0
movq %r14, 0x8(%rsp)
movq 0xa56c(%rip), %rax      # 0x19570
addl %r13d, (%rax,%r12,4)
movq 0xa579(%rip), %rax      # 0x19588
leaq (%rax,%rbx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf02c
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xf036
leaq 0x8(%rsp), %rdx
callq 0x7e56
decl %ebp
jne 0xef65
movq 0xa52b(%rip), %rax      # 0x19570
movl (%rax,%r12,4), %eax
cvtsi2ss %rax, %xmm0
subss %xmm0, %xmm0
cvttss2si %xmm0, %rax
movq 0xa4fa(%rip), %rcx      # 0x19558
movl %eax, (%rcx,%r12,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf073
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3340