// File: jasperandrew[P]cs350-project2/./classes.cpp
// Function: WriteBuffer::writeToDisk()
void WriteBuffer::writeToDisk(){
    // Segment summary blocks
    int nextSegment = current_segment;
    /*for(; nextSegment < 32; nextSegment++){
      if(Checkpoint_Region.liveBits[nextSegment] == 0) break;
      }*/

    if(DBG) cout << "Writing to SEGMENT" + to_string(nextSegment+1) << endl;

    for(int i = 0; i < num_blocks; i++){
        buf[i]->writeToSegment();
    }

    ofstream segment("DRIVE/SEGMENT" + to_string(nextSegment+1), ios::out | ios::binary);
    segment.write(mem_segment, SEG_SZ);
    segment.close();

    Checkpoint_Region.liveBits[nextSegment] = 1;
    num_blocks = 8;
    for(int i =0; i < num_blocks; i++) seg_summary[i]->clearSegSum();

    current_segment++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movl 0x1077b4(%rip), %eax    # 0x10d294
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %esi
incl %esi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x69f0
movq -0x2b0(%rbp), %rdx
leaq 0x36d2(%rip), %rsi      # 0x91d8
leaq -0x30(%rbp), %rdi
callq 0x69a0
jmp 0x5b11
movq 0x74b0(%rip), %rdi      # 0xcfc8
leaq -0x30(%rbp), %rsi
callq 0x31f0
movq %rax, -0x2c0(%rbp)
jmp 0x5b2a
movq -0x2c0(%rbp), %rdi
movq 0x7480(%rip), %rsi      # 0xcfb8
callq 0x3250
jmp 0x5b3f
leaq -0x30(%rbp), %rdi
callq 0x3170
leaq -0x50(%rbp), %rdi
callq 0x3170
movl $0x0, -0x60(%rbp)
movq -0x2b8(%rbp), %rcx
movl -0x60(%rbp), %eax
cmpl 0x2000(%rcx), %eax
jge 0x5bba
movq -0x2b8(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x6f50
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x5b58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5bac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3170
leaq -0x50(%rbp), %rdi
callq 0x3170
jmp 0x5d45
movl -0xc(%rbp), %esi
incl %esi
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x69f0
movq -0x2c8(%rbp), %rdx
leaq 0x3424(%rip), %rsi      # 0x9004
leaq -0x280(%rbp), %rdi
callq 0x69a0
jmp 0x5bee
movl $0x10, %edi
movl $0x4, %esi
callq 0x6c00
movl %eax, -0x2cc(%rbp)
jmp 0x5c05
movl -0x2cc(%rbp), %edx
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x3480
jmp 0x5c20
leaq -0x280(%rbp), %rdi
callq 0x3170
leaq -0x2a0(%rbp), %rdi
callq 0x3170
leaq 0x7651(%rip), %rsi      # 0xd290
leaq -0x260(%rbp), %rdi
movl $0x100000, %edx         # imm = 0x100000
callq 0x3310
jmp 0x5c52
leaq -0x260(%rbp), %rdi
callq 0x3340
jmp 0x5c60
movq -0x2b8(%rbp), %rax
movslq -0xc(%rbp), %rdx
leaq 0x16ba32(%rip), %rcx    # 0x1716a4
movb $0x1, 0xa0(%rcx,%rdx)
movl $0x8, 0x2000(%rax)
movl $0x0, -0x2a4(%rbp)
movq -0x2b8(%rbp), %rcx
movl -0x2a4(%rbp), %eax
cmpl 0x2000(%rcx), %eax
jge 0x5d21
movq -0x2b8(%rbp), %rax
movslq -0x2a4(%rbp), %rcx
movq 0x2008(%rax,%rcx,8), %rdi
callq 0x7070
jmp 0x5cc0
jmp 0x5cc2
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x5c8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5cf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x3170
leaq -0x2a0(%rbp), %rdi
callq 0x3170
jmp 0x5d45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3370
jmp 0x5d45
movl 0x10756d(%rip), %eax    # 0x10d294
addl $0x1, %eax
movl %eax, 0x107564(%rip)    # 0x10d294
leaq -0x260(%rbp), %rdi
callq 0x3370
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x3430
nop