// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/io/outstream.cpp
// Function: smooth::IO::OutStream::OutputBits(long long, int)
S::Bool S::IO::OutStream::OutputBits(Int64 number, Int bits)
{
	if (streamType == STREAM_NONE)	{ lastError = IO_ERROR_NOTOPEN; return False; }
	if (packageSize <= 0)		{ lastError = IO_ERROR_UNKNOWN; return False; }
	if (bits > 64 || bits < 0)	{ lastError = IO_ERROR_BADPARAM; return False; }

	if (!bitstreamActive) InitBitstream();

	for (Int j = 0; j < bits; j++)
	{
		bitBuffer[bitLength] = IOGetBit(number, j);
		bitLength++;
	}

	while (bitLength >= 8)
	{
		unsigned char	 out = 0;

		for (Int i = 0; i < 8; i++) out = out | (bitBuffer[i] << i);

		bitLength = bitLength - 8;

		for (Int j = 0; j < bitLength; j++) bitBuffer[j] = bitBuffer[j + 8];

		dataBuffer[currentBufferPos] = out;

		if (currentFilePos == size) size++;

		currentBufferPos++;
		currentFilePos++;

		if (currentBufferPos >= packageSize)
		{
			if (!WriteData()) { lastError = IO_ERROR_UNKNOWN; return False; }
		}
	}

	return True;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movswl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0xe7d0a
movq -0x38(%rbp), %rax
movw $0x5, 0xf8(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe7ed9
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jg 0xe7d2a
movq -0x38(%rbp), %rax
movw $0x4, 0xf8(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe7ed9
cmpl $0x40, -0x1c(%rbp)
jg 0xe7d36
cmpl $0x0, -0x1c(%rbp)
jge 0xe7d4c
movq -0x38(%rbp), %rax
movw $0x2, 0xf8(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe7ed9
movq -0x38(%rbp), %rax
testb $0x1, 0x60(%rax)
jne 0xe7d5f
movq -0x38(%rbp), %rdi
callq 0x5cc80
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xe7dbc
cmpl $0x3f, -0x20(%rbp)
jle 0xe7d7c
xorl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0xe7d8e
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
sarq %cl, %rax
andq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq $0x0, %rcx
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 -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe7d66
jmp 0xe7dbe
movq -0x38(%rbp), %rax
cmpl $0x8, 0x64(%rax)
jl 0xe7ed5
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x8, -0x28(%rbp)
jge 0xe7e0a
movq -0x38(%rbp), %rcx
movzbl -0x21(%rbp), %eax
movslq -0x28(%rbp), %rdx
movb 0x68(%rcx,%rdx), %cl
andb $0x1, %cl
movzbl %cl, %edx
movl -0x28(%rbp), %ecx
shll %cl, %edx
movl %edx, %ecx
orl %ecx, %eax
movb %al, -0x21(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xe7dd7
movq -0x38(%rbp), %rax
movl 0x64(%rax), %ecx
subl $0x8, %ecx
movl %ecx, 0x64(%rax)
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x64(%rcx), %eax
jge 0xe7e51
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x8, %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 0xe7e1e
movq -0x38(%rbp), %rax
movb -0x21(%rbp), %cl
movb %cl, -0x41(%rbp)
movq %rax, %rdi
addq $0x20, %rdi
movl 0x50(%rax), %esi
callq 0x717e0
movb -0x41(%rbp), %dl
movq -0x38(%rbp), %rcx
movb %dl, (%rax)
movq 0x48(%rcx), %rax
cmpq 0x10(%rcx), %rax
jne 0xe7e8d
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movl 0x50(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x50(%rcx)
movq 0x48(%rcx), %rax
addq $0x1, %rax
movq %rax, 0x48(%rcx)
movl 0x50(%rcx), %eax
cmpl 0x38(%rcx), %eax
jl 0xe7ed0
movq -0x38(%rbp), %rdi
callq 0x5be10
testb $0x1, %al
jne 0xe7ece
movq -0x38(%rbp), %rax
movw $0x4, 0xf8(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe7ed9
jmp 0xe7ed0
jmp 0xe7dbe
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)