// File: jasperandrew[P]cs350-project2/./lab7.h
// Function: display(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int)
void display(string filename, int how_many, int start)
{
		int inode_num = getInodeNum(filename);
		if(inode_num == -1){
			cout << "File '" << filename << "' does not exist!\n";
			return;
		}
		
		int start_block = start/BLOCK_SZ;
		int start_offset = start % BLOCK_SZ;
		int bytes_read = 0;
		
		inode file_inode = readInode(inode_num);
		for(int i = start_block; i < MAX_FILE_BLOCKS; i++){
			if(file_inode.datablocks[i]){
				if(bytes_read < how_many){
					readData(file_inode.datablocks[i]);
					if(how_many - bytes_read >= BLOCK_SZ)
						printf("%.*s", BLOCK_SZ, block_buffer);
					else
						printf("%.*s", how_many-bytes_read, block_buffer);
				}else{
					cout << "\n\nComplete! (read " << how_many << " bytes)\n";
					return;
				}
			}else{
				cout << "\n\nReached end of file (read " << bytes_read << " bytes)\n";
				return;
			}
		}
		
		if(bytes_read < how_many)
			cout << "\n\nReached end of file (read " << bytes_read << " bytes)\n";
		else
			cout << "\n\nComplete! (read " << how_many << " bytes)\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movl %esi, %eax
movq %rdi, %rsi
movq %rsi, -0x358(%rbp)
movq %rsi, -0x8(%rbp)
movl %eax, -0xc(%rbp)
movl %edx, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x30f0
leaq -0x38(%rbp), %rdi
callq 0x44c0
movl %eax, -0x350(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3170
movl -0x350(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x5387
movq 0x7c70(%rip), %rdi      # 0xcfc8
leaq 0x3d5a(%rip), %rsi      # 0x90b9
callq 0x3220
movq -0x358(%rbp), %rsi
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
leaq 0x3d43(%rip), %rsi      # 0x90c0
callq 0x3220
jmp 0x5525
movl -0x10(%rbp), %eax
movl $0x400, %ecx            # imm = 0x400
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movl -0x10(%rbp), %eax
movl $0x400, %ecx            # imm = 0x400
cltd
idivl %ecx
movl %edx, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x14(%rbp), %esi
leaq -0x348(%rbp), %rdi
callq 0x40d0
movl -0x3c(%rbp), %eax
movl %eax, -0x34c(%rbp)
cmpl $0x80, -0x34c(%rbp)
jge 0x54c1
movslq -0x34c(%rbp), %rax
cmpl $0x0, -0x244(%rbp,%rax,4)
je 0x547c
movl -0x44(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x5448
movslq -0x34c(%rbp), %rax
movl -0x244(%rbp,%rax,4), %edi
callq 0x42f0
movl -0xc(%rbp), %eax
subl -0x44(%rbp), %eax
cmpl $0x400, %eax            # imm = 0x400
jl 0x542b
leaq 0x3cfb(%rip), %rdi      # 0x9111
movl $0x400, %esi            # imm = 0x400
leaq 0x107e7e(%rip), %rdx    # 0x10d2a0
movb $0x0, %al
callq 0x3050
jmp 0x5446
movl -0xc(%rbp), %esi
subl -0x44(%rbp), %esi
leaq 0x3cd9(%rip), %rdi      # 0x9111
leaq 0x107e61(%rip), %rdx    # 0x10d2a0
movb $0x0, %al
callq 0x3050
jmp 0x547a
movq 0x7b79(%rip), %rdi      # 0xcfc8
leaq 0x3cc0(%rip), %rsi      # 0x9116
callq 0x3220
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x3410
movq %rax, %rdi
leaq 0x3c98(%rip), %rsi      # 0x9108
callq 0x3220
jmp 0x5525
jmp 0x54ab
movq 0x7b45(%rip), %rdi      # 0xcfc8
leaq 0x3c9f(%rip), %rsi      # 0x9129
callq 0x3220
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x3410
movq %rax, %rdi
leaq 0x3c64(%rip), %rsi      # 0x9108
callq 0x3220
jmp 0x5525
jmp 0x54ad
movl -0x34c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34c(%rbp)
jmp 0x53c2
movl -0x44(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x54f8
movq 0x7af8(%rip), %rdi      # 0xcfc8
leaq 0x3c52(%rip), %rsi      # 0x9129
callq 0x3220
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x3410
movq %rax, %rdi
leaq 0x3c17(%rip), %rsi      # 0x9108
callq 0x3220
jmp 0x5525
movq 0x7ac9(%rip), %rdi      # 0xcfc8
leaq 0x3c10(%rip), %rsi      # 0x9116
callq 0x3220
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x3410
movq %rax, %rdi
leaq 0x3be8(%rip), %rsi      # 0x9108
callq 0x3220
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
nop