// File: /workspace/github_cpp_makefile_star2_O1/lotuskip[P]yuxtapa/client/msg.cpp
// Function: add_to_chat(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned char)
void add_to_chat(string &s, const string &talker, const unsigned char t)
{
	// Chop into pieces if line is too long:
	unsigned short len = num_syms(talker) + strlen(team_ind[t]);
	short new_lines = 1;
	if(len + num_syms(s) > Base::chat_width())
	{
		int i;
		if((i = s.rfind(' ', Base::chat_width() - len)) == string::npos)
			i = Base::chat_width() - len;
		chatbuffer.push_back(ChatBufferLine(s.substr(0, i), talker, t));
		++new_lines;
		s.erase(0, i);
		while(num_syms(s) > Base::chat_width())
		{
			if((i = s.rfind(' ', Base::chat_width())) == string::npos)
				i = Base::chat_width();
			chatbuffer.push_back(ChatBufferLine(s.substr(0, i), "", T_NO_TEAM));
			++new_lines;
			s.erase(0, i);
		}
		chatbuffer.push_back(ChatBufferLine(s, "", T_NO_TEAM));
	}
	else
		chatbuffer.push_back(ChatBufferLine(s, talker, t));
	num_chat_lines += new_lines;
	
	bool forceredraw = false;
	while(num_chat_lines >= CHAT_BUFFER_SIZE)
	{
		chatbuffer.pop_front();
		--num_chat_lines;
		--chat_top;
	}
	if(chat_top <= 0)
	{
		chat_top = 0;
		forceredraw = true;
	}

	// auto-scrolling:
	if(chat_top + Base::num_chat_lines_to_show() + new_lines == num_chat_lines)
	{
		chat_top += new_lines;
		forceredraw = true;
	}

	// Redraw if the new line is shown or the deleted line was shown before
	if(forceredraw ||
		chat_top + Base::num_chat_lines_to_show() + 1 >= num_chat_lines)
		redraw_chat();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xf89c
movl %eax, %r12d
movl %r15d, %eax
leaq 0xc5cb(%rip), %rcx      # 0x16d30
movq (%rcx,%rax,8), %rdi
callq 0x41b0
addl %r12d, %eax
movzwl %ax, %r13d
movq %rbx, %rdi
callq 0xf89c
movswl %ax, %r12d
addl %r13d, %r12d
callq 0x6b79
movzwl %ax, %eax
movzbl %r15b, %r15d
cmpl %eax, %r12d
jle 0xaa45
callq 0x6b79
movzwl %ax, %eax
subl %r13d, %eax
movslq %eax, %rdx
movq %rbx, %rdi
movl $0x20, %esi
callq 0x4720
cmpl $-0x1, %eax
jne 0xa7c4
callq 0x6b79
movzwl %ax, %eax
subl %r13d, %eax
movslq %eax, %r12
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x43c0
leaq -0x90(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0xaeb6
leaq -0x90(%rbp), %rdi
callq 0xac6c
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa815
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43a0
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa82e
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43a0
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa847
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x40d0
movq %rbx, %rdi
callq 0xf89c
movswl %ax, %r15d
callq 0x6b79
movzwl %ax, %eax
movl $0x2, %r14d
cmpl %eax, %r15d
jle 0xa9b7
movw $0x2, %r15w
leaq -0xb8(%rbp), %r13
movq %rbx, %r12
leaq -0x90(%rbp), %rbx
movq %r12, -0x98(%rbp)
callq 0x6b79
movzwl %ax, %edx
movq %r12, %rdi
movl $0x20, %esi
callq 0x4720
cmpl $-0x1, %eax
jne 0xa8b6
callq 0x6b79
movzwl %ax, %eax
movslq %eax, %r14
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq -0x98(%rbp), %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x43c0
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq %r13, %rdi
leaq 0x5b90(%rip), %rdx      # 0x10479
movq %rdx, %rsi
callq 0x8912
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl $0x3, %ecx
callq 0xaeb6
movq %rbx, %rdi
callq 0xac6c
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xa925
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa941
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xa963
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xa97c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
incl %r15d
movq -0x98(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x40d0
movq %r12, %rdi
callq 0xf89c
movswl %ax, %r14d
callq 0x6b79
movzwl %ax, %eax
cmpl %eax, %r14d
jg 0xa894
movswl %r15w, %r14d
movq %r12, %rbx
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x5ab0(%rip), %rdx      # 0x10479
movq %rdx, %rsi
callq 0x8912
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %rbx, %rsi
movl $0x3, %ecx
callq 0xaeb6
leaq -0x90(%rbp), %rdi
callq 0xac6c
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xaa0e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xaa2a
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xaa9d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
jmp 0xaa9d
leaq -0x90(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0xaeb6
movq %r12, %rdi
callq 0xac6c
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaa7e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43a0
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaa97
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43a0
movl $0x1, %r14d
movzwl 0xd590(%rip), %eax      # 0x18034
addw %r14w, %ax
movw %ax, 0xd585(%rip)       # 0x18034
cmpw $0x32, %ax
jl 0xab49
movq 0xd4e8(%rip), %rbx      # 0x17fa8
movq 0xd4f1(%rip), %r15      # 0x17fb8
addq $-0x48, %r15
movq %rbx, %rdi
callq 0xb3c6
cmpq %r15, %rbx
je 0xaae5
movq 0xd4c9(%rip), %rax      # 0x17fa8
addq $0x48, %rax
jmp 0xab21
movq 0xd4c4(%rip), %rdi      # 0x17fb0
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x43a0
movq 0xd4c3(%rip), %rax      # 0x17fc0
leaq 0x8(%rax), %rcx
movq %rcx, 0xd4b8(%rip)      # 0x17fc0
movq 0x8(%rax), %rax
movq %rax, 0xd49d(%rip)      # 0x17fb0
leaq 0x1f8(%rax), %rcx
movq %rcx, 0xd497(%rip)      # 0x17fb8
movq %rax, 0xd480(%rip)      # 0x17fa8
movzwl 0xd505(%rip), %eax      # 0x18034
decl %eax
movw %ax, 0xd4fc(%rip)       # 0x18034
decw 0xd4f7(%rip)            # 0x18036
cmpw $0x31, %ax
jg 0xaab9
movzwl 0xd4e6(%rip), %ebx      # 0x18036
testw %bx, %bx
jg 0xab5e
movw $0x0, 0xd4d8(%rip)      # 0x18036
movswl 0xd4d0(%rip), %r15d     # 0x18036
callq 0x6b6b
movzbl %al, %eax
movl %r14d, %ecx
addl %eax, %ecx
addl %r15d, %ecx
movswl 0xd4b7(%rip), %eax      # 0x18034
cmpl %eax, %ecx
jne 0xab8b
addw %r14w, 0xd4ad(%rip)     # 0x18036
jmp 0xabae
testw %bx, %bx
jle 0xabae
movswl 0xd49f(%rip), %ebx      # 0x18036
callq 0x6b6b
movzbl %al, %eax
addl %ebx, %eax
incl %eax
movswl 0xd48a(%rip), %ecx      # 0x18034
cmpl %ecx, %eax
jl 0xabb3
callq 0xaf6f
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf2a
jmp 0xac4a
jmp 0xac0f
movq %rax, %rbx
jmp 0xac63
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf2a
jmp 0xac05
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf2a
jmp 0xac63
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0xac52
movq %rax, %rbx
jmp 0xac4a
movq %rax, %rbx
jmp 0xac28
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf2a
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xac4a
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xac63
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4670
nop