// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: dir_sdi
static
FRESULT dir_sdi (	/* FR_OK(0):succeeded, !=0:error */
	DIR* dp,		/* Pointer to directory object */
	DWORD ofs		/* Offset of directory table */
)
{
	DWORD csz, clst;
	FATFS *fs = dp->obj.fs;


	if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR) || ofs % SZDIRE) {	/* Check range of offset and alignment */
		return FR_INT_ERR;
	}
	dp->dptr = ofs;				/* Set current offset */
	clst = dp->obj.sclust;		/* Table start cluster (0:root) */
	if (clst == 0 && fs->fs_type >= FS_FAT32) {	/* Replace cluster# 0 with root cluster# */
		clst = fs->dirbase;
		if (FF_FS_EXFAT) dp->obj.stat = 0;	/* exFAT: Root dir has an FAT chain */
	}

	if (clst == 0) {	/* Static table (root-directory on the FAT volume) */
		if (ofs / SZDIRE >= fs->n_rootdir) return FR_INT_ERR;	/* Is index out of range? */
		dp->sect = fs->dirbase;

	} else {			/* Dynamic table (sub-directory or root-directory on the FAT32/exFAT volume) */
		csz = (DWORD)fs->csize * SS(fs);	/* Bytes per cluster */
		while (ofs >= csz) {				/* Follow cluster chain */
			clst = get_fat(&dp->obj, clst);				/* Get next cluster */
			if (clst == 0xFFFFFFFF) return FR_DISK_ERR;	/* Disk error */
			if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR;	/* Reached to end of table or internal error */
			ofs -= csz;
		}
		dp->sect = clst2sect(fs, clst);
	}
	dp->clust = clst;					/* Current cluster# */
	if (dp->sect == 0) return FR_INT_ERR;
	dp->sect += ofs / SS(fs);			/* Sector# of the directory entry */
	dp->dir = fs->win + (ofs % SS(fs));	/* Pointer to the entry in the win[] */

	return FR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x200000, -0x18(%rbp)  # imm = 0x200000
jae 0x4053
movq -0x18(%rbp), %rax
andq $0x1f, %rax
cmpq $0x0, %rax
je 0x405f
movl $0x2, -0x4(%rbp)
jmp 0x41b7
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4096
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jl 0x4096
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x40d3
movq -0x18(%rbp), %rax
shrq $0x5, %rax
movq -0x30(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jb 0x40be
movl $0x2, -0x4(%rbp)
jmp 0x41b7
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x415f
movq -0x30(%rbp), %rax
movzwl 0xa(%rax), %eax
shlq $0x9, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x4147
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x29e0
movq %rax, -0x28(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x28(%rbp)
jne 0x4115
movl $0x1, -0x4(%rbp)
jmp 0x41b7
cmpq $0x2, -0x28(%rbp)
jb 0x412a
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jb 0x4136
movl $0x2, -0x4(%rbp)
jmp 0x41b7
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x40e3
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2bd0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x417f
movl $0x2, -0x4(%rbp)
jmp 0x41b7
movq -0x18(%rbp), %rcx
shrq $0x9, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rcx
addq $0x58, %rcx
movq -0x18(%rbp), %rax
andq $0x1ff, %rax            # imm = 0x1FF
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq