// File: jasperandrew[P]cs350-project2/./lab7.h
// Function: checkPointInit()
void checkPointInit()
{
    FILE * checkpoint_file;
    current_segment = 0;
    checkpoint_file = fopen("DRIVE/CHECKPOINT_REGION","r");
    if(checkpoint_file != NULL){
        if(DBG) cout << "reading checkpoint \n";
        fread(&Checkpoint_Region,sizeof(Checkpoint_Region), 1, checkpoint_file);
        fclose(checkpoint_file);
        for(int i = 0 ; i < 40; i++)
        {
            if(Checkpoint_Region.imaps[i]==0) break;
            //cout << "Imap location: " << Checkpoint_Region.imaps[i] << "\n";
        }

        for(; current_segment < 32; current_segment++){
            if(Checkpoint_Region.liveBits[current_segment] == 0){ 
                //cout <<"livebit: "  << current_segment << " value: " << Checkpoint_Region.liveBits[current_segment];
                //cout <<"current segment: "<< current_segment<< "\n";
                break;
            }
        }
        readImaps();
    }
    else{
        current_segment = 0;
        for(unsigned int imap: Checkpoint_Region.imaps)
        {
            imap = 0;
        }
        for(char liveBit: Checkpoint_Region.liveBits)
        {
            liveBit = 0;
        }
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, 0x109802(%rip)    # 0x10d294
leaq 0x557b(%rip), %rdi      # 0x9014
leaq 0x5572(%rip), %rsi      # 0x9012
callq 0x3290
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3b5c
movq 0x950d(%rip), %rdi      # 0xcfc8
leaq 0x556a(%rip), %rsi      # 0x902c
callq 0x3220
movq -0x8(%rbp), %rcx
leaq 0x16dbd2(%rip), %rdi    # 0x1716a4
movl $0xc0, %esi
movl $0x1, %edx
callq 0x3380
movq -0x8(%rbp), %rdi
callq 0x3230
movl $0x0, -0xc(%rbp)
cmpl $0x28, -0xc(%rbp)
jge 0x3b17
movslq -0xc(%rbp), %rcx
leaq 0x16dba2(%rip), %rax    # 0x1716a4
cmpl $0x0, (%rax,%rcx,4)
jne 0x3b0a
jmp 0x3b17
jmp 0x3b0c
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3af1
jmp 0x3b19
cmpl $0x20, 0x109774(%rip)   # 0x10d294
jge 0x3b52
movslq 0x10976b(%rip), %rcx    # 0x10d294
leaq 0x16db74(%rip), %rax    # 0x1716a4
movsbl 0xa0(%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x3b3f
jmp 0x3b52
jmp 0x3b41
movl 0x10974d(%rip), %eax    # 0x10d294
addl $0x1, %eax
movl %eax, 0x109744(%rip)    # 0x10d294
jmp 0x3b19
callq 0x3740
jmp 0x3c13
movl $0x0, 0x10972e(%rip)    # 0x10d294
leaq 0x16db37(%rip), %rax    # 0x1716a4
movq %rax, -0x18(%rbp)
leaq 0x16db2c(%rip), %rax    # 0x1716a4
movq %rax, -0x20(%rbp)
leaq 0x16db21(%rip), %rax    # 0x1716a4
addq $0xa0, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x3bb5
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
jmp 0x3b8d
leaq 0x16dae8(%rip), %rax    # 0x1716a4
addq $0xa0, %rax
movq %rax, -0x38(%rbp)
leaq 0x16dad7(%rip), %rax    # 0x1716a4
addq $0xa0, %rax
movq %rax, -0x40(%rbp)
leaq 0x16dac6(%rip), %rax    # 0x1716a4
addq $0xa0, %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x3c11
movq -0x40(%rbp), %rax
movb (%rax), %al
movb %al, -0x49(%rbp)
movb $0x0, -0x49(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3bec
jmp 0x3c13
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)