// File: /workspace/github_c_makefile_star2_O3/lb3361[P]dosfs/ff.c
// Function: f_forward
FRESULT f_forward (
	FIL* fp, 						/* Pointer to the file object */
	UINT (*func)(const BYTE*,UINT),	/* Pointer to the streaming function */
	UINT btf,						/* Number of bytes to forward */
	UINT* bf						/* Pointer to number of bytes forwarded */
)
{
	FRESULT res;
	FATFS *fs;
	DWORD clst;
	LBA_t sect;
	FSIZE_t remain;
	UINT rcnt, csect;
	BYTE *dbuf;


	*bf = 0;	/* Clear transfer byte counter */
	res = validate(&fp->obj, &fs);		/* Check validity of the file object */
	if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);
	if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED);	/* Check access mode */

	remain = fp->obj.objsize - fp->fptr;
	if (btf > remain) btf = (UINT)remain;			/* Truncate btf by remaining bytes */

	for ( ;  btf && (*func)(0, 0);					/* Repeat until all data transferred or stream goes busy */
		fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) {
		csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1));	/* Sector offset in the cluster */
		if (fp->fptr % SS(fs) == 0) {				/* On the sector boundary? */
			if (csect == 0) {						/* On the cluster boundary? */
				clst = (fp->fptr == 0) ?			/* On the top of the file? */
					fp->obj.sclust : get_fat(&fp->obj, fp->clust);
				if (clst <= 1) ABORT(fs, FR_INT_ERR);
				if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
				fp->clust = clst;					/* Update current cluster */
			}
		}
		sect = clst2sect(fs, fp->clust);			/* Get current data sector */
		if (sect == 0) ABORT(fs, FR_INT_ERR);
		sect += csect;
#if FF_FS_TINY
		if (move_window(fs, sect) != FR_OK) ABORT(fs, FR_DISK_ERR);	/* Move sector window to the file data */
		dbuf = fs->win;
#else
		if (fp->sect != sect) {		/* Fill sector cache with file data */
#if !FF_FS_READONLY
			if (fp->flag & FA_DIRTY) {		/* Write-back dirty sector cache */
				if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
				fp->flag &= (BYTE)~FA_DIRTY;
			}
#endif
			if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
		}
		dbuf = fp->buf;
#endif
		fp->sect = sect;
		rcnt = SS(fs) - (UINT)fp->fptr % SS(fs);	/* Number of bytes remains in the sector */
		if (rcnt > btf) rcnt = btf;					/* Clip it by btr if needed */
		rcnt = (*func)(dbuf + ((UINT)fp->fptr % SS(fs)), rcnt);	/* Forward the file data */
		if (rcnt == 0) ABORT(fs, FR_INT_ERR);
	}

	LEAVE_FF(fs, FR_OK);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movl $0x0, (%rcx)
leaq 0x20(%rsp), %rsi
callq 0x65ec
movl %eax, %r12d
testl %eax, %eax
jne 0x93cb
movzbl 0x31(%rbx), %r12d
testl %r12d, %r12d
jne 0x93cb
movl $0x7, %r12d
testb $0x1, 0x30(%rbx)
je 0x93cb
movq 0x10(%rbx), %r13
subq 0x38(%rbx), %r13
movl %ebp, %eax
cmpq %rax, %r13
cmovael %ebp, %r13d
testl %r13d, %r13d
je 0x938d
movq 0x20(%rsp), %rbp
leaq 0x60(%rbx), %rax
movq %rax, 0x8(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
xorl %edi, %edi
xorl %esi, %esi
callq *%r15
testl %eax, %eax
je 0x93cb
movq 0x38(%rbx), %rax
movq %rax, %rcx
shrq $0x9, %rcx
movzwl 0xa(%rbp), %edx
decl %edx
movl %eax, %esi
andl $0x1ff, %esi            # imm = 0x1FF
andl %edx, %ecx
movl %ecx, %r15d
orq %r15, %rsi
jne 0x92a5
testq %rax, %rax
je 0x92aa
movl 0x40(%rbx), %esi
movq %rbx, %rdi
callq 0x616a
jmp 0x92ad
movl 0x40(%rbx), %eax
jmp 0x92c2
movl 0xc(%rbx), %eax
cmpl $0x2, %eax
jb 0x9392
cmpl $-0x1, %eax
je 0x93b0
movl %eax, 0x40(%rbx)
addl $-0x2, %eax
movl 0x28(%rbp), %ecx
addl $-0x2, %ecx
cmpl %ecx, %eax
jae 0x9392
movl $0x2, 0x4(%rsp)
movb $0x2, 0x3(%rsp)
movzwl 0xa(%rbp), %ecx
movq %rbp, %rdx
movl %eax, %ebp
imulq %rcx, %rbp
addq 0x48(%rdx), %rbp
je 0x93bd
movq %rdx, %r14
addq %r15, %rbp
movq 0x48(%rbx), %rdx
cmpq %rbp, %rdx
movq 0x18(%rsp), %r15
je 0x9348
cmpb $0x0, 0x30(%rbx)
jns 0x932d
movzbl 0x1(%r14), %edi
movq 0x8(%rsp), %rsi
movl $0x1, %ecx
callq 0x2d75
testl %eax, %eax
jne 0x93a1
andb $0x7f, 0x30(%rbx)
movzbl 0x1(%r14), %edi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0x2cfe
testl %eax, %eax
jne 0x93a1
movq %rbp, 0x48(%rbx)
movq 0x38(%rbx), %rdi
andl $0x1ff, %edi            # imm = 0x1FF
movl $0x200, %esi            # imm = 0x200
subl %edi, %esi
cmpl %r13d, %esi
jb 0x9365
movl %r13d, %esi
addq 0x8(%rsp), %rdi
callq *%r15
testl %eax, %eax
je 0x93bd
movq %r14, %rbp
movl %eax, %ecx
addq %rcx, 0x38(%rbx)
movq 0x10(%rsp), %r14
addl %eax, (%r14)
subl %eax, %r13d
jne 0x925e
jmp 0x93cb
xorl %r12d, %r12d
jmp 0x93cb
movl $0x2, 0x4(%rsp)
movb $0x2, 0x3(%rsp)
jmp 0x93bd
movb $0x1, 0x3(%rsp)
movl $0x1, 0x4(%rsp)
jmp 0x93bd
movl $0x1, 0x4(%rsp)
movb $0x1, 0x3(%rsp)
movb 0x3(%rsp), %al
movb %al, 0x31(%rbx)
movl 0x4(%rsp), %eax
movl %eax, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq