// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, 0x4254(%rip)      # 0x70f4
andl $0x0, 0x4251(%rip)      # 0x70f8
movq %rsi, %rbx
leaq 0x424f(%rip), %rax      # 0x7100
xorl %ecx, %ecx
leaq 0x4446(%rip), %rdx      # 0x7300
cmpq $0x7f, %rcx
je 0x2ecf
movb $0x1, (%rcx,%rdx)
movl %ecx, (%rax)
incq %rcx
addq $0x4, %rax
jmp 0x2eba
movq 0x8(%rbx), %rdi
callq 0x1130
movl %eax, 0x44a6(%rip)      # 0x7384
movq 0x10(%rbx), %rdi
callq 0x1130
movl %eax, 0x4493(%rip)      # 0x7380
movq 0x18(%rbx), %rdi
callq 0x1130
movl %eax, %ebp
movl %eax, 0x448a(%rip)      # 0x7388
movq 0x20(%rbx), %rdi
callq 0x1130
movl %eax, %r14d
movl %eax, 0x447c(%rip)      # 0x738c
movq 0x28(%rbx), %rdi
callq 0x1130
movl %eax, %r15d
movl %eax, 0x446e(%rip)      # 0x7390
movq 0x30(%rbx), %rdi
callq 0x1130
movl %eax, 0x4463(%rip)      # 0x7394
movq 0x38(%rbx), %rdi
callq 0x1130
movl %eax, 0x4458(%rip)      # 0x7398
movq 0x40(%rbx), %rbx
leaq 0xa8(%rsp), %rdi
movsd 0x10b4(%rip), %xmm0     # 0x4008
pushq $0x1
popq %r9
movl %ebp, %esi
movl %r14d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x137c
movl 0x441a(%rip), %esi      # 0x7388
movl 0x4420(%rip), %edx      # 0x7394
movl 0x441e(%rip), %ecx      # 0x7398
movq %rsp, %r15
pushq $0x2
popq %r9
movq %r15, %rdi
movsd 0x107c(%rip), %xmm0     # 0x4008
xorl %r8d, %r8d
callq 0x137c
leaq 0x150(%rsp), %rdi
pushq $0x4
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movsd 0x105d(%rip), %xmm0     # 0x4008
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x137c
cmpl $0x0, 0x43d7(%rip)      # 0x7394
je 0x2fc6
andq $0x0, (%rsp)
jmp 0x2fc9
xorl %r15d, %r15d
leaq 0xa8(%rsp), %r14
movq %r15, (%r14)
andq $0x0, 0x8(%r14)
andq $0x0, 0x150(%rsp)
leaq 0x12a2(%rip), %rsi      # 0x428b
movq %rbx, %rdi
callq 0x10e0
movq %rax, %rbx
movq %rsp, %r15
movq %rbx, %rdi
callq 0x2e67
testb %al, %al
je 0x3045
callq 0x2d09
movq %r14, %rdi
movq %r15, %rsi
callq 0x29d1
movl 0x4367(%rip), %edi      # 0x7380
callq 0x28b3
movl 0x4360(%rip), %edi      # 0x7384
movl 0x4356(%rip), %esi      # 0x7380
callq 0x26f9
movl 0x434b(%rip), %esi      # 0x7380
movq %rbx, %rdi
callq 0x25d8
incl 0x40b5(%rip)            # 0x70f8
jmp 0x2ff7
movq %rbx, %rdi
callq 0x10b0
cmpl $0x0, 0x4338(%rip)      # 0x738c
je 0x309a
leaq 0x133e(%rip), %rdi      # 0x439b
callq 0x1110
leaq 0xa8(%rsp), %rbx
movl 0x80(%rbx), %esi
leaq 0x1216(%rip), %rdi      # 0x428d
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x121d(%rip), %rdi      # 0x42a8
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2520
cmpl $0x0, 0x42f3(%rip)      # 0x7394
je 0x30e2
leaq 0x1303(%rip), %rdi      # 0x43ad
callq 0x1110
movq %rsp, %rbx
movl 0x80(%rbx), %esi
leaq 0x11ce(%rip), %rdi      # 0x428d
xorl %eax, %eax
callq 0x1040
movl 0x84(%rbx), %esi
leaq 0x11d5(%rip), %rdi      # 0x42a8
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2520
cmpl $0x0, 0x42a3(%rip)      # 0x738c
je 0x30f3
pushq $0xa
popq %rdi
callq 0x10f0
leaq 0x12c5(%rip), %rdi      # 0x43bf
callq 0x1110
movl 0x427b(%rip), %esi      # 0x7380
leaq 0x11b5(%rip), %rdi      # 0x42c1
xorl %eax, %eax
callq 0x1040
movl 0x4267(%rip), %esi      # 0x7380
addl %esi, %esi
leaq 0x11c0(%rip), %rdi      # 0x42e2
xorl %eax, %eax
callq 0x1040
movl 0x4255(%rip), %esi      # 0x7384
leaq 0x11cd(%rip), %rdi      # 0x4303
xorl %eax, %eax
callq 0x1040
leaq 0x1289(%rip), %rdi      # 0x43cd
callq 0x1110
movl 0x3fa5(%rip), %esi      # 0x70f4
leaq 0x11ce(%rip), %rdi      # 0x4324
xorl %eax, %eax
callq 0x1040
movl 0x3f95(%rip), %esi      # 0x70f8
decl %esi
leaq 0x11d6(%rip), %rdi      # 0x4342
xorl %eax, %eax
callq 0x1040
movl 0x3f7b(%rip), %eax      # 0x70f4
cvtsi2ss %rax, %xmm0
movl 0x3f74(%rip), %eax      # 0x70f8
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x11c6(%rip), %rdi      # 0x4360
movb $0x1, %al
callq 0x1040
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop