// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdi, %rbx
movslq 0x104c72(%rip), %rax    # 0x109244
movq %rax, -0x50(%rbp)
leal 0x1(%rax), %r15d
movl %r15d, %r14d
negl %r14d
cmovsl %r15d, %r14d
movl $0x1, %r12d
cmpl $0xa, %r14d
jb 0x463a
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r14d, %ecx
cmpl $0x63, %ecx
jbe 0x4631
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x4637
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x463a
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x45fe
addl $-0x3, %r12d
jmp 0x463a
addl $-0x2, %r12d
jmp 0x463a
decl %r12d
shrl $0x1f, %r15d
leal (%r12,%r15), %esi
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movl $0x2d, %edx
callq 0x2250
movq (%r13), %rdi
addq %r15, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x54a4
leaq 0x1b74(%rip), %rcx      # 0x61e8
movl $0x12, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq -0x260(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x46b3
movq %rdx, -0x270(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x260(%rbp)
jmp 0x46bb
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x268(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x270(%rbp), %rsi
movq -0x268(%rbp), %rdx
movq 0x48e6(%rip), %rdi      # 0x8fd0
callq 0x2240
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq -0x270(%rbp), %rdi
cmpq %r13, %rdi
je 0x472a
callq 0x21b0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x473c
callq 0x21b0
cmpl $0x0, 0x2000(%rbx)
jle 0x4760
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
callq 0x533e
incq %r12
movslq 0x2000(%rbx), %rax
cmpq %rax, %r12
jl 0x4748
movl $0x1, %r12d
cmpl $0xa, %r14d
jb 0x47b6
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r14d, %ecx
cmpl $0x63, %ecx
jbe 0x47ad
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x47b3
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x47b6
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x477a
addl $-0x3, %r12d
jmp 0x47b6
addl $-0x2, %r12d
jmp 0x47b6
decl %r12d
leal (%r15,%r12), %esi
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x70(%rbp), %r13
movq %r13, %rdi
movl $0x2d, %edx
callq 0x2250
addq (%r13), %r15
movq %r15, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x54a4
leaq 0x1828(%rip), %rcx      # 0x6014
movl $0xd, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq -0x38(%rbp), %r14
movq %r14, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4822
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x4829
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x48(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x270(%rbp), %rdi
movl $0x14, %edx
callq 0x23f0
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x4863
callq 0x21b0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x4875
callq 0x21b0
leaq 0x49c4(%rip), %rsi      # 0x9240
leaq -0x270(%rbp), %rdi
movl $0x100000, %edx         # imm = 0x100000
callq 0x22c0
leaq -0x270(%rbp), %rdi
callq 0x22e0
leaq 0x168db4(%rip), %rax    # 0x16d654
movq -0x50(%rbp), %rcx
movb $0x1, 0xa0(%rcx,%rax)
movl $0x8, 0x2000(%rbx)
xorl %r14d, %r14d
movl $0xb0c, %r15d           # imm = 0xB0C
movq 0x2008(%rbx,%r14,8), %rdi
addq %r15, %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x2100
incq %r14
movslq 0x2000(%rbx), %rax
cmpq %rax, %r14
jl 0x48bf
incl 0x104959(%rip)          # 0x109244
movq 0x46d6(%rip), %rax      # 0x8fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x268(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x270(%rbp,%rcx)
callq 0x2190
leaq -0x178(%rbp), %rdi
callq 0x20a0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x4949
callq 0x21b0
jmp 0x4949
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
jmp 0x4985
movq %rax, %rbx
jmp 0x497d
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
callq 0x2310
jmp 0x498f
movq %rax, %rbx
movq -0x270(%rbp), %rdi
cmpq %r13, %rdi
je 0x497d
callq 0x21b0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x498f
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0
nop