// File: /workspace/github_cpp_makefile_star2_O1/jasperandrew[P]cs350-project2/./lab7.h
// Function: readData(unsigned int)
void readData(block_num num)
{
		for(int i = 0; i < BLOCK_SZ; i++) block_buffer[i] = 0;
	
    int seg_idx = num/BLOCK_SZ;
    int seg_block = num % BLOCK_SZ;

    if(seg_idx == current_segment){
        memcpy(block_buffer, wbuffer.getBlock(seg_block-1)->getData(), BLOCK_SZ);
    }else{
        string seg_path = "DRIVE/SEGMENT" + to_string(seg_idx+1);
        ifstream segment(seg_path, ios::in | ios::binary);
        segment.seekg(BLOCK_SZ * (seg_block-1));

				segment.read(block_buffer, BLOCK_SZ);
        segment.close();
		}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl %edi, %r15d
leaq 0x1060f9(%rip), %rdi    # 0x109250
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x2100
movl %r15d, %ebx
shrl $0xa, %ebx
movl %r15d, %r12d
andl $0x3ff, %r12d           # imm = 0x3FF
cmpl 0x1060cb(%rip), %ebx    # 0x109244
jne 0x31b0
movl %r12d, %eax
leaq 0x17459b(%rip), %rcx    # 0x177720
movq -0x8(%rcx,%rax,8), %rsi
addq $0x4, %rsi
leaq 0x1060bb(%rip), %rdi    # 0x109250
movl $0x400, %edx            # imm = 0x400
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2170
incl %ebx
movl $0x1, %r14d
cmpl $0x2400, %r15d          # imm = 0x2400
jb 0x320a
movl $0x4, %r14d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x3201
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x3207
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x320a
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r14d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x31ce
addl $-0x3, %r14d
jmp 0x320a
addl $-0x2, %r14d
jmp 0x320a
decl %r14d
movl %r14d, %esi
leaq -0x240(%rbp), %r13
movq %r13, -0x10(%r13)
leaq -0x250(%rbp), %r15
movq %r15, %rdi
movl $0x2d, %edx
callq 0x2250
movq (%r15), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x54a4
leaq 0x2dd4(%rip), %rcx      # 0x6014
movl $0xd, %r8d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3276
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x327d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x250(%rbp), %rdi
cmpq %r13, %rdi
je 0x32a5
callq 0x21b0
leaq -0x250(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0xc, %edx
callq 0x2360
shll $0xa, %r12d
addl $0xfffffc00, %r12d      # imm = 0xFFFFFC00
movslq %r12d, %rsi
leaq -0x250(%rbp), %rdi
xorl %edx, %edx
callq 0x22a0
leaq 0x105f73(%rip), %rsi    # 0x109250
leaq -0x250(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2290
leaq -0x250(%rbp), %rdi
callq 0x2060
leaq -0x250(%rbp), %rdi
callq 0x2070
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3314
callq 0x21b0
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x334b
movq %rax, %rbx
movq -0x250(%rbp), %rdi
cmpq %r13, %rdi
jne 0x3354
jmp 0x3359
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
callq 0x2070
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3359
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0