// File: /workspace/github_cpp_makefile_star2_O1/jasperandrew[P]cs350-project2/./lab7.h
// Function: readImaps()
void readImaps()
{
    for(int i = 0; i < 40; i++)
    {
        if((Checkpoint_Region.imaps[i]) == 0){
            Checkpoint_Region_counter = i;
            break;

        }
        int block_number = Checkpoint_Region.imaps[i];
        int seg_idx = block_number/1024;
        int seg_block = block_number % 1024;

        if(seg_idx == current_segment){
            //cout << current_segment<< "\n";
            transferImap(wbuffer.getBlock(seg_block-1)->getBlockData());
        }else{
            string seg_path = "DRIVE/SEGMENT" + to_string(seg_idx+1);
            FILE * fp;
            fp = fopen(seg_path.c_str(),"r");
            block_num tmpB[BLOCK_SZ/4];
            fseek(fp, (BLOCK_SZ * (seg_block-1)), SEEK_SET);
            fread(tmpB, sizeof(block_num), BLOCK_SZ/4, fp);
            fclose(fp);
            transferImap(tmpB);
        } 
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
xorl %r15d, %r15d
leaq 0x16b014(%rip), %r8     # 0x16d654
leaq 0x16b0d1(%rip), %r14    # 0x16d718
movl (%r8,%r15,4), %ebx
testl %ebx, %ebx
je 0x286f
leal 0x3ff(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %r12d
sarl $0xa, %r12d
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
subl %eax, %ebx
cmpl 0x106bd1(%rip), %r12d   # 0x109244
jne 0x26ba
movslq %ebx, %rax
leaq 0x1750a1(%rip), %rcx    # 0x177720
movq -0x8(%rcx,%rax,8), %rax
xorl %ecx, %ecx
movl 0x708(%rax,%rcx,4), %edx
testl %edx, %edx
je 0x2860
movslq 0x17507c(%rip), %rsi    # 0x177718
leal 0x1(%rsi), %edi
movl %edi, 0x175073(%rip)    # 0x177718
movl %edx, (%r14,%rsi,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x2686
jmp 0x2860
incl %r12d
movl %r12d, %r13d
negl %r13d
cmovsl %r12d, %r13d
movl $0x1, %r14d
cmpl $0xa, %r13d
jb 0x271a
movl $0x4, %r14d
movl %r13d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x2711
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x2717
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x271a
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x26e1
addl $-0x3, %r14d
jmp 0x271a
addl $-0x2, %r14d
jmp 0x271a
decl %r14d
shrl $0x1f, %r12d
leal (%r14,%r12), %esi
leaq -0x440(%rbp), %rax
movq %rax, -0x450(%rbp)
leaq -0x450(%rbp), %rdi
movl $0x2d, %edx
callq 0x2250
addq -0x450(%rbp), %r12
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x54a4
movl $0xd, %r8d
leaq -0x450(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x38a6(%rip), %rcx      # 0x6014
callq 0x2230
leaq -0x38(%rbp), %r12
movq %r12, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2797
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x279f
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x450(%rbp), %rdi
leaq -0x440(%rbp), %rax
cmpq %rax, %rdi
je 0x27ce
callq 0x21b0
movq -0x48(%rbp), %rdi
leaq 0x3849(%rip), %rsi      # 0x6022
callq 0x2260
movq %rax, %r14
shll $0xa, %ebx
addl $0xfffffc00, %ebx       # imm = 0xFFFFFC00
movslq %ebx, %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x2220
movl $0x4, %esi
movl $0x100, %edx            # imm = 0x100
leaq -0x450(%rbp), %rdi
movq %r14, %rcx
callq 0x2320
movq %r14, %rdi
callq 0x21e0
xorl %eax, %eax
leaq 0x16aef7(%rip), %r14    # 0x16d718
movl -0x450(%rbp,%rax,4), %ecx
testl %ecx, %ecx
je 0x284b
movslq 0x174ee5(%rip), %rdx    # 0x177718
leal 0x1(%rdx), %esi
movl %esi, 0x174edc(%rip)    # 0x177718
movl %ecx, (%r14,%rdx,4)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x2821
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x2859
callq 0x21b0
leaq 0x16adf4(%rip), %r8     # 0x16d654
incq %r15
cmpq $0x28, %r15
jne 0x2647
jmp 0x2876
movl %r15d, 0x16ae9e(%rip)   # 0x16d714
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x450(%rbp), %rdi
leaq -0x440(%rbp), %rax
cmpq %rax, %rdi
je 0x28a3
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0
nop