// File: /workspace/github_cpp_makefile_star2_O1/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 0x29f7c(%rip), %rcx     # 0x2f154
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq %rsi, %r14
ja 0x51fd
jmp 0x52ca
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rax, (%rbx)
callq 0x3430
movq 0x8(%rbx), %rsi
movl $0x8, %edx
movq %rbx, %rdi
jmp 0x52db
leaq 0x7(%r14), %rax
movq %rax, %rcx
shrq $0x3, %rcx
decq %rcx
bsrq %rcx, %rcx
movl $0x2, %edx
shlq %cl, %rdx
movl $0x2, %edi
leaq 0x7(%rsi), %r8
movq %r8, %rcx
shrq $0x3, %rcx
decq %rcx
bsrq %rcx, %rcx
shlq %cl, %rdi
xorl %ecx, %ecx
cmpq $0x10, %r8
movl $0x1, %r15d
cmovaeq %rdi, %r15
setae %cl
xorl %edi, %edi
cmpq %r15, %rdx
setb %dil
cmpq $0x10, %rax
cmovael %edi, %ecx
cmpb $0x1, %cl
jne 0x52d0
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x157b7
movq %rax, (%rbx)
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x52d8
addq $0x7, %rsi
movq %rsi, %rax
shrq $0x3, %rax
decq %rax
bsrq %rax, %rcx
movl $0x2, %eax
shlq %cl, %rax
cmpq $0x10, %rsi
movl $0x1, %r14d
cmovaeq %rax, %r14
movq %r14, %rdi
callq 0x1573c
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 0x52ca
movq %rbx, %rdi
movq %r15, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x515c
nop