// File: hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::Inside_file2str(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool FileSystem::Inside_file2str(const string& filepath, string& str) {
	/*
		step 1: get dir inode number and filename
	*/
	string filename;
	int dir_inodeNum = Analysis_path(filepath, filename);
	if(dir_inodeNum == -1) {
		return false;
	}

	/*
		step 2: get file inode number and get the inode
	*/

	int file_inodeNum = Get_file_inodeNum_from_dir(dir_inodeNum, filename);
	if(file_inodeNum == -1) {
		return false;
	}

	char inode_buf[64];
	Get_inode_from_inodeNum(inode_buf, file_inodeNum);

	/*
		step 3: travel each data block, add to string until find EOF
	*/

	str.clear();
	char buf[BLKsize];
	for(int i = 42; i < 58; i += 2) {
		D.Getblk(buf, Get_actual_dataBLKnumber(byte2int(inode_buf, i, i + 2)));
		int pos = FindEOF(buf);
		if(pos == -1) {
			for(int j = 0; j < BLKsize; ++j) {
				str += buf[j];
			}
		} else {
			for(int j = 0; j < pos; ++j) {
				str += buf[j];
			}
			break;
		}
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x33e0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0x18(%rbp), %rsi
callq 0x65b0
movl %eax, -0xc4(%rbp)
jmp 0x88d1
movl -0xc4(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x890a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x8b0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3160
jmp 0x8b1e
movq -0xd8(%rbp), %rdi
movl -0x44(%rbp), %esi
leaq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x4d30
movl %eax, -0xdc(%rbp)
jmp 0x8927
movl -0xdc(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $-0x1, -0x5c(%rbp)
jne 0x8946
movb $0x0, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x8b0b
movq -0xd8(%rbp), %rdi
movl -0x5c(%rbp), %edx
leaq -0xa0(%rbp), %rsi
callq 0x4ff0
jmp 0x895e
movq -0x20(%rbp), %rdi
callq 0x33c0
movq -0xd8(%rbp), %rax
movl (%rax), %eax
movq %rsp, %rcx
movq %rcx, -0xa8(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xe8(%rbp)
movq %rcx, %rsp
movq %rax, -0xb0(%rbp)
movl $0x2a, -0xb4(%rbp)
cmpl $0x3a, -0xb4(%rbp)
jge 0x8af6
movq -0xd8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xf8(%rbp)
movl -0xb4(%rbp), %esi
movl %esi, %edx
addl $0x2, %edx
leaq -0xa0(%rbp), %rdi
callq 0x40e0
movl %eax, -0xec(%rbp)
jmp 0x89e4
movl -0xec(%rbp), %esi
movq -0xd8(%rbp), %rdi
callq 0x9390
movl %eax, -0xfc(%rbp)
jmp 0x89fe
movl -0xfc(%rbp), %edx
movq -0xe8(%rbp), %rsi
movq -0xf8(%rbp), %rdi
callq 0x3900
jmp 0x8a19
movq -0xe8(%rbp), %rsi
movq -0xd8(%rbp), %rdi
callq 0x53d0
movl %eax, -0x100(%rbp)
jmp 0x8a34
movl -0x100(%rbp), %eax
movl %eax, -0xb8(%rbp)
cmpl $-0x1, -0xb8(%rbp)
jne 0x8a96
movl $0x0, -0xbc(%rbp)
movq -0xd8(%rbp), %rcx
movl -0xbc(%rbp), %eax
cmpl (%rcx), %eax
jge 0x8a94
movq -0xe8(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movsbl (%rax,%rcx), %esi
movq -0x20(%rbp), %rdi
callq 0x3170
jmp 0x8a81
jmp 0x8a83
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x8a53
jmp 0x8ae0
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jge 0x8ade
movq -0xe8(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movsbl (%rax,%rcx), %esi
movq -0x20(%rbp), %rdi
callq 0x3170
jmp 0x8acb
jmp 0x8acd
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x8aa0
jmp 0x8af6
jmp 0x8ae2
movl -0xb4(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xb4(%rbp)
jmp 0x89a6
movb $0x1, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, %rsp
leaq -0x40(%rbp), %rdi
callq 0x3160
movb -0x1(%rbp), %al
andb $0x1, %al
movq %rbp, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x3490
nopw (%rax,%rax)