// File: /workspace/github_cpp_makefile_star2_O2/NishadSaraf[P]Championship-Simulator/src/cache.cc
// Function: CACHE::handle_read()
void CACHE::handle_read()
{
    // handle read
    uint32_t read_cpu = RQ.entry[RQ.head].cpu;
    if (read_cpu == NUM_CPUS)
        return;

    for (uint32_t i=0; i<MAX_READ; i++) {

        // handle the oldest entry
        if ((RQ.entry[RQ.head].event_cycle <= current_core_cycle[read_cpu]) && (RQ.occupancy > 0)) {
            int index = RQ.head;

            // access cache
            uint32_t set = get_set(RQ.entry[index].address);
            int way = check_hit(&RQ.entry[index]);
            
            if (way >= 0) { // read hit

                if (cache_type == IS_ITLB) {
                    RQ.entry[index].instruction_pa = block[set][way].data;
                    if (PROCESSED.occupancy < PROCESSED.SIZE)
                        PROCESSED.add_queue(&RQ.entry[index]);
                }
                else if (cache_type == IS_DTLB) {
                    RQ.entry[index].data_pa = block[set][way].data;
                    if (PROCESSED.occupancy < PROCESSED.SIZE)
                        PROCESSED.add_queue(&RQ.entry[index]);
                }
                else if (cache_type == IS_STLB) 
                    RQ.entry[index].data = block[set][way].data;
                else if (cache_type == IS_L1I) {
                    if (PROCESSED.occupancy < PROCESSED.SIZE)
                        PROCESSED.add_queue(&RQ.entry[index]);
                }
                //else if (cache_type == IS_L1D) {
                else if ((cache_type == IS_L1D) && (RQ.entry[index].type != PREFETCH)) {
                    if (PROCESSED.occupancy < PROCESSED.SIZE)
                        PROCESSED.add_queue(&RQ.entry[index]);
                }

                // update prefetcher on load instruction
                if (RQ.entry[index].type == LOAD) {
                    if (cache_type == IS_L1D) 
                        l1d_prefetcher_operate(block[set][way].full_addr, RQ.entry[index].ip, 1, RQ.entry[index].type);
                    else if (cache_type == IS_L2C)
                        l2c_prefetcher_operate(block[set][way].full_addr, RQ.entry[index].ip, 1, RQ.entry[index].type);
                }

                // update replacement policy
                if (cache_type == IS_LLC) {
                    llc_update_replacement_state(read_cpu, set, way, block[set][way].full_addr, RQ.entry[index].ip, 0, RQ.entry[index].type, 1);

                }
                else
                    update_replacement_state(read_cpu, set, way, block[set][way].full_addr, RQ.entry[index].ip, 0, RQ.entry[index].type, 1);

                // COLLECT STATS
                sim_hit[read_cpu][RQ.entry[index].type]++;
                sim_access[read_cpu][RQ.entry[index].type]++;

                // check fill level
                if (RQ.entry[index].fill_level < fill_level) {

                    if (RQ.entry[index].instruction) 
                        upper_level_icache[read_cpu]->return_data(&RQ.entry[index]);
                    else // data
                        upper_level_dcache[read_cpu]->return_data(&RQ.entry[index]);
                }

                // update prefetch stats and reset prefetch bit
                if (block[set][way].prefetch) {
                    STATS.pf_useful++;
                    block[set][way].prefetch = 0;
                }
                block[set][way].used = 1;

                HIT[RQ.entry[index].type]++;
                ACCESS[RQ.entry[index].type]++;
                
                // remove this entry from RQ
                RQ.remove_queue(&RQ.entry[index]);
            }
            else { // read miss

                DP ( if (warmup_complete[read_cpu]) {
                cout << "[" << NAME << "] " << __func__ << " read miss";
                cout << " instr_id: " << RQ.entry[index].instr_id << " address: " << hex << RQ.entry[index].address;
                cout << " full_addr: " << RQ.entry[index].full_addr << dec;
                cout << " cycle: " << RQ.entry[index].event_cycle << endl; });

                // check mshr
                uint8_t miss_handled = 1;
                int mshr_index = check_mshr(&RQ.entry[index]);

                if ((mshr_index == -1) && (MSHR.occupancy < MSHR_SIZE)) { // this is a new miss

                    // add it to mshr (read miss)
                    add_mshr(&RQ.entry[index]);

                    // add it to the next level's read queue
                    if (lower_level)
                        lower_level->add_rq(&RQ.entry[index]);
                    else { // this is the last level
                        if (cache_type == IS_STLB) {
                            // TODO: need to differentiate page table walk and actual swap

                            // emulate page table walk
                            uint64_t pa = va_to_pa(read_cpu, RQ.entry[index].instr_id, RQ.entry[index].full_addr, RQ.entry[index].address);

                            RQ.entry[index].data = pa >> PAGE_SHIFT; 
                            RQ.entry[index].event_cycle = current_core_cycle[read_cpu];
                            return_data(&RQ.entry[index]);
                        }
                    }
                }
                else {
                    if ((mshr_index == -1) && (MSHR.occupancy == MSHR_SIZE)) { // not enough MSHR resource
                        
                        // cannot handle miss request until one of MSHRs is available
                        miss_handled = 0;
                        STALL[RQ.entry[index].type]++;
                    }
                    else if (mshr_index != -1) { // already in-flight miss

                        // mark merged consumer
                        if (RQ.entry[index].type == RFO) {

                            if (RQ.entry[index].tlb_access) {
                                uint32_t sq_index = RQ.entry[index].sq_index;
                                MSHR.entry[mshr_index].store_merged = 1;
                                MSHR.entry[mshr_index].sq_index_depend_on_me[sq_index] = 1;
                                for (uint32_t i=0; i<SQ_SIZE; i++) {
                                    if (RQ.entry[index].sq_index_depend_on_me[i])
                                        MSHR.entry[mshr_index].sq_index_depend_on_me[i] = 1;
                                    else
                                        continue;
                                }
                            }

                            if (RQ.entry[index].load_merged) {
                                //uint32_t lq_index = RQ.entry[index].lq_index; 
                                MSHR.entry[mshr_index].load_merged = 1;
                                //MSHR.entry[mshr_index].lq_index_depend_on_me[lq_index] = 1;
                                for (uint32_t i=0; i<LQ_SIZE; i++) {
                                    if (RQ.entry[index].lq_index_depend_on_me[i])
                                        MSHR.entry[mshr_index].lq_index_depend_on_me[i] = 1;
                                }
                            }
                        }
                        else {
                            if (RQ.entry[index].instruction) {
                                uint32_t rob_index = RQ.entry[index].rob_index;
                                MSHR.entry[mshr_index].instr_merged = 1;
                                MSHR.entry[mshr_index].rob_index_depend_on_me[rob_index] = 1;

                                DP (if (warmup_complete[MSHR.entry[mshr_index].cpu]) {
                                cout << "[INSTR_MERGED] " << __func__ << " cpu: " << MSHR.entry[mshr_index].cpu << " instr_id: " << MSHR.entry[mshr_index].instr_id;
                                cout << " merged rob_index: " << rob_index << " instr_id: " << RQ.entry[index].instr_id << endl; });

                                if (RQ.entry[index].instr_merged) {
                                    for (uint32_t i=0; i<ROB_SIZE; i++) {
                                        if (RQ.entry[index].rob_index_depend_on_me[i]) {
                                            MSHR.entry[mshr_index].rob_index_depend_on_me[i] = 1;

                                            DP (if (warmup_complete[MSHR.entry[mshr_index].cpu]) {
                                            cout << "[INSTR_MERGED] " << __func__ << " cpu: " << MSHR.entry[mshr_index].cpu << " instr_id: " << MSHR.entry[mshr_index].instr_id;
                                            cout << " merged rob_index: " << i << " instr_id: N/A" << endl; });
                                        }
                                    }
                                }
                            }
                            else 
                            {
                                uint32_t lq_index = RQ.entry[index].lq_index;
                                MSHR.entry[mshr_index].load_merged = 1;
                                MSHR.entry[mshr_index].lq_index_depend_on_me[lq_index] = 1;

                                DP (if (warmup_complete[read_cpu]) {
                                cout << "[DATA_MERGED] " << __func__ << " cpu: " << read_cpu << " instr_id: " << RQ.entry[index].instr_id;
                                cout << " merged rob_index: " << RQ.entry[index].rob_index << " instr_id: " << RQ.entry[index].instr_id << " lq_index: " << RQ.entry[index].lq_index << endl; });

                                for (uint32_t i=0; i<LQ_SIZE; i++) {
                                    if (RQ.entry[index].lq_index_depend_on_me[i]) 
                                        MSHR.entry[mshr_index].lq_index_depend_on_me[i] = 1;
                                }

                                if (RQ.entry[index].store_merged) {
                                    //uint32_t sq_index = RQ.entry[index].sq_index;
                                    MSHR.entry[mshr_index].store_merged = 1;
                                    //MSHR.entry[mshr_index].sq_index_depend_on_me[sq_index] = 1;
                                    for (uint32_t i=0; i<SQ_SIZE; i++) {
                                        if (RQ.entry[index].sq_index_depend_on_me[i])
                                            MSHR.entry[mshr_index].sq_index_depend_on_me[i] = 1;
                                        else
                                            continue;
                                    }
                                }
                            }
                        }

                        // update fill_level
                        if (RQ.entry[index].fill_level < MSHR.entry[mshr_index].fill_level)
                            MSHR.entry[mshr_index].fill_level = RQ.entry[index].fill_level;

                        // update request
                        if (MSHR.entry[mshr_index].type == PREFETCH) {
                            uint8_t  prior_returned = MSHR.entry[mshr_index].returned;
                            uint64_t prior_event_cycle = MSHR.entry[mshr_index].event_cycle;
                            memcpy(&MSHR.entry[mshr_index], &RQ.entry[index], sizeof(PACKET));
                            
                            // in case request is already returned, we should keep event_cycle and retunred variables
                            MSHR.entry[mshr_index].returned = prior_returned;
                            MSHR.entry[mshr_index].event_cycle = prior_event_cycle;
                        }

                        MSHR_MERGED[RQ.entry[index].type]++;

                        DP ( if (warmup_complete[read_cpu]) {
                        cout << "[" << NAME << "] " << __func__ << " mshr merged";
                        cout << " instr_id: " << RQ.entry[index].instr_id << " prior_id: " << MSHR.entry[mshr_index].instr_id; 
                        cout << " address: " << hex << RQ.entry[index].address;
                        cout << " full_addr: " << RQ.entry[index].full_addr << dec;
                        cout << " cycle: " << RQ.entry[index].event_cycle << endl; });
                    }
                    else { // WE SHOULD NOT REACH HERE
                        cerr << "[" << NAME << "] MSHR errors" << endl;
                        assert(0);
                    }
                }

                if (miss_handled) {
                    // update prefetcher on load instruction
                    if (RQ.entry[index].type == LOAD) {
                        if (cache_type == IS_L1D) 
                            l1d_prefetcher_operate(RQ.entry[index].full_addr, RQ.entry[index].ip, 0, RQ.entry[index].type);
                        if (cache_type == IS_L2C)
                            l2c_prefetcher_operate(RQ.entry[index].full_addr, RQ.entry[index].ip, 0, RQ.entry[index].type);
                    }

                    MISS[RQ.entry[index].type]++;
                    ACCESS[RQ.entry[index].type]++;

                    // remove this entry from RQ
                    RQ.remove_queue(&RQ.entry[index]);
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x90e0(%rdi), %rax
movl 0x9074(%rdi), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
movl 0x330(%rax,%rcx), %r13d
cmpq $0x1, %r13
jne 0x39ed
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
leaq 0x9048(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0xe628(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x10308(%rdi), %rax
movq %rax, 0x40(%rsp)
leaq 0x102e8(%rdi), %rax
movq %rax, 0x38(%rsp)
leaq 0x8(%rdi,%r13,8), %rax
movq %rax, 0x30(%rsp)
leaq (%rdi,%r13,8), %rax
addq $0x10, %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
leaq 0x7946f(%rip), %r14     # 0x7ceb0
movq %r13, (%rsp)
cmpl 0x739c(%rbx), %r12d
jae 0x39de
movq 0x90e0(%rbx), %rax
movl 0x9074(%rbx), %ecx
imulq $0x380, %rcx, %rdx      # imm = 0x380
movq 0x378(%rax,%rdx), %rdx
cmpq (%r14,%r13,8), %rdx
ja 0x4060
cmpl $0x0, 0x907c(%rbx)
je 0x4060
movslq %ecx, %rcx
imulq $0x380, %rcx, %r15      # imm = 0x380
movq 0x340(%rax,%r15), %rsi
movq %rbx, %rdi
callq 0x2e58
movl %eax, %r14d
movq 0x90e0(%rbx), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x3772
testl %eax, %eax
js 0x3b0f
movl %eax, %ebp
movq %r12, 0x18(%rsp)
movzbl 0x73a4(%rbx), %eax
movl %ebp, %r13d
movl %r14d, %edi
cmpq $0x4, %rax
movq %rdi, 0x8(%rsp)
ja 0x3d6d
leaq 0xc53a(%rip), %rcx      # 0x10018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x7390(%rbx), %rax
movq (%rax,%rdi,8), %rax
imulq $0x50, %r13, %rcx
movq 0x30(%rax,%rcx), %rax
movq 0x90e0(%rbx), %rsi
movq %rax, 0x350(%rsi,%r15)
jmp 0x3d4d
movq 0x90e0(%rbx), %r14
leaq (%r14,%r15), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3908
cmpl $-0x1, %eax
je 0x3bb0
cmpb $0x1, 0x32f(%r13)
movslq %eax, %rcx
jne 0x3bf9
cmpb $0x0, 0x1(%r13)
je 0x3c77
movl 0x33c(%r13), %esi
movq 0xca20(%rbx), %rdi
movslq %eax, %rdx
imulq $0x380, %rdx, %rdx      # imm = 0x380
movb $0x1, %r8b
movb %r8b, 0x32b(%rdi,%rdx)
addq %rdx, %rdi
movb %r8b, 0x229(%rsi,%rdi)
xorl %esi, %esi
movq 0x90e0(%rbx), %r14
cmpq $0x38, %rsi
je 0x3c77
addq %r15, %r14
cmpb $0x0, 0x229(%rsi,%r14)
je 0x3bab
movq 0xca20(%rbx), %rdi
addq %rdx, %rdi
movb $0x1, 0x229(%rsi,%rdi)
incq %rsi
jmp 0x3b7a
movl 0x7388(%rbx), %eax
cmpl %eax, 0xc9bc(%rbx)
jae 0x4068
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3940
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x413c
movq 0x90e0(%rbx), %rsi
addq %r15, %rsi
movq (%rdi), %rax
callq *(%rax)
movq (%rsp), %r13
leaq 0x792bc(%rip), %r14     # 0x7ceb0
jmp 0x3fc2
cmpb $0x0, (%r13)
movq 0xca20(%rbx), %rdx
je 0x408c
movl 0x10(%r13), %esi
imulq $0x380, %rcx, %rax      # imm = 0x380
movb $0x1, %dil
movb %dil, 0x329(%rdx,%rax)
addq %rax, %rdx
movb %dil, 0x29(%rsi,%rdx)
movq 0x90e0(%rbx), %rdx
cmpb $0x0, 0x329(%rdx,%r15)
je 0x3f2a
xorl %edx, %edx
movq (%rsp), %r13
cmpq $0x100, %rdx            # imm = 0x100
je 0x3f2e
movq 0x90e0(%rbx), %rsi
addq %r15, %rsi
cmpb $0x0, 0x29(%rdx,%rsi)
je 0x3c72
movq 0xca20(%rbx), %rsi
addq %rax, %rsi
movb $0x1, 0x29(%rdx,%rsi)
incq %rdx
jmp 0x3c45
cmpb $0x0, 0x32a(%r14,%r15)
je 0x3f2a
movq 0xca20(%rbx), %rdx
movslq %eax, %rcx
imulq $0x380, %rcx, %rax      # imm = 0x380
movb $0x1, 0x32a(%rdx,%rax)
xorl %edx, %edx
movq (%rsp), %r13
cmpq $0x48, %rdx
je 0x3f2e
movq 0x90e0(%rbx), %rsi
addq %r15, %rsi
cmpb $0x0, 0x129(%rdx,%rsi)
je 0x3cd5
movq 0xca20(%rbx), %rsi
addq %rax, %rsi
movb $0x1, 0x129(%rdx,%rsi)
incq %rdx
jmp 0x3ca5
movq 0x90e0(%rbx), %rsi
cmpb $0x2, 0x32f(%rsi,%r15)
jne 0x3d4d
jmp 0x3d6d
movq 0x7390(%rbx), %rax
movq (%rax,%rdi,8), %rax
imulq $0x50, %r13, %rcx
movq 0x30(%rax,%rcx), %rax
movq 0x90e0(%rbx), %rcx
movq %rax, 0x360(%rcx,%r15)
jmp 0x3d6d
movl 0xe65c(%rbx), %eax
cmpl 0xe648(%rbx), %eax
jae 0x3d6d
movq 0x90e0(%rbx), %rsi
jmp 0x3d5b
movq 0x7390(%rbx), %rax
movq (%rax,%rdi,8), %rax
imulq $0x50, %r13, %rcx
movq 0x30(%rax,%rcx), %rax
movq 0x90e0(%rbx), %rsi
movq %rax, 0x358(%rsi,%r15)
movl 0xe65c(%rbx), %eax
cmpl 0xe648(%rbx), %eax
jae 0x3d6d
addq %r15, %rsi
movq 0x10(%rsp), %rdi
callq 0x9c5e
movq 0x8(%rsp), %rdi
movq 0x90e0(%rbx), %rax
cmpb $0x0, 0x32f(%rax,%r15)
jne 0x3dec
addq %r15, %rax
movzbl 0x73a4(%rbx), %ecx
cmpl $0x5, %ecx
je 0x3dbe
cmpl $0x4, %ecx
jne 0x3df2
movq 0x7390(%rbx), %rcx
movq (%rcx,%rdi,8), %rcx
imulq $0x50, %r13, %rdx
movq 0x20(%rcx,%rdx), %rsi
movq 0x370(%rax), %rdx
movq %rbx, %rdi
pushq $0x1
popq %rcx
xorl %r8d, %r8d
callq 0xfdde
jmp 0x3de7
movq 0x7390(%rbx), %rcx
movq (%rcx,%rdi,8), %rcx
imulq $0x50, %r13, %rdx
movq 0x20(%rcx,%rdx), %rsi
movq 0x370(%rax), %rdx
movq %rbx, %rdi
pushq $0x1
popq %rcx
xorl %r8d, %r8d
callq 0xfdd6
movq 0x8(%rsp), %rdi
movb 0x73a4(%rbx), %cl
movq %r13, %r12
imulq $0x50, %r13, %rax
movq 0x7390(%rbx), %rdx
movq (%rdx,%rdi,8), %rdx
movq 0x20(%rdx,%rax), %r8
movq 0x90e0(%rbx), %rax
movq 0x370(%rax,%r15), %r9
movzbl 0x32f(%rax,%r15), %eax
subq $0x8, %rsp
cmpb $0x6, %cl
jne 0x3e46
movq %rbx, %rdi
movq 0x8(%rsp), %r13
movl %r13d, %esi
movl %r14d, %edx
movl %ebp, %ecx
pushq $0x1
pushq %rax
pushq $0x0
callq 0xfcc8
jmp 0x3e60
movq %rbx, %rdi
movq 0x8(%rsp), %r13
movl %r13d, %esi
movl %r14d, %edx
movl %ebp, %ecx
pushq $0x1
pushq %rax
pushq $0x0
callq 0xfc4e
addq $0x20, %rsp
movq 0x90e0(%rbx), %rsi
movzbl 0x32f(%rsi,%r15), %eax
movq %r13, %rcx
shlq $0x5, %rcx
movq 0x40(%rsp), %rdx
addq %rcx, %rdx
shll $0x3, %eax
incq (%rax,%rdx)
addq 0x38(%rsp), %rcx
incq (%rax,%rcx)
movl 0x8(%rsi,%r15), %eax
cmpl 0x7398(%rbx), %eax
leaq 0x7900b(%rip), %r14     # 0x7ceb0
jge 0x3ec1
addq %r15, %rsi
cmpb $0x0, (%rsi)
movq 0x30(%rsp), %rax
cmoveq 0x28(%rsp), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x7390(%rbx), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
imulq $0x50, %r12, %rcx
cmpb $0x0, 0x1(%rax,%rcx)
je 0x3eed
leaq (%rax,%rcx), %rdx
incq %rdx
incq 0x102d0(%rbx)
movb $0x0, (%rdx)
movb $0x1, 0x3(%rax,%rcx)
movq 0x90e0(%rbx), %rax
movzbl 0x32f(%rax,%r15), %ecx
incq 0x72c8(%rbx,%rcx,8)
leaq (%rax,%r15), %rsi
incq 0x72a8(%rbx,%rcx,8)
movq 0x20(%rsp), %rdi
callq 0x9cc0
movq 0x18(%rsp), %r12
jmp 0x4060
movq (%rsp), %r13
movq 0x90e0(%rbx), %rsi
movl 0x8(%rsi,%r15), %eax
movq 0xca20(%rbx), %rdi
imulq $0x380, %rcx, %r14      # imm = 0x380
cmpl 0x8(%rdi,%r14), %eax
jge 0x3f59
leaq (%rdi,%r14), %rcx
addq $0x8, %rcx
movl %eax, (%rcx)
cmpb $0x2, 0x32f(%rdi,%r14)
jne 0x3faa
addq %r14, %rdi
movb 0x32c(%rdi), %bpl
movq %r12, 0x18(%rsp)
movq 0x378(%rdi), %r12
addq %r15, %rsi
movl $0x380, %edx            # imm = 0x380
callq 0x21b0
movq 0xca20(%rbx), %rax
movb %bpl, 0x32c(%rax,%r14)
movq %r12, 0x378(%rax,%r14)
movq 0x18(%rsp), %r12
movq 0x90e0(%rbx), %rsi
leaq 0x78eff(%rip), %r14     # 0x7ceb0
movzbl 0x32f(%rsi,%r15), %eax
incq 0x7308(%rbx,%rax,8)
movq 0x90e0(%rbx), %rax
cmpb $0x0, 0x32f(%rax,%r15)
jne 0x4039
movb 0x73a4(%rbx), %cl
cmpb $0x4, %cl
jne 0x400a
addq %r15, %rax
movq 0x348(%rax), %rsi
movq 0x370(%rax), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xfdde
movb 0x73a4(%rbx), %cl
movq 0x90e0(%rbx), %rax
cmpb $0x5, %cl
jne 0x4039
movq 0x348(%rax,%r15), %rsi
movq 0x370(%rax,%r15), %rdx
movzbl 0x32f(%rax,%r15), %r8d
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xfdd6
movq 0x90e0(%rbx), %rax
movzbl 0x32f(%rax,%r15), %ecx
incq 0x72e8(%rbx,%rcx,8)
leaq (%rax,%r15), %rsi
incq 0x72a8(%rbx,%rcx,8)
movq 0x20(%rsp), %rdi
callq 0x9cc0
incl %r12d
jmp 0x3a45
movq (%rsp), %r13
jne 0x41ac
movzbl 0x32f(%r14,%r15), %eax
incq 0x7328(%rbx,%rax,8)
leaq 0x78e26(%rip), %r14     # 0x7ceb0
jmp 0x4060
movl 0x338(%r13), %esi
imulq $0x380, %rcx, %rax      # imm = 0x380
movb $0x1, %dil
movb %dil, 0x32a(%rdx,%rax)
addq %rax, %rdx
movb %dil, 0x129(%rsi,%rdx)
xorl %edx, %edx
movq (%rsp), %r13
movq 0x90e0(%rbx), %rsi
cmpq $0x48, %rdx
je 0x40e7
addq %r15, %rsi
cmpb $0x0, 0x129(%rdx,%rsi)
je 0x40e2
movq 0xca20(%rbx), %rsi
addq %rax, %rsi
movb $0x1, 0x129(%rdx,%rsi)
incq %rdx
jmp 0x40b6
cmpb $0x0, 0x32b(%rsi,%r15)
je 0x3f2e
movq 0xca20(%rbx), %rdx
movb $0x1, 0x32b(%rdx,%rax)
xorl %edx, %edx
cmpq $0x38, %rdx
je 0x3f2e
movq 0x90e0(%rbx), %rsi
addq %r15, %rsi
cmpb $0x0, 0x229(%rdx,%rsi)
je 0x4137
movq 0xca20(%rbx), %rsi
addq %rax, %rsi
movb $0x1, 0x229(%rdx,%rsi)
incq %rdx
jmp 0x4107
cmpb $0x2, 0x73a4(%rbx)
movq (%rsp), %r13
leaq 0x78d62(%rip), %r14     # 0x7ceb0
jne 0x3fc2
movq 0x90e0(%rbx), %rax
movq 0x368(%rax,%r15), %rsi
movq 0x340(%rax,%r15), %rcx
movq 0x348(%rax,%r15), %rdx
movl %r13d, %edi
callq 0x7259
shrq $0xc, %rax
movq 0x90e0(%rbx), %rcx
leaq (%rcx,%r15), %rsi
movq %rax, 0x360(%rcx,%r15)
movq (%r14,%r13,8), %rax
movq %rax, 0x378(%rcx,%r15)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
jmp 0x3fc2
movq 0x11e3d(%rip), %rdi     # 0x15ff0
leaq 0xbed6(%rip), %rsi      # 0x10090
callq 0x2230
addq $0x7350, %rbx           # imm = 0x7350
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21d0
leaq 0xbeba(%rip), %rsi      # 0x10092
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2110
leaq 0xbe78(%rip), %rdi      # 0x10067
leaq 0xbe73(%rip), %rsi      # 0x10069
leaq 0xbeef(%rip), %rcx      # 0x100ec
movl $0x273, %edx            # imm = 0x273
callq 0x2160
nop