// File: /workspace/github_cpp_makefile_star2_O3/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, 0x374b(%rip)      # 0x70e4
movl %eax, 0x3749(%rip)      # 0x70e8
movaps 0x18aa(%rip), %xmm0     # 0x5250
movaps %xmm0, 0x3943(%rip)     # 0x72f0
movaps %xmm0, 0x394c(%rip)     # 0x7300
movaps %xmm0, 0x3955(%rip)     # 0x7310
movaps %xmm0, 0x395e(%rip)     # 0x7320
movaps %xmm0, 0x3967(%rip)     # 0x7330
movaps %xmm0, 0x3970(%rip)     # 0x7340
movaps %xmm0, 0x3979(%rip)     # 0x7350
movups %xmm0, 0x3981(%rip)     # 0x735f
movdqa 0x163a(%rip), %xmm0     # 0x5020
movdqa 0x1642(%rip), %xmm1     # 0x5030
movdqa 0x186a(%rip), %xmm2     # 0x5260
pshufd $0xf5, %xmm2, %xmm3     # xmm3 = xmm2[1,1,3,3]
leaq 0x36ee(%rip), %rcx      # 0x70f0
movdqa 0x1636(%rip), %xmm4     # 0x5040
movdqa %xmm0, %xmm5
pxor %xmm1, %xmm5
movdqa %xmm2, %xmm6
pcmpgtd %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pcmpeqd %xmm3, %xmm5
pand %xmm6, %xmm5
movd %xmm5, %edx
testb $0x1, %dl
je 0x3a33
movl %eax, (%rcx,%rax,4)
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x3a44
leal 0x1(%rax), %edx
movl %edx, 0x4(%rcx,%rax,4)
addq $0x2, %rax
paddq %xmm4, %xmm0
cmpq $0x80, %rax
jne 0x3a0a
movq 0x8(%rbx), %rdi
callq 0x1120
movl %eax, 0x3911(%rip)      # 0x7374
movq 0x10(%rbx), %rdi
callq 0x1120
movl %eax, 0x38fe(%rip)      # 0x7370
movq 0x18(%rbx), %rdi
callq 0x1120
movl %eax, %ebp
movl %eax, 0x38f5(%rip)      # 0x7378
movq 0x20(%rbx), %rdi
callq 0x1120
movl %eax, %r14d
movl %eax, 0x38e7(%rip)      # 0x737c
movq 0x28(%rbx), %rdi
callq 0x1120
movl %eax, %r15d
movl %eax, 0x38d9(%rip)      # 0x7380
movq 0x30(%rbx), %rdi
callq 0x1120
movl %eax, 0x38ce(%rip)      # 0x7384
movq 0x38(%rbx), %rdi
callq 0x1120
movl %eax, 0x38c3(%rip)      # 0x7388
movq 0x40(%rbx), %rbx
leaq 0xa8(%rsp), %rdi
movsd 0x152f(%rip), %xmm0     # 0x5008
movl %ebp, %esi
movl %r14d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x138c
movl 0x3883(%rip), %esi      # 0x7378
movl 0x3889(%rip), %edx      # 0x7384
movl 0x3887(%rip), %ecx      # 0x7388
movq %rsp, %r15
movq %r15, %rdi
movsd 0x14f9(%rip), %xmm0     # 0x5008
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x138c
leaq 0x150(%rsp), %rdi
movl $0x4, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movsd 0x14d2(%rip), %xmm0     # 0x5008
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x138c
cmpl $0x0, 0x383c(%rip)      # 0x7384
je 0x3b54
movq $0x0, (%rsp)
jmp 0x3b57
xorl %r15d, %r15d
leaq 0xa8(%rsp), %r14
movq %r15, (%r14)
xorl %eax, %eax
movq %rax, 0x8(%r14)
movq %rax, 0x150(%rsp)
leaq 0x1774(%rip), %rsi      # 0x52eb
movq %rbx, %rdi
callq 0x10d0
movq %rax, %rbx
movq %rsp, %r15
movq 0x3804(%rip), %rax      # 0x7390
cmpq 0x3805(%rip), %rax      # 0x7398
jne 0x3ba1
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
jne 0x3be3
callq 0x37e9
movq %r14, %rdi
movq %r15, %rsi
callq 0x3422
movl 0x37b9(%rip), %edi      # 0x7370
callq 0x3238
movl 0x37b2(%rip), %edi      # 0x7374
movl 0x37a8(%rip), %esi      # 0x7370
callq 0x2fd3
movl 0x379d(%rip), %esi      # 0x7370
movq %rbx, %rdi
callq 0x2e38
incl 0x3507(%rip)            # 0x70e8
jmp 0x3b85
movq %rbx, %rdi
callq 0x10a0
cmpl $0x0, 0x378a(%rip)      # 0x737c
je 0x3c38
leaq 0x1800(%rip), %rdi      # 0x53fb
callq 0x1100
leaq 0xa8(%rsp), %rbx
movl 0x80(%rbx), %esi
leaq 0x16d8(%rip), %rdi      # 0x52ed
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x16df(%rip), %rdi      # 0x5308
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2d78
cmpl $0x0, 0x3745(%rip)      # 0x7384
je 0x3c80
leaq 0x17c5(%rip), %rdi      # 0x540d
callq 0x1100
movq %rsp, %rbx
movl 0x80(%rbx), %esi
leaq 0x1690(%rip), %rdi      # 0x52ed
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x1697(%rip), %rdi      # 0x5308
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2d78
cmpl $0x0, 0x36f5(%rip)      # 0x737c
je 0x3c93
movl $0xa, %edi
callq 0x10e0
leaq 0x1785(%rip), %rdi      # 0x541f
callq 0x1100
movl 0x36cb(%rip), %esi      # 0x7370
leaq 0x1675(%rip), %rdi      # 0x5321
xorl %eax, %eax
callq 0x1040
movl 0x36b7(%rip), %esi      # 0x7370
addl %esi, %esi
leaq 0x1680(%rip), %rdi      # 0x5342
xorl %eax, %eax
callq 0x1040
movl 0x36a5(%rip), %esi      # 0x7374
leaq 0x168d(%rip), %rdi      # 0x5363
xorl %eax, %eax
callq 0x1040
leaq 0x1749(%rip), %rdi      # 0x542d
callq 0x1100
movl 0x33f5(%rip), %esi      # 0x70e4
leaq 0x168e(%rip), %rdi      # 0x5384
xorl %eax, %eax
callq 0x1040
movl 0x33e5(%rip), %esi      # 0x70e8
decl %esi
leaq 0x1696(%rip), %rdi      # 0x53a2
xorl %eax, %eax
callq 0x1040
movl 0x33cb(%rip), %eax      # 0x70e4
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movl 0x33c1(%rip), %eax      # 0x70e8
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1683(%rip), %rdi      # 0x53c0
movb $0x1, %al
callq 0x1040
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq