// File: /workspace/github_c_makefile_star2_O3/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: dir_next
static
FRESULT dir_next (	/* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
	DIR* dp,		/* Pointer to the directory object */
	int stretch		/* 0: Do not stretch table, 1: Stretch table if needed */
)
{
	DWORD ofs, clst;
	FATFS *fs = dp->obj.fs;


	ofs = dp->dptr + SZDIRE;	/* Next entry */
	if (dp->sect == 0 || ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR)) return FR_NO_FILE;	/* Report EOT when offset has reached max value */

	if (ofs % SS(fs) == 0) {	/* Sector changed? */
		dp->sect++;				/* Next sector */

		if (dp->clust == 0) {	/* Static table */
			if (ofs / SZDIRE >= fs->n_rootdir) {	/* Report EOT if it reached end of static table */
				dp->sect = 0; return FR_NO_FILE;
			}
		}
		else {					/* Dynamic table */
			if ((ofs / SS(fs) & (fs->csize - 1)) == 0) {	/* Cluster changed? */
				clst = get_fat(&dp->obj, dp->clust);		/* Get next cluster */
				if (clst <= 1) return FR_INT_ERR;			/* Internal error */
				if (clst == 0xFFFFFFFF) return FR_DISK_ERR;	/* Disk error */
				if (clst >= fs->n_fatent) {					/* It reached end of dynamic table */
#if !FF_FS_READONLY
					if (!stretch) {								/* If no stretch, report EOT */
						dp->sect = 0; return FR_NO_FILE;
					}
					clst = create_chain(&dp->obj, dp->clust);	/* Allocate a cluster */
					if (clst == 0) return FR_DENIED;			/* No free cluster */
					if (clst == 1) return FR_INT_ERR;			/* Internal error */
					if (clst == 0xFFFFFFFF) return FR_DISK_ERR;	/* Disk error */
					if (dir_clear(fs, clst) != FR_OK) return FR_DISK_ERR;	/* Clean up the stretched table */
					if (FF_FS_EXFAT) dp->obj.stat |= 4;			/* exFAT: The directory has been stretched */
#else
					if (!stretch) dp->sect = 0;					/* (this line is to suppress compiler warning) */
					dp->sect = 0; return FR_NO_FILE;			/* Report EOT */
#endif
				}
				dp->clust = clst;		/* Initialize data for new cluster */
				dp->sect = clst2sect(fs, clst);
			}
		}
	}
	dp->dptr = ofs;						/* Current entry */
	dp->dir = fs->win + ofs % SS(fs);	/* Pointer to the entry in the win[] */

	return FR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x20(%rdi), %r12
addq $0x20, %r12
movq 0x30(%rdi), %rax
testq %rax, %rax
sete %cl
cmpq $0x200000, %r12         # imm = 0x200000
setae %dl
orb %cl, %dl
movl $0x4, %r15d
jne 0x3023
movq %rdi, %rbx
movq (%rdi), %rdi
movq %r12, %r14
andq $0x1ff, %r14            # imm = 0x1FF
je 0x3035
movq %r12, 0x20(%rbx)
leaq (%rdi,%r14), %rax
addq $0x58, %rax
movq %rax, 0x38(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r13d
incq %rax
movq %rax, 0x30(%rbx)
movq 0x28(%rbx), %rsi
movq %r12, %rax
testq %rsi, %rsi
je 0x30ae
shrq $0x9, %rax
movzwl 0xa(%rdi), %ecx
addl $0xfff, %ecx            # imm = 0xFFF
testl %eax, %ecx
jne 0x3010
movq %rdi, -0x30(%rbp)
callq 0x1fb2
movl $0x2, %r15d
cmpq $0x2, %rax
jb 0x3023
movl $0x1, %r15d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x3023
movq -0x30(%rbp), %rdi
movq 0x20(%rdi), %rcx
cmpq %rcx, %rax
jae 0x30cc
movq %rax, 0x28(%rbx)
addq $-0x2, %rax
addq $-0x2, %rcx
cmpq %rcx, %rax
jae 0x3105
movzwl 0xa(%rdi), %ecx
imulq %rcx, %rax
addq 0x48(%rdi), %rax
jmp 0x3107
shrq $0x5, %rax
movzwl 0x8(%rdi), %ecx
cmpq %rcx, %rax
jb 0x3010
movq $0x0, 0x30(%rbx)
jmp 0x3023
testl %r13d, %r13d
je 0x3110
movq 0x28(%rbx), %rsi
movq %rbx, %rdi
callq 0x26be
testq %rax, %rax
je 0x3123
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
movq -0x30(%rbp), %r13
je 0x3023
cmpq $0x1, %rax
jne 0x312e
movl $0x2, %r15d
jmp 0x3023
xorl %eax, %eax
movq %rax, 0x30(%rbx)
jmp 0x3010
movq $0x0, 0x30(%rbx)
movl $0x4, %r15d
jmp 0x3023
movl $0x7, %r15d
jmp 0x3023
movq %r13, %rdi
movq %rax, %rsi
movq %rax, -0x38(%rbp)
callq 0x37fb
testl %eax, %eax
jne 0x3023
movq 0x20(%r13), %rcx
movq %r13, %rdi
movq -0x38(%rbp), %rax
jmp 0x308f