// File: Alcaro[P]bridges/arlib/string.cpp
// Function: string::resize(unsigned long)
void string::resize(size_t newlen)
{
	switch (!inlined()<<1 | (newlen>max_inline()))
	{
	case 0: // small->small
		{
			m_inline[newlen] = '\0';
			m_inline_len_w() = max_inline()-newlen;
		}
		break;
	case 1: // small->big
		{
			uint8_t* newptr = xmalloc(bytes_for(newlen));
			memcpy(newptr, m_inline, max_inline());
			newptr[newlen] = '\0';
			m_data = newptr;
			m_len = newlen;
			m_nul = true;
			
			m_inline_len_w() = -1;
		}
		break;
	case 2: // big->small
		{
			uint8_t* oldptr = m_data;
			memcpy(m_inline, oldptr, newlen);
			free(oldptr);
			m_inline[newlen] = '\0';
			m_inline_len_w() = max_inline()-newlen;
		}
		break;
	case 3: // big->big
		{
			if (bytes_for(newlen) != bytes_for(m_len))
				m_data = xrealloc(m_data, bytes_for(newlen));
			m_data[newlen] = '\0';
			m_len = newlen;
		}
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
shrl $0x1f, %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x5c90
movq -0x58(%rbp), %rcx
movl %eax, %edx
movl -0x4c(%rbp), %eax
movl %edx, %edx
subq %rdx, %rcx
seta %cl
movzbl %cl, %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x3, %eax
ja 0x36eff
movq -0x48(%rbp), %rax
leaq 0x2cf4d(%rip), %rcx     # 0x63ce0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
callq 0x5c90
movq -0x60(%rbp), %rdi
movl %eax, %eax
subq -0x18(%rbp), %rax
movb %al, -0x61(%rbp)
callq 0x5ca0
movb -0x61(%rbp), %cl
movb %cl, (%rax)
jmp 0x36eff
movq -0x18(%rbp), %rdi
callq 0x3dca0
movq %rax, %rdi
callq 0x2d5e0
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6bc0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x5c90
movq -0x70(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
callq 0x4280
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq %rax, (%rdi)
movq -0x18(%rbp), %rax
movl %eax, 0x8(%rdi)
movb $0x1, 0xc(%rdi)
callq 0x5ca0
movb $-0x1, (%rax)
jmp 0x36eff
movq -0x60(%rbp), %rdi
movq (%rdi), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4280
movq -0x30(%rbp), %rdi
callq 0x4420
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
callq 0x5c90
movq -0x60(%rbp), %rdi
movl %eax, %eax
subq -0x18(%rbp), %rax
movb %al, -0x71(%rbp)
callq 0x5ca0
movb -0x71(%rbp), %cl
movb %cl, (%rax)
jmp 0x36eff
movq -0x18(%rbp), %rdi
callq 0x3dca0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x80(%rbp)
movl 0x8(%rax), %eax
movl %eax, %edi
callq 0x3dca0
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
je 0x36ee9
movq -0x60(%rbp), %rax
movq (%rax), %rsi
leaq -0x40(%rbp), %rdi
callq 0x6be0
movq -0x18(%rbp), %rdi
callq 0x3dca0
movq %rax, %rsi
movq -0x40(%rbp), %rdi
callq 0x2d690
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6bc0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rdx
movb $0x0, (%rcx,%rdx)
movq -0x18(%rbp), %rcx
movl %ecx, 0x8(%rax)
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)