// File: ASG-ICT[P]SPEC2017-Trace/trace_py.cpp
// Function: main
int main(int argc, char *argv[])
{
    if (argc != 5) {
        printf("./sim tracefile ktfile simn skipn\n");
        return 0;
    }
    printf("%s\n", argv[1]);
    trace_init(argv[1], argv[2]);
    unsigned long long i;
    unsigned long long simn = atol(argv[3]);
    unsigned long long skipn = atol(argv[4]);
    printf("start skip!\n");
    for (i = 0; i < skipn; i++) {
        int res = next_translate();
        if (res == 0) {
            printf("\n");
	    printf("res= %d\n",res);
	    break;
        }
    }
    printf("end skip!\n");
    unsigned valid = 0;
    printf("*******************************\n");

    //trace_finish();

    printf("*******************************\n");
    unsigned long long last_non = 0;
    unsigned long long last_miss_free_pte = 0, last_skip_set_pt_pmd = 0;
    nonpte = 0;
    trace_id = 0;
    miss_free_pte = 0;
    skip_set_pt_pmd = 0;
    for (i = 0; i < simn; i++) {
        int res = next_translate();
        if(i % 200000000 == 0){
		double tmp_d = nonpte - last_non;
	        
                printf("**<%llu> nonpte = %llu , percent = %lf , miss_free_pte = %llu, skip_set_pt_pmd = %llu\n", i / 200000000 ,nonpte - last_non ,  tmp_d /200000000.0, miss_free_pte - last_miss_free_pte , skip_set_pt_pmd - last_skip_set_pt_pmd);
                last_non = nonpte;
		last_miss_free_pte = miss_free_pte;
		last_skip_set_pt_pmd = skip_set_pt_pmd;
		miss_free_pte = 0;
            }




        if (res == 0) break;
        if (record.rw == 1) {
            valid++;
        }
        if (record.paddr >> 12 == 494597)
        printf("trace_py %d %lx %lx %lld\n",
            record.rw, record.paddr >> 6, record.vaddr >> 6, record.tm);
    }

    double tmp_d = nonpte - last_non;
                printf("**<%llu> nonpte = %llu , percent = %lf , miss_free_pte = %llu, skip_set_pt_pmd = %llu\n", i / 200000000 ,nonpte - last_non ,  tmp_d /200000000.0, miss_free_pte - last_miss_free_pte , skip_set_pt_pmd - last_skip_set_pt_pmd);


    printf("\n");
    fprintf(stderr, "\n\n%ld\n", nonpte);
    printf("trace_id = %llu\n",trace_id);
    trace_finish();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
je 0x1376
leaq 0x3ccd(%rip), %rdi      # 0x5030
movb $0x0, %al
callq 0x1050
movl $0x0, -0x4(%rbp)
jmp 0x1713
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x3cce(%rip), %rdi      # 0x5053
movb $0x0, %al
callq 0x1050
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x21b0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1150
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1150
movq %rax, -0x28(%rbp)
leaq 0x3c8d(%rip), %rdi      # 0x5057
movb $0x0, %al
callq 0x1050
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x1422
callq 0x1990
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x1412
leaq 0x3e78(%rip), %rdi      # 0x5270
movb $0x0, %al
callq 0x1050
movl -0x2c(%rbp), %esi
leaq 0x3c5b(%rip), %rdi      # 0x5064
movb $0x0, %al
callq 0x1050
jmp 0x1422
jmp 0x1414
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x13d9
leaq 0x3c44(%rip), %rdi      # 0x506d
movb $0x0, %al
callq 0x1050
movl $0x0, -0x30(%rbp)
leaq 0x3c3a(%rip), %rdi      # 0x5078
movb $0x0, %al
callq 0x1050
leaq 0x3c2c(%rip), %rdi      # 0x5078
movb $0x0, %al
callq 0x1050
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
leaq 0xeef386(%rip), %rax    # 0xef07f8
movq $0x0, (%rax)
leaq 0x6cc8(%rip), %rax      # 0x8148
movq $0x0, (%rax)
leaq 0xeef3fa(%rip), %rax    # 0xef0888
movq $0x0, (%rax)
leaq 0xeef3c4(%rip), %rax    # 0xef0860
movq $0x0, (%rax)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x162f
callq 0x1990
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movl $0xbebc200, %ecx        # imm = 0xBEBC200
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x15a8
leaq 0xeef318(%rip), %rax    # 0xef07f8
movq (%rax), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm0
movaps 0x3b1a(%rip), %xmm1     # 0x5010
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3b1e(%rip), %xmm1     # 0x5020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl $0xbebc200, %ecx        # imm = 0xBEBC200
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
leaq 0xeef2ca(%rip), %rax    # 0xef07f8
movq (%rax), %rdx
subq -0x38(%rbp), %rdx
movsd -0x58(%rbp), %xmm0
movsd 0x3ac6(%rip), %xmm1     # 0x5008
divsd %xmm1, %xmm0
leaq 0xeef33b(%rip), %rax    # 0xef0888
movq (%rax), %rcx
subq -0x40(%rbp), %rcx
leaq 0xeef305(%rip), %rax    # 0xef0860
movq (%rax), %r8
subq -0x48(%rbp), %r8
leaq 0x3b30(%rip), %rdi      # 0x5099
movb $0x1, %al
callq 0x1050
leaq 0xeef281(%rip), %rax    # 0xef07f8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq 0xeef303(%rip), %rax    # 0xef0888
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0xeef2cd(%rip), %rax    # 0xef0860
movq (%rax), %rax
movq %rax, -0x48(%rbp)
leaq 0xeef2e7(%rip), %rax    # 0xef0888
movq $0x0, (%rax)
cmpl $0x0, -0x4c(%rbp)
jne 0x15b0
jmp 0x162f
leaq 0x6b99(%rip), %rax      # 0x8150
cmpl $0x1, (%rax)
jne 0x15c5
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
leaq 0x6b84(%rip), %rax      # 0x8150
movq 0x10(%rax), %rax
shrq $0xc, %rax
cmpq $0x78c05, %rax          # imm = 0x78C05
jne 0x161c
leaq 0x6b6d(%rip), %rax      # 0x8150
movl (%rax), %esi
leaq 0x6b64(%rip), %rax      # 0x8150
movq 0x10(%rax), %rdx
shrq $0x6, %rdx
leaq 0x6b55(%rip), %rax      # 0x8150
movq 0x18(%rax), %rcx
shrq $0x6, %rcx
leaq 0x6b46(%rip), %rax      # 0x8150
movq 0x8(%rax), %r8
leaq 0x3adb(%rip), %rdi      # 0x50f0
movb $0x0, %al
callq 0x1050
jmp 0x161e
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x14ab
leaq 0xeef1c2(%rip), %rax    # 0xef07f8
movq (%rax), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm0
movaps 0x39c4(%rip), %xmm1     # 0x5010
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x39c8(%rip), %xmm1     # 0x5020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl $0xbebc200, %ecx        # imm = 0xBEBC200
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
leaq 0xeef174(%rip), %rax    # 0xef07f8
movq (%rax), %rdx
subq -0x38(%rbp), %rdx
movsd -0x60(%rbp), %xmm0
movsd 0x3970(%rip), %xmm1     # 0x5008
divsd %xmm1, %xmm0
leaq 0xeef1e5(%rip), %rax    # 0xef0888
movq (%rax), %rcx
subq -0x40(%rbp), %rcx
leaq 0xeef1af(%rip), %rax    # 0xef0860
movq (%rax), %r8
subq -0x48(%rbp), %r8
leaq 0x39da(%rip), %rdi      # 0x5099
movb $0x1, %al
callq 0x1050
leaq 0x3ba3(%rip), %rdi      # 0x5270
movb $0x0, %al
callq 0x1050
movq 0x68fd(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
leaq 0xeef113(%rip), %rax    # 0xef07f8
movq (%rax), %rdx
leaq 0x3a1b(%rip), %rsi      # 0x510a
movb $0x0, %al
callq 0x1170
leaq 0x6a4b(%rip), %rax      # 0x8148
movq (%rax), %rsi
leaq 0x3a0a(%rip), %rdi      # 0x5111
movb $0x0, %al
callq 0x1050
callq 0x2a70
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)