// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: follow_path
static
FRESULT follow_path (	/* FR_OK(0): successful, !=0: error code */
	DIR* dp,			/* Directory object to return last directory and found object */
	const TCHAR* path	/* Full-path string to find a file or directory */
)
{
	FRESULT res;
	BYTE ns;
	FATFS *fs = dp->obj.fs;


#if FF_FS_RPATH != 0
	if (*path != '/' && *path != '\\') {	/* Without heading separator */
		dp->obj.sclust = fs->cdir;				/* Start from current directory */
	} else
#endif
	{										/* With heading separator */
		while (*path == '/' || *path == '\\') path++;	/* Strip heading separator */
		dp->obj.sclust = 0;					/* Start from root directory */
	}
#if FF_FS_EXFAT
	dp->obj.n_frag = 0;	/* Invalidate last fragment counter of the object */
#if FF_FS_RPATH != 0
	if (fs->fs_type == FS_EXFAT && dp->obj.sclust) {	/* exFAT: Retrieve the sub-directory's status */
		DIR dj;

		dp->obj.c_scl = fs->cdc_scl;
		dp->obj.c_size = fs->cdc_size;
		dp->obj.c_ofs = fs->cdc_ofs;
		res = load_obj_xdir(&dj, &dp->obj);
		if (res != FR_OK) return res;
		dp->obj.objsize = ld_dword(fs->dirbuf + XDIR_FileSize);
		dp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2;
	}
#endif
#endif

	if ((UINT)*path < ' ') {				/* Null path name is the origin directory itself */
		dp->fn[NSFLAG] = NS_NONAME;
		res = dir_sdi(dp, 0);

	} else {								/* Follow path */
		for (;;) {
			res = create_name(dp, &path);	/* Get a segment name of the path */
			if (res != FR_OK) break;
			res = dir_find(dp);				/* Find an object with the segment name */
			ns = dp->fn[NSFLAG];
			if (res != FR_OK) {				/* Failed to find the object */
				if (res == FR_NO_FILE) {	/* Object is not found */
					if (FF_FS_RPATH && (ns & NS_DOT)) {	/* If dot entry is not exist, stay there */
						if (!(ns & NS_LAST)) continue;	/* Continue to follow if not last segment */
						dp->fn[NSFLAG] = NS_NONAME;
						res = FR_OK;
					} else {							/* Could not find the object */
						if (!(ns & NS_LAST)) res = FR_NO_PATH;	/* Adjust error code if not last segment */
					}
				}
				break;
			}
			if (ns & NS_LAST) break;			/* Last segment matched. Function completed. */
			/* Get into the sub-directory */
			if (!(dp->obj.attr & AM_DIR)) {		/* It is not a sub-directory and cannot follow */
				res = FR_NO_PATH; break;
			}
#if FF_FS_EXFAT
			if (fs->fs_type == FS_EXFAT) {		/* Save containing directory information for next dir */
				dp->obj.c_scl = dp->obj.sclust;
				dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
				dp->obj.c_ofs = dp->blk_ofs;
				init_alloc_info(fs, &dp->obj);	/* Open next directory */
			} else
#endif
			{
				dp->obj.sclust = ld_clust(fs, fs->win + dp->dptr % SS(fs));	/* Open next directory */
			}
		}
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rcx
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x1b58
cmpl $0x2f, %eax
jne 0x1b5d
incq %r14
jmp 0x1b4a
movq $0x0, 0x10(%rbx)
cmpb $0x20, (%r14)
jae 0x1b85
movb $-0x80, 0x4b(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d55
movq %rcx, -0x30(%rbp)
leaq 0x40(%rbx), %r13
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, (%r13)
movl $0x20202020, 0x7(%r13)  # imm = 0x20202020
movl $0x8, %edi
xorl %esi, %esi
xorl %r10d, %r10d
xorl %ecx, %ecx
leal 0x1(%r10), %eax
movl %r10d, %edx
movb (%r14,%rdx), %r9b
movb $0x4, %dl
cmpb $0x21, %r9b
jb 0x1d22
leal -0x1(%rdi), %r8d
xorl %r15d, %r15d
cmpb $0x2e, %r9b
je 0x1cd7
movzbl %r9b, %r11d
cmpl $0x5c, %r11d
je 0x1cff
cmpl $0x2f, %r11d
je 0x1cff
cmpl %edi, %ecx
jae 0x1cd7
cmpb $-0x80, %r9b
jbe 0x1c7a
cmpb $-0x60, %r9b
setb %r15b
leal 0x20(%r9), %r12d
cmpb $0x1d, %r12b
setb %r12b
orb %r15b, %r12b
cmpb $0x1, %r12b
jne 0x1c7a
movl %eax, %eax
movzbl (%r14,%rax), %r11d
cmpl $0x40, %r11d
jb 0x1c42
movb $0x1, %r12b
cmpb $0x7f, %r11b
jb 0x1c45
leal -0xfd(%r11), %eax
cmpl $0x3, %eax
jb 0x1c42
cmpl $0x7f, %r11d
jne 0x1c45
xorl %r12d, %r12d
movl $0x6, %eax
xorl %r15d, %r15d
testb %r12b, %r12b
je 0x1d49
cmpl %r8d, %ecx
jae 0x1d49
addl $0x2, %r10d
movl %ecx, %eax
movb %r9b, 0x40(%rbx,%rax)
movslq %ecx, %rax
addl $0x2, %ecx
movb %r11b, 0x41(%rbx,%rax)
movl %r10d, %eax
jmp 0x1cb9
leaq 0x3857(%rip), %r10      # 0x54d8
movsbl (%r10), %r15d
testl %r15d, %r15d
je 0x1c92
incq %r10
cmpl %r11d, %r15d
jne 0x1c81
testb %r15b, %r15b
jne 0x1d41
leal -0x61(%r9), %r10d
addb $-0x20, %r9b
cmpb $0x1a, %r10b
movzbl %r9b, %r9d
cmovbl %r9d, %r11d
movl %ecx, %r9d
incl %ecx
movb %r11b, (%r13,%r9)
movl %eax, %r10d
leal 0x1(%r10), %eax
movl %r10d, %r9d
movb (%r14,%r9), %r9b
cmpb $0x21, %r9b
setb %r15b
jae 0x1bcd
jmp 0x1d1d
cmpb $0x2e, %r9b
setne %cl
orb %cl, %sil
movl $0x8, %ecx
movl $0xb, %edi
movl %eax, %r10d
testb $0x1, %sil
movb $0x1, %sil
je 0x1baf
jmp 0x1d41
incl %eax
movl %eax, %edx
movzbl (%r14,%rdx), %edx
cmpl $0x5c, %edx
je 0x1cfd
cmpl $0x2f, %edx
je 0x1cfd
andb $0x1, %r15b
shlb $0x2, %r15b
movl %r15d, %edx
jmp 0x1d22
movl $0x1, %ecx
movl %eax, %eax
addq %rax, %r14
testl %ecx, %ecx
je 0x1d41
cmpb $-0x1b, (%r13)
jne 0x1d37
movb $0x5, (%r13)
movb %dl, 0x4b(%rbx)
xorl %eax, %eax
movb $0x1, %r15b
jmp 0x1d49
movl $0x6, %eax
xorl %r15d, %r15d
testb %r15b, %r15b
je 0x1e1d
movq (%rbx), %r15
movq %rbx, %rdi
callq 0x2d55
testl %eax, %eax
jne 0x1dba
movq 0x30(%rbx), %rsi
movq %r15, %rdi
callq 0x1f73
testl %eax, %eax
jne 0x1dba
movq 0x38(%rbx), %rax
cmpb $0x0, (%rax)
je 0x1db1
movb 0xb(%rax), %cl
andb $0x3f, %cl
movb %cl, 0xa(%rbx)
testb $0x8, 0xb(%rax)
jne 0x1da5
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb (%r13,%rcx), %sil
cmpl $0xa, %ecx
je 0x1da0
incq %rcx
cmpb %sil, %dl
je 0x1d8b
cmpb %sil, %dl
je 0x1db8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2fee
jmp 0x1d5d
movl $0x4, %eax
jmp 0x1dba
xorl %eax, %eax
movb 0x4b(%rbx), %cl
testl %eax, %eax
movq -0x30(%rbp), %rsi
jne 0x1e02
testb $0x4, %cl
jne 0x1e14
testb $0x10, 0xa(%rbx)
je 0x1e18
movq 0x20(%rbx), %rcx
andl $0x1ff, %ecx            # imm = 0x1FF
movzwl 0x72(%rsi,%rcx), %eax
cmpb $0x3, (%rsi)
jne 0x1df9
movzbl 0x6c(%rsi,%rcx), %edx
movzbl 0x6d(%rsi,%rcx), %ecx
shll $0x18, %ecx
shll $0x10, %edx
orl %ecx, %edx
orq %rdx, %rax
movq %rax, 0x10(%rbx)
jmp 0x1b8d
cmpl $0x4, %eax
jne 0x1e1d
andb $0x4, %cl
xorl %eax, %eax
cmpb $0x1, %cl
adcl $0x4, %eax
jmp 0x1e1d
xorl %eax, %eax
jmp 0x1e1d
movl $0x5, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq