// File: /workspace/github_c_makefile_star2_O1/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 0x773b
leaq 0x8(%r14), %rax
movq %rax, 0x2018(%r14)
leaq 0x9(%r14), %rax
movq %rax, 0x2010(%r14)
movl $0x1, 0x2034(%r14)
xorl %ebx, %ebx
jmp 0x7830
movq (%r14), %rdi
callq 0x2230
movq %rax, %r12
leaq 0x8(%r14), %r15
movq (%r14), %rcx
movl $0x1, %esi
movl $0x1fff, %edx           # imm = 0x1FFF
movq %r15, %rdi
callq 0x20c0
movq %rax, %rbx
cmpl $0x1ffe, %ebx           # imm = 0x1FFE
jg 0x7785
movq (%r14), %rdi
callq 0x2240
testl %eax, %eax
je 0x7805
movl $0x1, 0x2030(%r14)
testl %ebx, %ebx
jle 0x7830
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, 0x1d3b4(%rip)     # 0x24b78
jne 0x77e0
xorl %eax, %eax
cmpb $0x0, (%r15,%rax)
jne 0x77d4
movb $0x20, (%r15,%rax)
incq %rax
cmpl %eax, %ebx
jne 0x77c8
movb $0x0, (%r15,%rax)
cmpl $0xa, 0x1d395(%rip)     # 0x24b7c
jl 0x7830
movq 0x2040(%r14), %rcx
leaq 0xd952(%rip), %rdi      # 0x15149
leaq 0xd943(%rip), %rsi      # 0x15141
movl $0xae, %edx
jmp 0x7829
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xd8eb(%rip), %rdi      # 0x15103
leaq 0xd922(%rip), %rsi      # 0x15141
xorl %ebx, %ebx
movl $0x8a, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc960
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq