// File: /workspace/github_cpp_makefile_star2_O2/Alcaro[P]bridges/arlib/array.cpp
// Function: bitarray::resize(unsigned long)
void bitarray::resize(size_t len)
{
	size_t prevlen = this->nbits;
	this->nbits = len;
	
	switch ((prevlen > n_inline)<<1 | (len > n_inline))
	{
	case 0: // small->small
		if (len < prevlen)
			clear_unused(this->nbits, sizeof(this->bits_inline));
		break;
	case 1: // small->big
		{
			size_t newbytes = alloc_size(len);
			uint8_t* newbits = xmalloc(newbytes);
			memcpy(newbits, this->bits_inline, sizeof(this->bits_inline));
			memset(newbits+sizeof(this->bits_inline), 0, newbytes-sizeof(this->bits_inline));
			bits_outline = newbits;
		}
		break;
	case 2: // big->small
		{
			uint8_t* freethis = this->bits_outline;
			memcpy(this->bits_inline, this->bits_outline, sizeof(this->bits_inline));
			free(freethis);
			clear_unused(this->nbits, sizeof(this->bits_inline));
		}
		break;
	case 3: // big->big
		{
			size_t prevbytes = alloc_size(prevlen);
			size_t newbytes = alloc_size(len);
			if (newbytes > prevbytes)
			{
				bits_outline = xrealloc(this->bits_outline, newbytes);
				clear_unused(prevlen, newbytes);
			}
			else if (len < prevlen)
			{
				clear_unused(this->nbits, newbytes);
			}
		}
		break;
	}
	
//printf("%lu->%lu t=%d", prevlen, len, ((prevlen > n_inline)<<1 | (len > n_inline)));
//size_t bytes;
//if (len > n_inline) bytes = alloc_size(len);
//else bytes = sizeof(bits_inline);
//for (size_t i=0;i<bitround(bytes);i++)
//{
//printf(" %.2X", bits()[i]);
//}
//puts("");
//bool fail=false;
//if (len>prevlen)
//{
//for (size_t n=prevlen;n<len;n++)
//{
//	if (get(n))
//	{
//		printf("%lu->%lu: unexpected at %lu\n", prevlen, len, n);
//		fail=true;
//	}
//}
//}
//if(fail)abort();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq %rsi, 0x8(%rdi)
xorl %eax, %eax
cmpq $0x41, %r14
setae %al
xorl %ecx, %ecx
cmpq $0x41, %rsi
setae %cl
leal (%rcx,%rax,2), %eax
leaq 0x23c94(%rip), %rcx     # 0x28158
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq %rsi, %r14
ja 0x44e9
jmp 0x45a9
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rax, (%rbx)
callq 0x3430
movq 0x8(%rbx), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
jmp 0x45ba
leaq 0x7(%r14), %rax
movq %rax, %rcx
shrq $0x3, %rcx
decq %rcx
bsrq %rcx, %rcx
pushq $0x2
popq %rdx
movq %rdx, %rdi
shlq %cl, %rdi
leaq 0x7(%rsi), %r8
movq %r8, %rcx
shrq $0x3, %rcx
decq %rcx
bsrq %rcx, %rcx
shlq %cl, %rdx
xorl %ecx, %ecx
cmpq $0x10, %r8
pushq $0x1
popq %r15
cmovaeq %rdx, %r15
setae %cl
xorl %edx, %edx
cmpq %r15, %rdi
setb %dl
cmpq $0x10, %rax
cmovael %edx, %ecx
cmpb $0x1, %cl
jne 0x45af
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x115b4
movq %rax, (%rbx)
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x45b7
addq $0x7, %rsi
movq %rsi, %rax
shrq $0x3, %rax
decq %rax
bsrq %rax, %rcx
pushq $0x2
popq %rax
shlq %cl, %rax
cmpq $0x10, %rsi
pushq $0x1
popq %r14
cmovaeq %rax, %r14
movq %r14, %rdi
callq 0x11544
movq %rax, %r15
movq (%rbx), %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
addq $-0x8, %r14
xorl %esi, %esi
movq %r14, %rdx
callq 0x3170
movq %r15, (%rbx)
popq %rbx
popq %r14
popq %r15
retq
cmpq %rsi, %r14
jbe 0x45a9
movq %rbx, %rdi
movq %r15, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x4448