// File: /workspace/github_cpp_makefile_star2_O1/sopanpatra160[P]OOO_Superscalar_Processor_Simulator/main.cc
// Function: Dispatch(unsigned int, unsigned int)
void Dispatch(unsigned int s,unsigned int n)
{

	vector<instruction>     temp_dispatch_list;
  	unsigned int		dispatch_count=0;

	for (vector<instruction>::iterator it = dispatch_list.begin() ; it != dispatch_list.end(); ++it)
	{
		if(it->state == ID)
		{
			temp_dispatch_list.push_back(*it);			
		}
	}

	for (vector<instruction>::iterator it = temp_dispatch_list.begin() ; it != temp_dispatch_list.end(); ++it)
        {
                if(issue_list.size() < s && dispatch_count < n)
                {
			
			dispatch_count ++;
			it->state=IS;
			if(it->src1_regno_new != -1)
			{
				if(rdy[it->src1_regno_new])
				{
					it->src1_ready=1;
				}
				else
				{
					it->src1_ready=0;
					it->src1_regno_new=new_name[it->src1_regno];
				}
			}
			else
			{
                                it->src1_ready=1;
	
			}
			

			if(it->src2_regno_new != -1)
			{
				if(rdy[it->src2_regno_new])

                        	{
                                	it->src2_ready=1;
                        	}
                        	else
                        	{
                                	it->src2_ready=0;
					it->src2_regno_new=new_name[it->src2_regno];
                        	}
		
			}
			else
			{
                                it->src2_ready=1;
	
			}

			if (it->dest_regno != -1) 
			{
				rdy[it->dest_regno]=0;
				new_name[it->dest_regno] = it->tag;
			}
			it->id_duration = cycles - it->id_begin_cycle;
			it->is_begin_cycle = cycles;
			
			issue_list.push_back(*it);
			//temp_dispatch_list.remove(*it);
			dispatch_list.erase(dispatch_list.begin());
		}
	}
	for (vector<instruction>::iterator it = dispatch_list.begin() ; it != dispatch_list.end(); ++it)
	{
		if(it->state == IF)
		{
			it->state = ID;
			it->if_duration = cycles - it->if_begin_cycle;
			it->id_begin_cycle = cycles;
		}
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movl %edi, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x35b0(%rip), %r14      # 0x63a8
cmpq 0x35b1(%rip), %r14      # 0x63b0
je 0x2e4a
movq %rsp, %r15
cmpl $0x1, 0x4c(%r14)
jne 0x2e3d
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x2e2f
movl $0x16, %ecx
movq %rax, %rdi
movq %r14, %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x58, %rax
movq %rax, 0x8(%rsp)
jmp 0x2e3d
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x3b0c
addq $0x58, %r14
cmpq 0x3568(%rip), %r14      # 0x63b0
jne 0x2e04
movq (%rsp), %r14
cmpq 0x8(%rsp), %r14
je 0x2fa2
movl %ebp, %r12d
xorl %ebp, %ebp
movabsq $0x2e8ba2e8ba2e8ba3, %r13 # imm = 0x2E8BA2E8BA2E8BA3
leaq 0x3481(%rip), %r15      # 0x62f0
movq 0x3552(%rip), %rax      # 0x63c8
movq %rax, %rcx
subq 0x3540(%rip), %rcx      # 0x63c0
sarq $0x3, %rcx
imulq %r13, %rcx
cmpq %r12, %rcx
setb %cl
cmpl %ebx, %ebp
setb %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2f93
movl $0x2, 0x4c(%r14)
movslq 0x14(%r14), %rcx
cmpq $-0x1, %rcx
je 0x2eb7
cmpb $0x1, (%rcx,%r15)
jne 0x2ebe
movb $0x1, 0x4(%r14)
jmp 0x2ed5
movb $0x0, 0x4(%r14)
movslq 0xc(%r14), %rcx
leaq 0x3222(%rip), %rdx      # 0x60f0
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x14(%r14)
movslq 0x18(%r14), %rcx
cmpq $-0x1, %rcx
je 0x2ee6
cmpb $0x1, (%rcx,%r15)
jne 0x2eed
movb $0x1, 0x5(%r14)
jmp 0x2f04
movb $0x0, 0x5(%r14)
movslq 0x10(%r14), %rcx
leaq 0x31f3(%rip), %rdx      # 0x60f0
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x18(%r14)
movslq 0x8(%r14), %rcx
cmpq $-0x1, %rcx
je 0x2f21
movb $0x0, (%rcx,%r15)
movl 0x50(%r14), %edx
leaq 0x31d2(%rip), %rsi      # 0x60f0
movl %edx, (%rsi,%rcx,4)
movl 0x31c1(%rip), %ecx      # 0x60e8
movl %ecx, %edx
subl 0x24(%r14), %edx
movl %edx, 0x28(%r14)
movl %ecx, 0x2c(%r14)
cmpq 0x3494(%rip), %rax      # 0x63d0
je 0x2f58
movl $0x16, %ecx
movq %rax, %rdi
movq %r14, %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x58, %rax
movq %rax, 0x3472(%rip)      # 0x63c8
jmp 0x2f6a
leaq 0x3461(%rip), %rdi      # 0x63c0
movq %rax, %rsi
movq %r14, %rdx
callq 0x3b0c
movq 0x3437(%rip), %rdi      # 0x63a8
leaq 0x58(%rdi), %rsi
movq 0x3434(%rip), %rdx      # 0x63b0
cmpq %rdx, %rsi
je 0x2f89
subq %rsi, %rdx
callq 0x1130
incl %ebp
addq $-0x58, 0x341d(%rip)    # 0x63b0
addq $0x58, %r14
cmpq 0x8(%rsp), %r14
jne 0x2e6f
movq 0x33ff(%rip), %rax      # 0x63a8
movq 0x3400(%rip), %rcx      # 0x63b0
cmpq %rcx, %rax
je 0x2fdc
movl 0x312d(%rip), %edx      # 0x60e8
cmpl $0x0, 0x4c(%rax)
jne 0x2fd3
movl $0x1, 0x4c(%rax)
movl %edx, %esi
subl 0x1c(%rax), %esi
movl %esi, 0x20(%rax)
movl %edx, 0x24(%rax)
addq $0x58, %rax
cmpq %rcx, %rax
jne 0x2fbb
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2ff2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3003
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x301c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1140