// File: ASG-ICT[P]SPEC2017-Trace/trace.cpp
// Function: trace_init(char*, char*)
int trace_init(char *tracefile, char *ktfile)
{
    kernel_trace_offset = 0;
    kernel_trace_len = 0;
    memset(kernel_trace_buffer, 0 , sizeof(char) * 1024);

    tracefp = fopen(tracefile, "rb");
    ktfp = fopen(ktfile, "rb");
    //ofp = fopen(argv[3], "wb");
    ppn2pid = new int[MAXPPN];
    ppn2vpn = new uint64_t[MAXPPN];


    //vpn2ppn = new uint64_t[MAXPPN];
    next_page_map = new unsigned long[MAXPPN];
    prev_page_map = new unsigned long[MAXPPN];
    memset(ppn2pid, 0, sizeof(int) * MAXPPN);
    memset(ppn2vpn, 0, sizeof(uint64_t) * MAXPPN);

    //memset(vpn2ppn, 0, sizeof(uint64_t) * MAXPPN);
    memset(next_page_map, 0, sizeof(unsigned long) * MAXPPN);
    memset(prev_page_map, 0, sizeof(unsigned long) * MAXPPN);

    alloc_stamp = new unsigned long[MAXPPN];
    memset(alloc_stamp, 0, sizeof(unsigned long) * MAXPPN);
    memset(kt_ch, 0, sizeof(char) * 200);

    fseek(ktfp, 0, SEEK_END);
    tag_size = ftell(ktfp);
    printf("tag_size = %llu\n",tag_size);
    fseek(ktfp, 0, SEEK_SET);
//    tag = (char*)malloc(sizeof(char) * tag_size);
//    fread(tag, 1, tag_size, ktfp);
    //first read
    int tmp_l = read_kt();

    tagp = 0; 
    printf("start trace_init\n");
    printf("%s\n",kt_ch);
    if(strncmp(kt_ch , "@@", 2) == 0)
	printf("yes\n");

	int tmp_i = 0;
    unsigned int pid;
    unsigned long ppn;
    unsigned long vpn;
    uint64_t val;
    unsigned long long h_set = 0, h_free = 0,k_set = 0,k_free = 0;

    int ret_len = 0;
    while (tagp + 16 < tag_size) {
        if (strncmp(kt_ch , "@@@@@@@@@@@@@", 13) == 0) {
            tagp += 16;
	    fread(kt_ch, 1, 3, ktfp);
	    has_read += 3;
            printf("start collect trace  flag, tagp = %lu, has_read = %llu\n", tagp, has_read);
	    ret_len = read_kt();
            break;
        }
        tagp += 13;
	ret_len = read_kt();
    }
    while (tagp + 16 < tag_size) {
        if (strncmp(kt_ch , "#############", 13) == 0) {
            tagp += 16;
	    fread(kt_ch, 1, 3, ktfp);
	    has_read += 3;
	    printf("start dump page talbe flag, tagp = %lu, has_read = %llu\n", tagp, has_read);
	    ret_len = read_kt();
	    printf("ret_len = %d\n",ret_len);
	    char ttt_ch = (*(char*)(kt_ch));
	    printf("magic in KT, %x in KT\n", ttt_ch);

            break;
        }
        tagp += 13;
	ret_len = read_kt();
    }
    unsigned long long dump_pte_trace = 0;
    char free_pt_addr_magic     = 0xfd;
    char set_page_table_magic   = 0xec;
    char free_page_table_magic  = 0xfc;
    unsigned long long set_pt_num = 0,free_pt_num = 0, set_page_table_num = 0, free_page_table_num = 0;


    while(tagp + 16 < tag_size) {
        if (strncmp(kt_ch, "&&&&&&&&&&&&&", 13) == 0) {
            tagp += 16;
	    fread(kt_ch, 1, 3, ktfp);
	    has_read += 3;
	    ret_len = read_kt();
	    char ttt_ch = (*(char*)(kt_ch));
	    printf("set_pt_num = %llu,free_pt_num = %llu, set_page_table_num = %llu, free_page_table_num = %llu\n",set_pt_num,free_pt_num, set_page_table_num, free_page_table_num);
            break;
        }
	char tmp_magic =  (*(char*)(kt_ch));
	if(tmp_magic == set_page_table_magic){
		set_page_table_num ++;

	}
	else if(tmp_magic == free_page_table_magic){
		free_page_table_num ++;
	}
	else {printf("****************************error !!!\n");}


        pid = (*(int*)((kt_ch + 1)));;
	val = (*(uint64_t*)(kt_ch + 5));
        ppn = val & 0xffffff;
        vpn = (val >> 24) & 0xffffffffff;
        ppn2pid[ppn] = pid;
        ppn2vpn[ppn] = vpn;
        vpn2ppn[vpn] = ppn;
        if (vpn2ppn[vpn-1] > 0) {
            unsigned long last_ppn = vpn2ppn[vpn - 1];
            if (last_ppn != ppn - 1) {
                next_page_map[last_ppn] = ppn;
            }
        }
        else if (vpn2ppn[vpn - 2] > 0) {
            unsigned long last_ppn = vpn2ppn[vpn - 2];
            if (last_ppn != ppn - 2) {
                next_page_map[last_ppn] = ppn;
            }
        }
        //printf("setpte: %llu %d %llx %lx %lx\n",
                //total_trace, pid, val, vpn, ppn);
        tagp += 13;
	ret_len = read_kt();
        dump_pte_trace ++;
        alloc_stamp[ppn] = total_trace;
    }   

  /*
    while(tagp + 16 < tag_size) {
        if (strncmp(&(tag[tagp]), "$$$$$$$$$$$$$$$$", 16) == 0) {
            tagp += 16;
            printf("end collect trace, ,dump_pte_trace = %llu, tagp = %lu\n",dump_pte_trace,tagp);
            printf("h_set = %llu , h_free = %llu\n",h_set,h_free);
            printf("set_pt_num = %llu,free_pt_num = %llu, set_page_table_num = %llu, free_page_table_num = %llu\n",set_pt_num,free_pt_num, set_page_table_num, free_page_table_num);
            break;
        }
        char tmp_magic =  (*(char*)(&(tag[tagp])));
        if(tmp_magic == set_pt_addr_magic){
                set_pt_num ++;
        }
        else if(tmp_magic == free_pt_addr_magic){
                free_pt_num ++;
        }
        else if(tmp_magic == set_page_table_magic){
                set_page_table_num ++;
        }
        else if(tmp_magic == free_page_table_magic){
                free_page_table_num ++;
        }
        else {printf("****************************error !!!\n");}
	tagp +=13;
    }
*/
    unsigned long long tmp_sync = 0;

    while (1) {
        if (next_record(tracefp) != 0) {
	    printf("finish in trace_init\n");
            break;
        }
        uint64_t addr = record.paddr;
        if (is_kernel_tag_trace(addr)) {
            // is sync tag
            int kernel_trace_seq = (addr - kernel_config_entry) / (KERNEL_TRACE_CONFIG_SIZE << 20);
            if (kernel_trace_seq >= KERNEL_TRACE_SEQ_NUM) {
                fprintf(stderr, "#### Invalid kernel trace seq:addr=0x%llx, seq=%d\n", addr, kernel_trace_seq);
                exit(-1);
            }

            tmp_sync ++;

            unsigned long long kernel_trace_seq_entry =
                    addr - kernel_config_entry - kernel_trace_seq * (KERNEL_TRACE_CONFIG_SIZE << 20);

            int kernel_trace_tag = (kernel_trace_seq_entry) / TAG_ACCESS_SIZE;
            if (kernel_trace_tag >= TAG_MAX_POS) {
                fprintf(stderr, "#### Invalid kernel_trace_tag:addr=0x%llx,tag=%d\n", addr, kernel_trace_tag);
                exit(-1);
            }
            int hmtt_kt_type = ((kernel_trace_seq_entry) % TAG_ACCESS_SIZE) / TAG_ACCESS_STEP;
            if (hmtt_kt_type > 1) {
                fprintf(stderr, "#### Invalid hmtt_kt_type:addr=0x%llx,tag=%d,type=%d\n", addr, kernel_trace_tag,
                        hmtt_kt_type);
                exit(-1);
            } else if (hmtt_kt_type == 1);


            if(kernel_trace_tag == SET_PTE_TAG){
                    h_set ++;
            }
            else if(kernel_trace_tag == FREE_PTE_TAG){
	            h_free ++;
            }

	

            if (kernel_trace_tag == DUMP_PAGE_TABLE_TAG) {
		printf("find DUMP_PAGE_TABLE_TAG in hmtt trace, trace_idd = %llu\n",trace_id);
                break;
            }
        }
    }

    printf("dump page done.\n");
    printf("trace init done.\n");

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, 0xeee4a7(%rip)    # 0xef0674
movl $0x0, 0xeee4a1(%rip)    # 0xef0678
leaq 0x1ee432(%rip), %rdi    # 0x1f0610
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x10b0
movq -0x8(%rbp), %rdi
leaq 0x3140(%rip), %rsi      # 0x5335
callq 0x1140
movq %rax, 0xeee5c7(%rip)    # 0xef07c8
movq -0x10(%rbp), %rdi
leaq 0x3129(%rip), %rsi      # 0x5335
callq 0x1140
movq %rax, 0xeee548(%rip)    # 0xef0760
movl $0x4000000, %edi        # imm = 0x4000000
callq 0x1040
movq %rax, 0xeee5af(%rip)    # 0xef07d8
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x1040
movq %rax, 0xeee596(%rip)    # 0xef07d0
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x1040
movq %rax, 0xeee5c5(%rip)    # 0xef0810
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x1040
movq %rax, 0xeee5bc(%rip)    # 0xef0818
movq 0xeee575(%rip), %rdi    # 0xef07d8
xorl %esi, %esi
movl $0x4000000, %edx        # imm = 0x4000000
callq 0x10b0
movq 0xeee55a(%rip), %rdi    # 0xef07d0
xorl %esi, %esi
movl $0x8000000, %edx        # imm = 0x8000000
callq 0x10b0
movq 0xeee587(%rip), %rdi    # 0xef0810
xorl %esi, %esi
movl $0x8000000, %edx        # imm = 0x8000000
callq 0x10b0
movq 0xeee57c(%rip), %rdi    # 0xef0818
xorl %esi, %esi
movl $0x8000000, %edx        # imm = 0x8000000
callq 0x10b0
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x1040
movq %rax, 0xeee567(%rip)    # 0xef0820
movq 0xeee560(%rip), %rdi    # 0xef0820
xorl %esi, %esi
movl $0x8000000, %edx        # imm = 0x8000000
callq 0x10b0
leaq 0xeee3bd(%rip), %rdi    # 0xef0690
xorl %esi, %esi
movl $0xc8, %edx
callq 0x10b0
movq 0xeee47a(%rip), %rdi    # 0xef0760
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1130
movq 0xeee465(%rip), %rdi    # 0xef0760
callq 0x1030
movq %rax, 0xeee471(%rip)    # 0xef0778
movq 0xeee46a(%rip), %rsi    # 0xef0778
leaq 0x3023(%rip), %rdi      # 0x5338
movb $0x0, %al
callq 0x1050
movq 0xeee43d(%rip), %rdi    # 0xef0760
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1130
callq 0x1720
movl %eax, -0x14(%rbp)
movl $0x0, 0xeee430(%rip)    # 0xef0770
leaq 0x3002(%rip), %rdi      # 0x5349
movb $0x0, %al
callq 0x1050
leaq 0x2cfe(%rip), %rdi      # 0x5053
leaq 0xeee334(%rip), %rsi    # 0xef0690
movb $0x0, %al
callq 0x1050
leaq 0xeee326(%rip), %rdi    # 0xef0690
leaq 0x2ffa(%rip), %rsi      # 0x536b
movl $0x2, %edx
callq 0x10a0
cmpl $0x0, %eax
jne 0x238e
leaq 0x2fd4(%rip), %rdi      # 0x535b
movb $0x0, %al
callq 0x1050
movl $0x0, -0x18(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl 0xeee3ae(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, %eax
cmpq 0xeee3aa(%rip), %rax    # 0xef0778
jae 0x2470
leaq 0xeee2b5(%rip), %rdi    # 0xef0690
leaq 0x2f7e(%rip), %rsi      # 0x5360
movl $0xd, %edx
callq 0x10a0
cmpl $0x0, %eax
jne 0x2454
movl 0xeee379(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, 0xeee370(%rip)    # 0xef0770
movq 0xeee359(%rip), %rcx    # 0xef0760
leaq 0xeee282(%rip), %rdi    # 0xef0690
movl $0x1, %esi
movl $0x3, %edx
callq 0x1190
movq 0xeee25c(%rip), %rax    # 0xef0680
addq $0x3, %rax
movq %rax, 0xeee251(%rip)    # 0xef0680
movl 0xeee33b(%rip), %esi    # 0xef0770
movq 0xeee244(%rip), %rdx    # 0xef0680
leaq 0x2f2b(%rip), %rdi      # 0x536e
movb $0x0, %al
callq 0x1050
callq 0x1720
movl %eax, -0x5c(%rbp)
jmp 0x2470
movl 0xeee316(%rip), %eax    # 0xef0770
addl $0xd, %eax
movl %eax, 0xeee30d(%rip)    # 0xef0770
callq 0x1720
movl %eax, -0x5c(%rbp)
jmp 0x23bc
jmp 0x2472
movl 0xeee2f8(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, %eax
cmpq 0xeee2f4(%rip), %rax    # 0xef0778
jae 0x2556
leaq 0xeee1ff(%rip), %rdi    # 0xef0690
leaq 0x2f0e(%rip), %rsi      # 0x53a6
movl $0xd, %edx
callq 0x10a0
cmpl $0x0, %eax
jne 0x253a
movl 0xeee2bf(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, 0xeee2b6(%rip)    # 0xef0770
movq 0xeee29f(%rip), %rcx    # 0xef0760
leaq 0xeee1c8(%rip), %rdi    # 0xef0690
movl $0x1, %esi
movl $0x3, %edx
callq 0x1190
movq 0xeee1a2(%rip), %rax    # 0xef0680
addq $0x3, %rax
movq %rax, 0xeee197(%rip)    # 0xef0680
movl 0xeee281(%rip), %esi    # 0xef0770
movq 0xeee18a(%rip), %rdx    # 0xef0680
leaq 0x2eb7(%rip), %rdi      # 0x53b4
movb $0x0, %al
callq 0x1050
callq 0x1720
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %esi
leaq 0x2ed7(%rip), %rdi      # 0x53ed
movb $0x0, %al
callq 0x1050
movb 0xeee16d(%rip), %al     # 0xef0690
movb %al, -0x5d(%rbp)
movsbl -0x5d(%rbp), %esi
leaq 0x2eca(%rip), %rdi      # 0x53fb
movb $0x0, %al
callq 0x1050
jmp 0x2556
movl 0xeee230(%rip), %eax    # 0xef0770
addl $0xd, %eax
movl %eax, 0xeee227(%rip)    # 0xef0770
callq 0x1720
movl %eax, -0x5c(%rbp)
jmp 0x2472
movq $0x0, -0x68(%rbp)
movb $-0x3, -0x69(%rbp)
movb $-0x14, -0x6a(%rbp)
movb $-0x4, -0x6b(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movl 0xeee1da(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, %eax
cmpq 0xeee1d6(%rip), %rax    # 0xef0778
jae 0x2869
leaq 0xeee0e1(%rip), %rdi    # 0xef0690
leaq 0x2e5c(%rip), %rsi      # 0x5412
movl $0xd, %edx
callq 0x10a0
cmpl $0x0, %eax
jne 0x2640
movl 0xeee1a5(%rip), %eax    # 0xef0770
addl $0x10, %eax
movl %eax, 0xeee19c(%rip)    # 0xef0770
movq 0xeee185(%rip), %rcx    # 0xef0760
leaq 0xeee0ae(%rip), %rdi    # 0xef0690
movl $0x1, %esi
movl $0x3, %edx
callq 0x1190
movq 0xeee088(%rip), %rax    # 0xef0680
addq $0x3, %rax
movq %rax, 0xeee07d(%rip)    # 0xef0680
callq 0x1720
movl %eax, -0x5c(%rbp)
movb 0xeee07f(%rip), %al     # 0xef0690
movb %al, -0x91(%rbp)
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %r8
leaq 0x2dec(%rip), %rdi      # 0x5420
movb $0x0, %al
callq 0x1050
jmp 0x2869
movb 0xeee04a(%rip), %al     # 0xef0690
movb %al, -0x92(%rbp)
movsbl -0x92(%rbp), %eax
movsbl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x266f
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x26a2
movsbl -0x92(%rbp), %eax
movsbl -0x6b(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2692
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x26a0
leaq 0x2de4(%rip), %rdi      # 0x547d
movb $0x0, %al
callq 0x1050
jmp 0x26a2
movl 0xeedfe9(%rip), %eax    # 0xef0691
movl %eax, -0x1c(%rbp)
movq 0xeedfe3(%rip), %rax    # 0xef0695
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
andq $0xffffff, %rax         # imm = 0xFFFFFF
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
shrq $0x18, %rax
movabsq $0xffffffffff, %rcx     # imm = 0xFFFFFFFFFF
andq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %edx
movq 0xeee0f1(%rip), %rax    # 0xef07d8
movq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rdx
movq 0xeee0d7(%rip), %rax    # 0xef07d0
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq 0xeee115(%rip), %rdi    # 0xef0828
leaq -0x30(%rbp), %rsi
callq 0x2c30
movq -0xf8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xa0(%rbp)
leaq 0xeee0ec(%rip), %rdi    # 0xef0828
leaq -0xa0(%rbp), %rsi
callq 0x2d10
cmpq $0x0, (%rax)
jbe 0x27a9
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xb0(%rbp)
leaq 0xeee0c4(%rip), %rdi    # 0xef0828
leaq -0xb0(%rbp), %rsi
callq 0x2d10
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq -0x28(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x27a4
movq -0x28(%rbp), %rdx
movq 0xeee077(%rip), %rax    # 0xef0810
movq -0xa8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x282b
movq -0x30(%rbp), %rax
subq $0x2, %rax
movq %rax, -0xb8(%rbp)
leaq 0xeee069(%rip), %rdi    # 0xef0828
leaq -0xb8(%rbp), %rsi
callq 0x2d10
cmpq $0x0, (%rax)
jbe 0x2829
movq -0x30(%rbp), %rax
subq $0x2, %rax
movq %rax, -0xc8(%rbp)
leaq 0xeee041(%rip), %rdi    # 0xef0828
leaq -0xc8(%rbp), %rsi
callq 0x2d10
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq -0x28(%rbp), %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
je 0x2827
movq -0x28(%rbp), %rdx
movq 0xeedff4(%rip), %rax    # 0xef0810
movq -0xc0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x2829
jmp 0x282b
movl 0xeedf3f(%rip), %eax    # 0xef0770
addl $0xd, %eax
movl %eax, 0xeedf36(%rip)    # 0xef0770
callq 0x1720
movl %eax, -0x5c(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq 0xeedf9b(%rip), %rdx    # 0xef07f0
movq 0xeedfc4(%rip), %rax    # 0xef0820
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x2590
movq $0x0, -0xd0(%rbp)
movq 0xeedf4d(%rip), %rdi    # 0xef07c8
callq 0x17a0
cmpl $0x0, %eax
je 0x2898
leaq 0x2c18(%rip), %rdi      # 0x54a4
movb $0x0, %al
callq 0x1050
jmp 0x2a48
movq 0x58c1(%rip), %rax      # 0x8160
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x1950
cmpl $0x0, %eax
je 0x2a43
movq -0xd8(%rbp), %rax
subq 0x5837(%rip), %rax      # 0x8100
shrq $0x14, %rax
movl %eax, -0xdc(%rbp)
movslq -0xdc(%rbp), %rax
cmpq $0x40, %rax
jb 0x290f
movq 0x56f1(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq -0xd8(%rbp), %rdx
movl -0xdc(%rbp), %ecx
leaq 0x2863(%rip), %rsi      # 0x5161
movb $0x0, %al
callq 0x1170
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1160
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
movq -0xd8(%rbp), %rax
subq 0x57d1(%rip), %rax      # 0x8100
movslq -0xdc(%rbp), %rcx
shlq $0x14, %rcx
subq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
shrq $0xc, %rax
movl %eax, -0xec(%rbp)
cmpl $0x100, -0xec(%rbp)     # imm = 0x100
jb 0x2990
movq 0x5670(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq -0xd8(%rbp), %rdx
movl -0xec(%rbp), %ecx
leaq 0x2815(%rip), %rsi      # 0x5194
movb $0x0, %al
callq 0x1170
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1160
movq -0xe8(%rbp), %rax
andq $0xfff, %rax            # imm = 0xFFF
shrq $0xb, %rax
movl %eax, -0xf0(%rbp)
cmpl $0x1, -0xf0(%rbp)
jle 0x29e6
movq 0x5621(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq -0xd8(%rbp), %rdx
movl -0xec(%rbp), %ecx
movl -0xf0(%rbp), %r8d
leaq 0x27f1(%rip), %rsi      # 0x51c6
movb $0x0, %al
callq 0x1170
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1160
cmpl $0x1, -0xf0(%rbp)
jne 0x29f1
jmp 0x29f1
jmp 0x29f3
cmpl $0x0, -0xec(%rbp)
jne 0x2a0a
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2a21
cmpl $0x1, -0xec(%rbp)
jne 0x2a1f
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2a21
cmpl $0x2, -0xec(%rbp)
jne 0x2a41
movq 0x5717(%rip), %rsi      # 0x8148
leaq 0x2a82(%rip), %rdi      # 0x54ba
movb $0x0, %al
callq 0x1050
jmp 0x2a48
jmp 0x2a43
jmp 0x2874
leaq 0x2aa5(%rip), %rdi      # 0x54f4
movb $0x0, %al
callq 0x1050
leaq 0x2aa8(%rip), %rdi      # 0x5505
movb $0x0, %al
callq 0x1050
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop