// File: 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
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, 0x58f1(%rip)      # 0xa0e4
movl $0x0, 0x58eb(%rip)      # 0xa0e8
movl $0x0, -0x24(%rbp)
cmpl $0x7f, -0x24(%rbp)
jae 0x4837
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0x5ada(%rip), %rax      # 0xa2f0
movb $0x1, (%rax,%rcx)
movl -0x24(%rbp), %edx
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0x58c7(%rip), %rax      # 0xa0f0
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4804
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1120
movl %eax, 0x5b2a(%rip)      # 0xa374
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1120
movl %eax, 0x5b13(%rip)      # 0xa370
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1120
movl %eax, 0x5b08(%rip)      # 0xa378
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1120
movl %eax, 0x5af9(%rip)      # 0xa37c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x1120
movl %eax, 0x5aea(%rip)      # 0xa380
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x1120
movl %eax, 0x5adb(%rip)      # 0xa384
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x1120
movl %eax, 0x5acc(%rip)      # 0xa388
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x18(%rbp)
movl 0x5aaa(%rip), %esi      # 0xa378
movl 0x5aa8(%rip), %edx      # 0xa37c
movl 0x5aa6(%rip), %ecx      # 0xa380
leaq -0xd0(%rbp), %rdi
movsd 0x271f(%rip), %xmm0     # 0x7008
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x13c0
movl 0x5a7b(%rip), %esi      # 0xa378
movl 0x5a81(%rip), %edx      # 0xa384
movl 0x5a7f(%rip), %ecx      # 0xa388
leaq -0x178(%rbp), %rdi
movsd 0x26f0(%rip), %xmm0     # 0x7008
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x13c0
leaq -0x220(%rbp), %rdi
movl $0x4, %esi
xorl %r9d, %r9d
movsd 0x26cb(%rip), %xmm0     # 0x7008
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
callq 0x13c0
cmpl $0x0, 0x5a32(%rip)      # 0xa384
je 0x496f
leaq -0x178(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x0, -0x178(%rbp)
jmp 0x497a
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0x220(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x28e2(%rip), %rsi      # 0x727d
callq 0x10f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4780
testb $0x1, %al
jne 0x49b3
jmp 0x4a0e
callq 0x4440
leaq -0xd0(%rbp), %rdi
leaq -0x178(%rbp), %rsi
leaq -0x220(%rbp), %rdx
callq 0x3b60
movl 0x5998(%rip), %edi      # 0xa370
callq 0x38e0
movl 0x5991(%rip), %edi      # 0xa374
movl 0x5987(%rip), %esi      # 0xa370
callq 0x34c0
movq -0x20(%rbp), %rdi
movl 0x5978(%rip), %esi      # 0xa370
callq 0x3380
movl 0x56e5(%rip), %eax      # 0xa0e8
addl $0x1, %eax
movl %eax, 0x56dc(%rip)      # 0xa0e8
jmp 0x49a4
movq -0x20(%rbp), %rdi
callq 0x10c0
cmpl $0x0, 0x595e(%rip)      # 0xa37c
je 0x4a5c
leaq 0x2858(%rip), %rdi      # 0x727f
movb $0x0, %al
callq 0x1040
movl -0x50(%rbp), %esi
leaq 0x285a(%rip), %rdi      # 0x7292
movb $0x0, %al
callq 0x1040
movl -0x4c(%rbp), %esi
leaq 0x2864(%rip), %rdi      # 0x72ad
movb $0x0, %al
callq 0x1040
leaq -0xd0(%rbp), %rdi
callq 0x3250
cmpl $0x0, 0x5921(%rip)      # 0xa384
je 0x4aa7
leaq 0x285a(%rip), %rdi      # 0x72c6
movb $0x0, %al
callq 0x1040
movl -0xf8(%rbp), %esi
leaq 0x2812(%rip), %rdi      # 0x7292
movb $0x0, %al
callq 0x1040
movl -0xf4(%rbp), %esi
leaq 0x2819(%rip), %rdi      # 0x72ad
movb $0x0, %al
callq 0x1040
leaq -0x178(%rbp), %rdi
callq 0x3250
cmpl $0x0, 0x58ce(%rip)      # 0xa37c
je 0x4abe
leaq 0x26e9(%rip), %rdi      # 0x71a0
movb $0x0, %al
callq 0x1040
leaq 0x2814(%rip), %rdi      # 0x72d9
xorl %eax, %eax
movb %al, -0x221(%rbp)
callq 0x1040
movb -0x221(%rbp), %al
movl 0x5892(%rip), %esi      # 0xa370
leaq 0x2803(%rip), %rdi      # 0x72e8
callq 0x1040
movb -0x221(%rbp), %al
movl 0x587a(%rip), %esi      # 0xa370
addl %esi, %esi
leaq 0x280a(%rip), %rdi      # 0x7309
callq 0x1040
movb -0x221(%rbp), %al
movl 0x5864(%rip), %esi      # 0xa374
leaq 0x2813(%rip), %rdi      # 0x732a
callq 0x1040
movb -0x221(%rbp), %al
leaq 0x2822(%rip), %rdi      # 0x734b
callq 0x1040
movb -0x221(%rbp), %al
movl 0x55aa(%rip), %esi      # 0xa0e4
leaq 0x2813(%rip), %rdi      # 0x7354
callq 0x1040
movb -0x221(%rbp), %al
movl 0x5596(%rip), %esi      # 0xa0e8
decl %esi
leaq 0x2817(%rip), %rdi      # 0x7372
callq 0x1040
movl 0x557e(%rip), %eax      # 0xa0e4
cvtsi2ss %rax, %xmm0
movl 0x5577(%rip), %eax      # 0xa0e8
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2809(%rip), %rdi      # 0x7390
movb $0x1, %al
callq 0x1040
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopw (%rax,%rax)