// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/io/instream.cpp
// Function: smooth::IO::InStream::InputBits(int)
S::Int64 S::IO::InStream::InputBits(Int bits)
{
	if (streamType == STREAM_NONE)	{ lastError = IO_ERROR_NOTOPEN; return -1; }
	if (bits > 64 || bits < 0)	{ lastError = IO_ERROR_BADPARAM; return -1; }

	if (!bitstreamActive) InitBitstream();

	Int64	 rval = 0;

	while (bitLength < bits)
	{
		if (currentFilePos >= (origfilepos + packageSize)) { lastError = IO_ERROR_UNKNOWN; return -1; }

		while (currentBufferPos >= packageSize)
		{
			if (!ReadData()) { lastError = IO_ERROR_NODATA; return -1; }
		}

		for (Int i = 0; i < 8; i++)
		{
			bitBuffer[bitLength] = IOGetBit(dataBuffer[currentBufferPos], i);
			bitLength++;
		}

		currentBufferPos++;
		currentFilePos++;
	}

	for (Int i = 0; i < bits; i++)
	{
		rval = rval | (Int64(bitBuffer[i]) << i);
	}

	bitLength = bitLength - bits;

	for (Int i = 0; i < bitLength; i++)
	{
		bitBuffer[i] = bitBuffer[i + bits];
	}

	return rval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movswl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0xe5e5a
movq -0x38(%rbp), %rax
movw $0x5, 0xf8(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe602a
cmpl $0x40, -0x14(%rbp)
jg 0xe5e66
cmpl $0x0, -0x14(%rbp)
jge 0xe5e80
movq -0x38(%rbp), %rax
movw $0x2, 0xf8(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe602a
movq -0x38(%rbp), %rax
testb $0x1, 0x60(%rax)
jne 0xe5e93
movq -0x38(%rbp), %rdi
callq 0x5c3e0
movq $0x0, -0x20(%rbp)
movq -0x38(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0xe5f99
movq -0x38(%rbp), %rdx
movq 0x48(%rdx), %rax
movq 0x58(%rdx), %rcx
movslq 0x38(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0xe5edd
movq -0x38(%rbp), %rax
movw $0x4, 0xf8(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe602a
jmp 0xe5edf
movq -0x38(%rbp), %rcx
movl 0x50(%rcx), %eax
cmpl 0x38(%rcx), %eax
jl 0xe5f14
movq -0x38(%rbp), %rdi
callq 0x59c50
testb $0x1, %al
jne 0xe5f12
movq -0x38(%rbp), %rax
movw $0x8, 0xf8(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe602a
jmp 0xe5edf
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jge 0xe5f7b
cmpl $0x3f, -0x24(%rbp)
jle 0xe5f2e
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe5f4f
movq -0x38(%rbp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movl 0x50(%rax), %esi
callq 0x717e0
movzbl (%rax), %eax
movl -0x24(%rbp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
cmpl $0x0, %ecx
setne %dl
movslq 0x64(%rax), %rcx
andb $0x1, %dl
movb %dl, 0x68(%rax,%rcx)
movl 0x64(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x64(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xe5f1b
movq -0x38(%rbp), %rax
movl 0x50(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x50(%rax)
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
jmp 0xe5e9b
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xe5fdb
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rdx
movb 0x68(%rcx,%rdx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, %edx
movl -0x28(%rbp), %ecx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xe5fa0
movq -0x38(%rbp), %rax
movl 0x64(%rax), %ecx
subl -0x14(%rbp), %ecx
movl %ecx, 0x64(%rax)
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x64(%rcx), %eax
jge 0xe6022
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movb 0x68(%rax,%rcx), %dl
movslq -0x2c(%rbp), %rcx
andb $0x1, %dl
movb %dl, 0x68(%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xe5fef
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)