// File: /workspace/github_cpp_makefile_star2_O3/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 -0x60(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq -0x70(%rbp), %rdx
movq %r15, %rsi
callq 0x4e5e
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x63d0
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x35dc
cmpl $-0x1, %eax
je 0x60c2
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3650(%rip), %rsi      # 0x96c2
leaq 0x364d(%rip), %rdx      # 0x96c6
leaq -0xc8(%rbp), %rdi
callq 0x2920
leaq -0xc8(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x487e
movl %eax, %r13d
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x60b5
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2200
testb %r13b, %r13b
leaq -0x60(%rbp), %r14
je 0x63a4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x45fc
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x35dc
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %r14
movq 0x8(%r14), %rsi
movslq (%rbx), %rcx
leaq (,%rcx,8), %rdi
xorl %eax, %eax
cmpq %rdi, %rsi
setne %al
addq %rsi, %rax
xorl %edx, %edx
divq %rcx
movq %rax, -0x38(%rbp)
cmpq %rdi, %rsi
je 0x611c
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x21b0
movl (%rbx), %ecx
movq %rsp, -0x78(%rbp)
movl %ecx, %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 0x3d48
movq 0x8(%r14), %rax
movl $0x400, %ecx            # imm = 0x400
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %eax, %eax
jle 0x617b
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 0x616a
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 0x61c4
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
movsbl -0xe6(%rbp), %eax
movsbl -0xe5(%rbp), %ecx
shll $0x8, %ecx
leaq 0x8(%rbx), %rdi
leal (%rcx,%rax), %edx
addl $0x6, %edx
movq %rdi, -0x80(%rbp)
movq %r13, %rsi
callq 0x27e6
movq %rbx, -0x48(%rbp)
cmpl $0x2, -0x38(%rbp)
jl 0x637a
movq -0x38(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x38(%rbp)
movl $0x1, %r14d
leaq -0xe4(%rbp), %rbx
leaq -0xa8(%rbp), %r12
movq -0x40(%rbp), %r15
xorl %ecx, %ecx
xorl %edx, %edx
movq -0x48(%rbp), %rax
movsbl 0x5a(%rax,%rdx), %esi
cmpl $-0x1, %esi
je 0x6244
xorl %eax, %eax
movl $0x1, %edi
testl %esi, %edi
je 0x6257
incl %eax
addl %edi, %edi
cmpl $0x8, %eax
jne 0x6237
incq %rdx
addl $-0x8, %ecx
cmpq $0x50, %rdx
jne 0x6222
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x6259
subl %ecx, %eax
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
movq -0x48(%rbp), %rcx
orb %dl, 0x5a(%rcx,%rsi)
leal 0x2a(,%r14,2), %ecx
movl %ecx, -0x4c(%rbp)
leaq 0x2c(,%r14,2), %rcx
movq %rcx, -0x88(%rbp)
xorl %ecx, %ecx
movb %al, (%rbx,%rcx)
leal 0xff(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x8, %edx
incq %rcx
movl %edx, %eax
cmpq $0x2, %rcx
jne 0x62a6
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x400, %ecx            # imm = 0x400
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %eax, %eax
jle 0x6300
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), %dil
movb %dil, (%r13,%rsi)
incq %rsi
cmpq %rax, %rsi
jb 0x62ef
movslq %ecx, %rdx
movq %r12, %rdi
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 0x6342
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x110(%rbp), %rdi
movl -0x4c(%rbp), %esi
movq -0x88(%rbp), %rdx
callq 0x2a36
addl $0x6, %eax
movq -0x80(%rbp), %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x27e6
incq %r14
addq $0x2, %rbx
cmpq -0x38(%rbp), %r14
jb 0x621e
leaq -0x110(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
leaq -0x60(%rbp), %r14
callq 0x5f58
movq %rbx, %rdi
callq 0x3ed6
movq -0x78(%rbp), %rsp
movb $0x1, %bl
jmp 0x63d2
movq 0x6c25(%rip), %rdi      # 0xcfd0
leaq 0x3315(%rip), %rsi      # 0x96c7
movl $0x1b, %edx
callq 0x2240
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq 0x6c05(%rip), %rdi      # 0xcfd0
callq 0x2240
xorl %ebx, %ebx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x63e7
movq -0x60(%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 0x6426
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x6429
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x6429
jmp 0x6426
jmp 0x6426
jmp 0x6426
jmp 0x6426
jmp 0x6426
jmp 0x6426
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x6442
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2350