// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/io/instream.cpp
// Function: smooth::IO::InStream::InputData(void*, int)
S::Int S::IO::InStream::InputData(Void *pointer, Int bytes)
{
	if (streamType == STREAM_NONE)	 { lastError = IO_ERROR_NOTOPEN; return 0; }
	if (bytes > 0 && pointer == NIL) { lastError = IO_ERROR_BADPARAM; return 0; }
	if (bytes < 0)			 { lastError = IO_ERROR_BADPARAM; return 0; }

	if (bitstreamActive && !keepBits) CompleteBitstream();

	Int	 bytesleft	= bytes;
	Int	 databufferpos	= 0;

	while (bytesleft)
	{
		if (currentFilePos >= (origfilepos + packageSize)) { lastError = IO_ERROR_UNKNOWN; return bytes - bytesleft; }

		while (currentBufferPos >= packageSize)
		{
			/* If no more data is available, set lastError and
			 * return the number of bytes actually read.
			 */
			if (!ReadData()) { lastError = IO_ERROR_NODATA; return bytes - bytesleft; }
		}

		/* Get amount of data read and copy to output buffer.
		 */
		Int	 amount = ((packageSize - currentBufferPos) < (bytesleft)) ? (packageSize - currentBufferPos) : (bytesleft);

		memcpy((UnsignedByte *) pointer + databufferpos, (UnsignedByte *) dataBuffer + currentBufferPos, amount);

		bytesleft	 -= amount;
		databufferpos	 += amount;
		currentBufferPos += amount;
		currentFilePos	 += amount;
	}

	return bytes;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movswl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0xe652d
movq -0x30(%rbp), %rax
movw $0x5, 0xf8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe66aa
cmpl $0x0, -0x1c(%rbp)
jle 0xe6553
cmpq $0x0, -0x18(%rbp)
jne 0xe6553
movq -0x30(%rbp), %rax
movw $0x2, 0xf8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe66aa
cmpl $0x0, -0x1c(%rbp)
jge 0xe6572
movq -0x30(%rbp), %rax
movw $0x2, 0xf8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe66aa
movq -0x30(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0xe658f
movq -0x30(%rbp), %rax
testb $0x1, 0x61(%rax)
jne 0xe658f
movq -0x30(%rbp), %rdi
callq 0x5bd50
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xe66a4
movq -0x30(%rbp), %rdx
movq 0x48(%rdx), %rax
movq 0x58(%rdx), %rcx
movslq 0x38(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0xe65d9
movq -0x30(%rbp), %rax
movw $0x4, 0xf8(%rax)
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe66aa
jmp 0xe65db
movq -0x30(%rbp), %rcx
movl 0x50(%rcx), %eax
cmpl 0x38(%rcx), %eax
jl 0xe6611
movq -0x30(%rbp), %rdi
callq 0x59c50
testb $0x1, %al
jne 0xe660f
movq -0x30(%rbp), %rax
movw $0x8, 0xf8(%rax)
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe66aa
jmp 0xe65db
movq -0x30(%rbp), %rcx
movl 0x38(%rcx), %eax
subl 0x50(%rcx), %eax
cmpl -0x20(%rbp), %eax
jge 0xe662f
movq -0x30(%rbp), %rcx
movl 0x38(%rcx), %eax
subl 0x50(%rcx), %eax
movl %eax, -0x34(%rbp)
jmp 0xe6635
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
addq $0x20, %rdi
callq 0x71100
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movq -0x30(%rbp), %rax
movslq 0x50(%rax), %rax
addq %rax, %rsi
movslq -0x28(%rbp), %rdx
callq 0x593a0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edx
movl -0x20(%rbp), %ecx
subl %edx, %ecx
movl %ecx, -0x20(%rbp)
movl -0x28(%rbp), %ecx
addl -0x24(%rbp), %ecx
movl %ecx, -0x24(%rbp)
movl -0x28(%rbp), %ecx
addl 0x50(%rax), %ecx
movl %ecx, 0x50(%rax)
movslq -0x28(%rbp), %rcx
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
jmp 0xe659c
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)