// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
addq $0x20, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x44ff
cmpq $0x200000, -0x20(%rbp)  # imm = 0x200000
jb 0x450b
movl $0x4, -0x4(%rbp)
jmp 0x46c2
movq -0x20(%rbp), %rax
andq $0x1ff, %rax            # imm = 0x1FF
cmpq $0x0, %rax
jne 0x4692
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x456c
movq -0x20(%rbp), %rax
shrq $0x5, %rax
movq -0x30(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jb 0x4567
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
movl $0x4, -0x4(%rbp)
jmp 0x46c2
jmp 0x4690
movq -0x20(%rbp), %rax
shrq $0x9, %rax
movq -0x30(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x468e
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x29e0
movq %rax, -0x28(%rbp)
cmpq $0x1, -0x28(%rbp)
ja 0x45b7
movl $0x2, -0x4(%rbp)
jmp 0x46c2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x28(%rbp)
jne 0x45ce
movl $0x1, -0x4(%rbp)
jmp 0x46c2
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jb 0x466a
cmpl $0x0, -0x14(%rbp)
jne 0x45fe
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
movl $0x4, -0x4(%rbp)
jmp 0x46c2
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x3540
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4626
movl $0x7, -0x4(%rbp)
jmp 0x46c2
cmpq $0x1, -0x28(%rbp)
jne 0x4639
movl $0x2, -0x4(%rbp)
jmp 0x46c2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x28(%rbp)
jne 0x464d
movl $0x1, -0x4(%rbp)
jmp 0x46c2
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4ff0
cmpl $0x0, %eax
je 0x4668
movl $0x1, -0x4(%rbp)
jmp 0x46c2
jmp 0x466a
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2bd0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x4690
jmp 0x4692
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rcx
addq $0x58, %rcx
movq -0x20(%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
nopl (%rax,%rax)