// File: /workspace/github_cpp_makefile_star2_O1/hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::str2Inside_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool FileSystem::str2Inside_file(string& file_data, const string& filepath) {
	/* 
        step 1: find the right directory
    */

	string filename;
    int dir_inodeNum = Analysis_path(filepath, filename);
    if(dir_inodeNum == -1) {
    	return false;
    }

    /*
        step 2: test if there is file having the same name
    */

    // exist file, delete to clear bitmap
	if(Get_file_inodeNum_from_dir(dir_inodeNum, filename) != -1) {
		if(!DeleteFile(filepath)) {
			cout << "[Error] Cannot delete file " << filename;
			return false;
		}
	}
	CreateFile(filepath);
	int file_inodeNum = Get_file_inodeNum_from_dir(dir_inodeNum, filename);

	/*
		step 3: allocate data blocks
	*/

	// EOF
	int BLKnum = (file_data.length() + (file_data.length() != 8 * BLKsize)) / BLKsize;
	char _EOF = -1;
	if(file_data.length() != 8 * BLKsize) {
		file_data += _EOF;
	}

	char buf[BLKsize], inode_buf[64];

	// first BLK
	Get_inode_from_inodeNum(inode_buf, file_inodeNum);
	Fill_byte_by_str(buf, 0, min(1024, (int)file_data.length()), file_data);
	file_data = file_data.substr(min(1024, (int)file_data.length()));
	D.Putblk(buf, Get_actual_dataBLKnumber(byte2int(inode_buf, 42, 44)));

	for(int i = 1; i < BLKnum; ++i) {
		// find an empty data block
		int next_dataBLKNum = Find_empty_dataBLKNum();
		// set data block bitmap
		Fill_data_block_bitmap(next_dataBLKNum, true);
		// change inode.data_block_number
		Fill_byte_by_num(inode_buf, 42 + 2 * i, 44 + 2 * i, next_dataBLKNum);
		// write data
		Fill_byte_by_str(buf, 0, min(1024, (int)file_data.length()), file_data);
		// cut str
		file_data = file_data.substr(min(1024, (int)file_data.length()));
		D.Putblk(buf, Get_actual_dataBLKnumber(byte2int(inode_buf, 42 + 2 * i, 44 + 2 * i)));
	}

	PutInode(inode_buf, file_inodeNum);
	Save_superBLK();

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %r15
movq %rsi, -0x40(%rbp)
movq %rdi, %rbx
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq -0x68(%rbp), %rdx
movq %r15, %rsi
callq 0x48f6
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x5e4a
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x35de
cmpl $-0x1, %eax
je 0x5b66
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3b1b(%rip), %rsi      # 0x9631
leaq 0x3b18(%rip), %rdx      # 0x9635
leaq -0xc8(%rbp), %rdi
callq 0x2910
leaq -0xc8(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x42ee
movl %eax, %r13d
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x5b59
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2200
testb %r13b, %r13b
leaq -0x58(%rbp), %r14
je 0x5e1e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x406c
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x35de
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %r14
movq 0x8(%r14), %rcx
movslq (%rbx), %rsi
leaq (,%rsi,8), %rdi
xorl %eax, %eax
cmpq %rdi, %rcx
setne %al
addq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, -0x38(%rbp)
cmpq %rdi, %rcx
je 0x5bbe
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x21b0
movq %rsp, -0x78(%rbp)
movl (%rbx), %eax
movq %rsp, %r13
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
leaq -0x110(%rbp), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x37c4
movq 0x8(%r14), %rax
movl $0x400, %ecx            # imm = 0x400
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %eax, %eax
jle 0x5c1d
movl %ecx, %esi
movq (%r14), %rdx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
cmovbq %rsi, %rax
xorl %esi, %esi
movb (%rdx,%rsi), %dil
movb %dil, (%r13,%rsi)
incq %rsi
cmpq %rax, %rsi
jb 0x5c0c
movslq %ecx, %rdx
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
movq $-0x1, %rcx
callq 0x2220
leaq -0xa8(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2260
movq (%r15), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x5c66
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
xorl %ecx, %ecx
leaq -0xe6(%rbp), %rax
xorl %edx, %edx
movsbl (%rax), %esi
shll %cl, %esi
addl %esi, %edx
incq %rax
addq $0x8, %rcx
cmpq $0x10, %rcx
jne 0x5c71
leaq 0x8(%rbx), %rdi
addl $0x6, %edx
movq %rdi, -0x80(%rbp)
movq %r13, %rsi
callq 0x27d6
movq %rbx, -0x70(%rbp)
cmpl $0x2, -0x38(%rbp)
jl 0x5df4
movq -0x38(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x38(%rbp)
movl $0x1, %ebx
leaq -0xe4(%rbp), %r14
leaq -0xa8(%rbp), %r12
movq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0x38a6
movslq %eax, %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rdx
addl %esi, %edx
movslq %edx, %rsi
shll $0x4, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %ecx
movl $0x1, %edx
shll %cl, %edx
orb %dl, 0x5a(%r15,%rsi)
leal 0x2a(,%rbx,2), %ecx
movl %ecx, -0x44(%rbp)
leaq 0x2c(,%rbx,2), %rcx
movq %rcx, -0x88(%rbp)
xorl %ecx, %ecx
movb %al, (%r14,%rcx)
leal 0xff(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x8, %edx
incq %rcx
movl %edx, %eax
cmpq $0x2, %rcx
jne 0x5d1b
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x400, %ecx            # imm = 0x400
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %eax, %eax
jle 0x5d76
movl %ecx, %esi
movq -0x40(%rbp), %rdx
movq (%rdx), %rdx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
cmovbq %rsi, %rax
xorl %esi, %esi
movb (%rdx,%rsi), %r8b
movb %r8b, (%r13,%rsi)
incq %rsi
cmpq %rax, %rsi
jb 0x5d65
movslq %ecx, %rdx
movq %r12, %rdi
movq -0x40(%rbp), %r15
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2220
movq %r15, %rdi
movq %r12, %rsi
callq 0x2260
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x5dbc
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x110(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x88(%rbp), %rdx
callq 0x2a38
addl $0x6, %eax
movq -0x80(%rbp), %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x27d6
incq %rbx
addq $0x2, %r14
cmpq -0x38(%rbp), %rbx
jb 0x5cc6
leaq -0x110(%rbp), %rsi
movq -0x70(%rbp), %rbx
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
leaq -0x58(%rbp), %r14
callq 0x59fc
movq %rbx, %rdi
callq 0x3996
movq -0x78(%rbp), %rsp
movb $0x1, %bl
jmp 0x5e4c
movq 0x71ab(%rip), %rdi      # 0xcfd0
leaq 0x380a(%rip), %rsi      # 0x9636
movl $0x1b, %edx
callq 0x2240
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x718b(%rip), %rdi      # 0xcfd0
callq 0x2240
xorl %ebx, %ebx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x5e61
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movl %ebx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ea0
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x5ea3
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x5ea3
jmp 0x5ea0
jmp 0x5ea0
jmp 0x5ea0
jmp 0x5ea0
jmp 0x5ea0
jmp 0x5ea0
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5ebc
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2350