// File: /workspace/github_cpp_makefile_star2_O3/dramninjasUMD[P]BOBSim/BOBWrapper.cpp
// Function: BOBSim::BOBWrapper::AddTransaction(BOBSim::Transaction*, unsigned int)
bool BOBWrapper::AddTransaction(Transaction* trans, unsigned port)
{
	if(inFlightRequestCounter[port]==0 &&
	        bob->ports[port].inputBuffer.size()<PORT_QUEUE_DEPTH)
	{
		trans->fullStartTime = currentClockCycle;
		requestCounterPerPort[port]++;

		inFlightRequest[port] = trans;
		inFlightRequest[port]->portID = port;
		inFlightRequest[port]->cyclesReqPort = currentClockCycle;

		inFlightRequestHeaderCounter[port] = 1;

		switch(trans->transactionType)
		{
		case DATA_READ:
			readsPerPort[port]++;
			inFlightRequestCounter[port] = 1;
			break;
		case DATA_WRITE:
			issuedWrites++;
			writesPerPort[port]++;
			inFlightRequestCounter[port] = TRANSACTION_SIZE / PORT_WIDTH;
			break;
		case LOGIC_OPERATION:
			issuedLogicOperations++;
			inFlightRequestCounter[port] = TRANSACTION_SIZE / PORT_WIDTH;
			break;
		default:
			ERROR(" = Error - wrong type");
			ERROR(trans);
			break;
		}

		if(DEBUG_PORTS) DEBUG(" = Putting transaction on port "<<port<<" - "<<*inFlightRequest[port]<<" for "<<inFlightRequestCounter[port]<<" CPU cycles");

		return true;
	}
	else
	{
		if(DEBUG_PORTS) DEBUG(" = Port Busy or Full");

		return false; //port busy
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %eax
movq 0x30(%rdi), %rcx
cmpl $0x0, (%rcx,%rax,4)
jne 0x9f3f
movq %rsi, %rbx
movq 0x10(%rdi), %rcx
movq 0x10(%rcx), %rcx
movq %rax, %rsi
shlq $0x6, %rsi
movq 0x18(%rcx,%rsi), %r8
subq 0x10(%rcx,%rsi), %r8
cmpq $0x3f, %r8
ja 0x9f3f
movq 0x8(%rdi), %rcx
movq %rcx, 0x60(%rbx)
movq 0xf8(%rdi), %rsi
incl (%rsi,%rax,4)
movq 0x18(%rdi), %rsi
movq %rbx, (%rsi,%rax,8)
movq 0x18(%rdi), %rsi
movq (%rsi,%rax,8), %rsi
movl %edx, 0x1c(%rsi)
movq %rcx, 0x38(%rsi)
movq 0x48(%rdi), %rcx
movl $0x1, (%rcx,%rax,4)
movl (%rbx), %ecx
cmpl $0x3, %ecx
je 0x9f62
cmpl $0x1, %ecx
je 0x9f50
testl %ecx, %ecx
jne 0x9f78
movq 0x110(%rdi), %rcx
incl (%rcx,%rax,4)
movq 0x30(%rdi), %rcx
movl $0x1, (%rcx,%rax,4)
jmp 0xa0ac
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl 0x290(%rdi)
movq 0x128(%rdi), %rcx
incl (%rcx,%rax,4)
jmp 0x9f68
incl 0x28c(%rdi)
movq 0x30(%rdi), %rcx
movl $0x4, (%rcx,%rax,4)
jmp 0xa0ac
movq 0xf071(%rip), %r14      # 0x18ff0
leaq 0x9242(%rip), %rsi      # 0x131c8
movl $0x8, %edx
movq %r14, %rdi
callq 0x3200
leaq 0x9ca3(%rip), %r12      # 0x13c3d
movl $0xe, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3200
leaq 0x91c0(%rip), %r13      # 0x13171
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3200
movq %r14, %rdi
movl $0x14b, %esi            # imm = 0x14B
callq 0x3330
movq %rax, %r15
leaq 0x9201(%rip), %rbp      # 0x131d9
movl $0x4, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
leaq 0x9c9a(%rip), %rsi      # 0x13c89
movl $0x15, %edx
movq %r15, %rdi
callq 0x3200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movl $0x8, %edx
movq %r14, %rdi
leaq 0x9196(%rip), %rsi      # 0x131c8
callq 0x3200
movl $0xe, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3200
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3200
movq %r14, %rdi
movl $0x14c, %esi            # imm = 0x14C
callq 0x3330
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movb $0x1, %al
jmp 0x9f41
nop