// File: /workspace/github_cpp_makefile_star2_O1/sopanpatra160[P]OOO_Superscalar_Processor_Simulator/main.cc
// Function: main
int main(int argc, char *argv[]) {

        char *tracefile;
	FILE *file;
	tag_num=0;
	cycles=0;
	//-------------RMT-----------------

	for(unsigned int i=0; i<127; i++)
	{
		rdy[i] = 1;
		new_name[i] = i;
	}
	//---------------------------------


 	s         = atoi (argv[1]);
        n         = atoi (argv[2]);
        blocksize = atoi (argv[3]);
	l1size	  = atoi (argv[4]);
	l1assoc	  = atoi (argv[5]);
	l2size	  = atoi (argv[6]);
	l2assoc	  = atoi (argv[7]);
	tracefile = 	  argv[8] ;


	cache l1(blocksize,l1size,l1assoc,2,0,1);      
	cache l2(blocksize,l2size,l2assoc,2,0,2);              
	cache v(4,0,0,2,0,0);               

	if(l2size!=0){
                l1.next = &l2;
                l2.next = NULL;

        }
        else{
                l1.next = NULL;
	}
	l1.vptr=NULL;
	v.next=NULL;
        

         file = fopen (tracefile,"r");

	//printf("level now= %d %d %d\n",l1.lev,l2.lev,v.lev);
	 while(Advance_Cycle(file))
	 {
         	FakeRetire();
         	Execute(&l1,&l2,&v);
         	Issue(n);
         	Dispatch(s,n);
		Fetch(file,n);
		cycles = cycles + 1;	
	 }
	fclose(file);


	if(l1size!=0){
		printf("L1 CACHE CONTENTS\n");
		printf("a. number of accesses :%d\n",l1.num_r);
		printf("b. number of misses :%d\n",l1.num_miss_r);
		l1.print_tag_store();
	}
	

	if(l2size!=0){
		printf("L2 CACHE CONTENTS\n");
		printf("a. number of accesses :%d\n",l2.num_r);
		printf("b. number of misses :%d\n",l2.num_miss_r);
		l2.print_tag_store();
	}
	if(l1size!=0) {printf("\n");}

	printf ("CONFIGURATION\n");
        printf (" superscalar bandwidth (N) = %d\n",n );
        printf (" dispatch queue size (2*N) = %d\n", 2*n);
        printf (" schedule queue size (S)   = %d\n", s);
        printf ("RESULTS\n");
        printf (" number of instructions = %d\n", tag_num);
        printf (" number of cycles       = %d\n", cycles-1);
        printf (" IPC                    = %0.2f\n", float(tag_num)/float(cycles-1));

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
xorl %eax, %eax
movl %eax, 0x2955(%rip)      # 0x60e4
movl %eax, 0x2953(%rip)      # 0x60e8
movaps 0xa74(%rip), %xmm0      # 0x4210
movaps %xmm0, 0x2b4d(%rip)     # 0x62f0
movaps %xmm0, 0x2b56(%rip)     # 0x6300
movaps %xmm0, 0x2b5f(%rip)     # 0x6310
movaps %xmm0, 0x2b68(%rip)     # 0x6320
movaps %xmm0, 0x2b71(%rip)     # 0x6330
movaps %xmm0, 0x2b7a(%rip)     # 0x6340
movaps %xmm0, 0x2b83(%rip)     # 0x6350
movups %xmm0, 0x2b8b(%rip)     # 0x635f
leaq 0x2915(%rip), %rcx      # 0x60f0
movl %eax, (%rcx)
incq %rax
addq $0x4, %rcx
cmpq $0x7f, %rax
jne 0x37db
movq 0x8(%rbx), %rdi
callq 0x1120
movl %eax, 0x2b7b(%rip)      # 0x6374
movq 0x10(%rbx), %rdi
callq 0x1120
movl %eax, 0x2b68(%rip)      # 0x6370
movq 0x18(%rbx), %rdi
callq 0x1120
movl %eax, %ebp
movl %eax, 0x2b5f(%rip)      # 0x6378
movq 0x20(%rbx), %rdi
callq 0x1120
movl %eax, %r14d
movl %eax, 0x2b51(%rip)      # 0x637c
movq 0x28(%rbx), %rdi
callq 0x1120
movl %eax, %r15d
movl %eax, 0x2b43(%rip)      # 0x6380
movq 0x30(%rbx), %rdi
callq 0x1120
movl %eax, 0x2b38(%rip)      # 0x6384
movq 0x38(%rbx), %rdi
callq 0x1120
movl %eax, 0x2b2d(%rip)      # 0x6388
movq 0x40(%rbx), %rbx
movq %rsp, %rdi
movsd 0x79e(%rip), %xmm0      # 0x4008
movl %ebp, %esi
movl %r14d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x138c
movl 0x2af2(%rip), %esi      # 0x6378
movl 0x2af8(%rip), %edx      # 0x6384
movl 0x2af6(%rip), %ecx      # 0x6388
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movsd 0x763(%rip), %xmm0      # 0x4008
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x138c
leaq 0x150(%rsp), %rdi
movl $0x4, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movsd 0x73c(%rip), %xmm0      # 0x4008
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x138c
cmpl $0x0, 0x2aa6(%rip)      # 0x6384
je 0x38f2
movq %r14, (%rsp)
movq $0x0, 0xa8(%rsp)
jmp 0x38fa
movq $0x0, (%rsp)
xorl %eax, %eax
movq %rsp, %r14
movq %rax, 0x8(%r14)
movq %rax, 0x150(%rsp)
leaq 0x989(%rip), %rsi       # 0x429b
movq %rbx, %rdi
callq 0x10d0
movq %rax, %rbx
leaq 0xa8(%rsp), %r15
movq 0x2a64(%rip), %rax      # 0x6390
cmpq 0x2a65(%rip), %rax      # 0x6398
jne 0x3941
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
jne 0x3983
callq 0x35cb
movq %r14, %rdi
movq %r15, %rsi
callq 0x31fe
movl 0x2a19(%rip), %edi      # 0x6370
callq 0x3024
movl 0x2a12(%rip), %edi      # 0x6374
movl 0x2a08(%rip), %esi      # 0x6370
callq 0x2dcf
movl 0x29fd(%rip), %esi      # 0x6370
movq %rbx, %rdi
callq 0x2c34
incl 0x2767(%rip)            # 0x60e8
jmp 0x3925
movq %rbx, %rdi
callq 0x10a0
cmpl $0x0, 0x29ea(%rip)      # 0x637c
je 0x39d3
leaq 0xa10(%rip), %rdi       # 0x43ab
callq 0x1100
movq %rsp, %rbx
movl 0x80(%rbx), %esi
leaq 0x8ed(%rip), %rdi       # 0x429d
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x8f4(%rip), %rdi       # 0x42b8
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2b76
cmpl $0x0, 0x29aa(%rip)      # 0x6384
je 0x3a20
leaq 0x9da(%rip), %rdi       # 0x43bd
callq 0x1100
leaq 0xa8(%rsp), %rbx
movl 0x80(%rbx), %esi
leaq 0x8a0(%rip), %rdi       # 0x429d
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x8a7(%rip), %rdi       # 0x42b8
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2b76
cmpl $0x0, 0x2955(%rip)      # 0x637c
je 0x3a33
movl $0xa, %edi
callq 0x10e0
leaq 0x995(%rip), %rdi       # 0x43cf
callq 0x1100
movl 0x292b(%rip), %esi      # 0x6370
leaq 0x885(%rip), %rdi       # 0x42d1
xorl %eax, %eax
callq 0x1040
movl 0x2917(%rip), %esi      # 0x6370
addl %esi, %esi
leaq 0x890(%rip), %rdi       # 0x42f2
xorl %eax, %eax
callq 0x1040
movl 0x2905(%rip), %esi      # 0x6374
leaq 0x89d(%rip), %rdi       # 0x4313
xorl %eax, %eax
callq 0x1040
leaq 0x959(%rip), %rdi       # 0x43dd
callq 0x1100
movl 0x2655(%rip), %esi      # 0x60e4
leaq 0x89e(%rip), %rdi       # 0x4334
xorl %eax, %eax
callq 0x1040
movl 0x2645(%rip), %esi      # 0x60e8
decl %esi
leaq 0x8a6(%rip), %rdi       # 0x4352
xorl %eax, %eax
callq 0x1040
movl 0x262b(%rip), %eax      # 0x60e4
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movl 0x2621(%rip), %eax      # 0x60e8
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x893(%rip), %rdi       # 0x4370
movb $0x1, %al
callq 0x1040
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq