// File: /workspace/github_cpp_makefile_star2_O2/hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::Get_file_inodeNum_from_dir(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
int FileSystem::Get_file_inodeNum_from_dir(int dir_inodeNum, const string& filename, bool isDelete) {
	char inode_buf[64], buf[BLKsize];
	
	if(!Get_inode_from_inodeNum(inode_buf, dir_inodeNum)) {
		cout << "[Error] Cannot get inode: " << dir_inodeNum << endl;
		return -1;
	}

	// if inode doesn't point to a directory
	if(byte2int(inode_buf, 0, 2) == 0) {
		cout << "[Error] Inode " << dir_inodeNum << " is not a dir" << endl;
		return -1;
	}

	// get the directory data block
	D.Getblk(buf, Get_actual_dataBLKnumber(byte2int(inode_buf, 42, 44)));

	for(int i = 0; i + 12 <= BLKsize; i += 12) {
		// check if filename EQU
		if(byteEQUstring(buf, i, i + (int)filename.size(), filename)) {
			// check if is used
			if(byte2int(buf, i + 8, i + 10) == 1) {
				// return inodeNum
                if (isDelete) {
                    Fill_byte_by_num(buf, i + 8, i + 10, 0);
                    D.Putblk(buf, Get_actual_dataBLKnumber(byte2int(inode_buf, 42, 44)));
                }
				return byte2int(buf, i + 10, i + 12);
			}
		}
	}

	// not found
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, -0x3c(%rbp)
movq %rdx, -0x50(%rbp)
movl %esi, %r15d
movq %rdi, %rbx
movq %rsp, -0x38(%rbp)
movl (%rdi), %eax
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
leaq -0x90(%rbp), %r13
movq %r13, %rsi
movl %r15d, %edx
callq 0x3176
xorl %r14d, %r14d
pushq $0x2
popq %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2917
testl %eax, %eax
je 0x30d4
leaq 0x8(%rbx), %r15
leaq -0x90(%rbp), %rdi
pushq $0x2a
popq %rsi
pushq $0x2c
popq %rdx
callq 0x2917
leal 0x6(%rax), %edx
movq %r15, -0x48(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2648
movq %r12, %rsi
movq %rbx, %r12
movq %rsi, -0x30(%rbp)
leal 0xc(%r14), %ebx
cmpl (%r12), %ebx
jg 0x30c8
movq -0x50(%rbp), %rdi
movl 0x8(%rdi), %ecx
addl %r14d, %ecx
movl %r14d, %edx
callq 0x28d0
testb %al, %al
je 0x30bf
leal 0x8(%r14), %r13d
leal 0xa(%r14), %r15d
movq -0x30(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2917
cmpl $0x1, %eax
je 0x3112
movl %ebx, %r14d
movq -0x30(%rbp), %rsi
jmp 0x3083
movq -0x38(%rbp), %rbx
pushq $-0x1
popq %rax
jmp 0x3164
movq 0x7ef5(%rip), %rdi      # 0xafd0
leaq 0x4362(%rip), %rsi      # 0x7444
callq 0x21d0
movq %rax, %rdi
movl %r15d, %esi
callq 0x2330
leaq 0x435a(%rip), %rsi      # 0x7453
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $-0x1
popq %rax
movq -0x38(%rbp), %rbx
jmp 0x3164
addl $0xc, %r14d
cmpb $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rbx
je 0x3155
movq -0x30(%rbp), %r12
movq %r12, %rdi
movl %r13d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x2b1c
leaq -0x90(%rbp), %rdi
pushq $0x2a
popq %rsi
pushq $0x2c
popq %rdx
callq 0x2917
leal 0x6(%rax), %edx
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x271c
movq -0x30(%rbp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2917
movq %rbx, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq