// File: /workspace/github_cpp_makefile_star2_O1/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, -0x2c(%rbp)
movq %rdx, %r15
movl %esi, %r14d
movq %rsp, %r13
movl (%rdi), %eax
movq %rsp, %rbx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
leaq -0x90(%rbp), %r12
movq %rdi, -0x40(%rbp)
movq %r12, %rsi
movl %r14d, %edx
callq 0x37c4
xorl %ecx, %ecx
xorl %eax, %eax
movsbl (%r12), %edx
shll %cl, %edx
addl %edx, %eax
addq $0x8, %rcx
incq %r12
cmpq $0x10, %rcx
jne 0x3628
testl %eax, %eax
je 0x36ea
xorl %ecx, %ecx
leaq -0x66(%rbp), %rax
xorl %edx, %edx
movsbl (%rax), %esi
shll %cl, %esi
addl %esi, %edx
incq %rax
addq $0x8, %rcx
cmpq $0x10, %rcx
jne 0x364e
movq -0x40(%rbp), %r14
leaq 0x8(%r14), %r12
addl $0x6, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x26d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0xc, (%r14)
jl 0x3753
movq %r12, -0x48(%rbp)
movq %r13, -0x38(%rbp)
movl $0x8, %r12d
xorl %r14d, %r14d
movl 0x8(%r15), %edx
addl %r14d, %edx
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rcx
callq 0x29ed
testb %al, %al
je 0x36cc
leal 0xa(%r14), %r13d
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x2a38
cmpl $0x1, %eax
je 0x3765
addq $0xc, %r12
leal 0xc(%r14), %eax
addl $0x18, %r14d
movq -0x40(%rbp), %rcx
cmpl (%rcx), %r14d
movl %eax, %r14d
jle 0x3698
movq -0x38(%rbp), %r13
jmp 0x374e
movq 0x98df(%rip), %rbx      # 0xcfd0
leaq 0x5d4c(%rip), %rsi      # 0x9444
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2240
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2330
movq %rax, %rbx
leaq 0x5d39(%rip), %rsi      # 0x9453
movl $0xd, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r13, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $0xc, %r14d
cmpb $0x0, -0x2c(%rbp)
je 0x37af
addq %rbx, %r12
movl $0x2, %eax
movb $0x0, (%r12)
incq %r12
decq %rax
jne 0x3777
xorl %ecx, %ecx
leaq -0x66(%rbp), %rax
xorl %edx, %edx
movsbl (%rax), %esi
shll %cl, %esi
addl %esi, %edx
incq %rax
addq $0x8, %rcx
cmpq $0x10, %rcx
jne 0x378c
addl $0x6, %edx
movq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x27d6
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x2a38
movq -0x38(%rbp), %r13
jmp 0x3753
nop