// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/ffget.c
// Function: FFGET_getnewblock
int FFGET_getnewblock( FFGET_FILE *f )
{
	int i;
	int bs = 0;
	char *p;

	// We read the maximum of FFGET_BUFFER_MAX -2, because later, when we
	// use fgets(), we may need to read in an /additional/ single byte
	// and if we dont allocate spare room, we may have a buffer overflow

	if (f->FILEEND > 0)
	{
		f->endpoint = f->buffer;
		f->startpoint = f->buffer +1;
		f->FFEOF = 1;
		return 0;

	} else {
		long block_pos;

		block_pos = ftell(f->f); /** Get our current read position so we can use it in FFGET_ftell if required **/

		bs = fread( f->buffer, 1, FFGET_BUFFER_MAX -FFGET_BUFFER_PADDING, f->f );

		if (bs < (FFGET_BUFFER_MAX -FFGET_BUFFER_PADDING))
		{
			if (feof(f->f))
			{
				f->FILEEND = 1;
			}
			else
			{
				LOGGER_log("%s:%d:FFGET_getnewblock:ERROR: File read failed with error:%s", FL, strerror(errno));
				return 0;
			}
		}

		if (bs > 0)
		{

			// If we read in some data, then adjust the buffer to deal with it
			//
			// First we set the start point back to the start of the buffer,
			// then we set the end point to be the start +datasize we read, -1
			// then we adjust the total bytes read (for the sake of record keeping
			// though it has no /real/ purpose)
			//

			f->buffer[bs] = '\0';	//20040208-1703:PLD:JS
			f->last_block_read_from = block_pos; // 200607150941:PLD
			f->startpoint = f->buffer;
			f->endpoint = f->startpoint +bs -1;
			f->bytes += bs;

			// Check the buffer for poisioning \0's
			//  As these routines are being used for 7-bit valid text data,
			// we have to filter out any nasty \0's.

			if (FFGET_ALLOW_NUL == 0)
			{
				p = f->startpoint;
				for (i = 0; i < bs; i++) {
					if (*p == '\0') *p = ' ';
					p++;
				}
				*p = '\0';
			}

			if (FFGET_DPEDANTIC) LOGGER_log("%s:%d:FFGET_getnewblock:DEBUG-PEDANTIC: Size: %ld bytes\n", FL, f->bytes);

		}

	}

	return bs;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
cmpl $0x0, 0x2030(%rdi)
jle 0x7433
leaq 0x8(%r14), %rax
movq %rax, 0x2018(%r14)
leaq 0x9(%r14), %rax
movq %rax, 0x2010(%r14)
movl $0x1, 0x2034(%r14)
xorl %ebx, %ebx
jmp 0x7528
movq (%r14), %rdi
callq 0x2220
movq %rax, %r12
leaq 0x8(%r14), %r15
movq (%r14), %rcx
pushq $0x1
popq %rsi
movl $0x1fff, %edx           # imm = 0x1FFF
movq %r15, %rdi
callq 0x20c0
movq %rax, %rbx
cmpl $0x1ffe, %ebx           # imm = 0x1FFE
jg 0x7483
movq (%r14), %rdi
callq 0x2230
testl %eax, %eax
je 0x74fd
movl $0x1, 0x2030(%r14)
testl %ebx, %ebx
jle 0x7528
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, 0x8(%r14,%rax)
movq %r12, 0x2028(%r14)
movq %r15, 0x2010(%r14)
leaq (%r15,%rax), %rcx
decq %rcx
movq %rcx, 0x2018(%r14)
addq %rax, 0x2040(%r14)
cmpl $0x0, 0x1c6be(%rip)     # 0x23b78
jne 0x74d8
xorl %eax, %eax
cmpl %eax, %ebx
je 0x74d3
cmpb $0x0, (%r15,%rax)
jne 0x74ce
movb $0x20, (%r15,%rax)
incq %rax
jmp 0x74be
movb $0x0, (%r15,%rax)
cmpl $0xa, 0x1c69d(%rip)     # 0x23b7c
jl 0x7528
movq 0x2040(%r14), %rcx
leaq 0xcc8a(%rip), %rdi      # 0x14179
leaq 0xcc7b(%rip), %rsi      # 0x14171
movl $0xae, %edx
jmp 0x7521
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xcc23(%rip), %rdi      # 0x14133
leaq 0xcc5a(%rip), %rsi      # 0x14171
xorl %ebx, %ebx
movl $0x8a, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc2a1
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq