// File: /workspace/github_cpp_makefile_star2_O2/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 0xd028
movl %eax, %r12d
movl %r15d, %eax
leaq 0xcd22(%rip), %rcx      # 0x15d40
movq (%rcx,%rax,8), %rdi
callq 0x41c0
addl %r12d, %eax
movzwl %ax, %r12d
movq %rbx, %rdi
callq 0xd028
movswl %ax, %r13d
addl %r12d, %r13d
callq 0x6481
movzwl %ax, %eax
movzbl %r15b, %r15d
cmpl %eax, %r13d
jle 0x9189
callq 0x6481
movzwl %ax, %eax
subl %r12d, %eax
movslq %eax, %rdx
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x4710
cmpl $-0x1, %eax
jne 0x907b
callq 0x6481
movzwl %ax, %eax
subl %r12d, %eax
movslq %eax, %r13
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x43c0
leaq -0x98(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x95d4
leaq -0x98(%rbp), %rdi
callq 0x9394
leaq -0x98(%rbp), %rdi
callq 0x961a
leaq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x4748
movw $0x2, %ax
movl %eax, -0x30(%rbp)
leaq -0xb8(%rbp), %r12
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x40e0
movq %rbx, %rdi
callq 0xd028
movswl %ax, %r13d
callq 0x6481
movzwl %ax, %eax
cmpl %eax, %r13d
jle 0x91bb
callq 0x6481
movzwl %ax, %edx
movq %rbx, %rdi
pushq $0x20
popq %rsi
callq 0x4710
cmpl $-0x1, %eax
jne 0x9123
callq 0x6481
movzwl %ax, %eax
movslq %eax, %r13
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x43c0
movq %r12, %rdi
leaq 0x5349(%rip), %rsi      # 0xe489
leaq -0x29(%rbp), %rdx
callq 0x69bc
movq %r15, %rsi
leaq -0x98(%rbp), %r14
movq %r14, %rdi
movq %r12, %rdx
pushq $0x3
popq %rcx
callq 0x95d4
movq %r14, %rdi
callq 0x9394
movq %r14, %rdi
callq 0x961a
movq %r12, %rdi
callq 0x4748
movq %r15, %rdi
callq 0x4748
incl -0x30(%rbp)
jmp 0x90d9
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x95d4
movq %r12, %rdi
callq 0x9394
leaq -0x98(%rbp), %rdi
callq 0x961a
pushq $0x1
popq %r14
jmp 0x920e
leaq 0x52c7(%rip), %rsi      # 0xe489
leaq -0x50(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
callq 0x69bc
leaq -0x98(%rbp), %rdi
leaq -0x50(%rbp), %rdx
pushq $0x3
popq %rcx
movq %rbx, %rsi
callq 0x95d4
leaq -0x98(%rbp), %rdi
callq 0x9394
leaq -0x98(%rbp), %rdi
callq 0x961a
leaq -0x50(%rbp), %rdi
callq 0x4748
movswl -0x30(%rbp), %r14d
movzwl 0xde1f(%rip), %eax      # 0x17034
addw %r14w, %ax
movw %ax, 0xde14(%rip)       # 0x17034
cmpw $0x32, %ax
jl 0x92b5
movq 0xdd77(%rip), %rbx      # 0x16fa8
movq 0xdd80(%rip), %r15      # 0x16fb8
addq $-0x48, %r15
movq %rbx, %rdi
callq 0x961a
cmpq %r15, %rbx
je 0x9256
movq 0xdd58(%rip), %rax      # 0x16fa8
addq $0x48, %rax
jmp 0x9292
movq 0xdd53(%rip), %rdi      # 0x16fb0
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x43b0
movq 0xdd52(%rip), %rax      # 0x16fc0
leaq 0x8(%rax), %rcx
movq %rcx, 0xdd47(%rip)      # 0x16fc0
movq 0x8(%rax), %rax
movq %rax, 0xdd2c(%rip)      # 0x16fb0
leaq 0x1f8(%rax), %rcx
movq %rcx, 0xdd26(%rip)      # 0x16fb8
movq %rax, 0xdd0f(%rip)      # 0x16fa8
movzwl 0xdd94(%rip), %eax      # 0x17034
decl %eax
movw %ax, 0xdd8b(%rip)       # 0x17034
decw 0xdd86(%rip)            # 0x17036
jmp 0x9220
movzwl 0xdd7a(%rip), %ebx      # 0x17036
movl %ebx, %eax
testw %bx, %bx
jg 0x92cd
andw $0x0, 0xdd6b(%rip)      # 0x17036
xorl %eax, %eax
movzwl %ax, %r15d
callq 0x6473
movzbl %al, %eax
movl %r14d, %ecx
addl %eax, %ecx
addl %r15d, %ecx
movswl 0xdd4c(%rip), %eax      # 0x17034
cmpl %eax, %ecx
jne 0x92f6
addw %r14w, 0xdd42(%rip)     # 0x17036
jmp 0x9319
testw %bx, %bx
jle 0x9319
movswl 0xdd34(%rip), %ebx      # 0x17036
callq 0x6473
movzbl %al, %eax
addl %ebx, %eax
incl %eax
movswl 0xdd1f(%rip), %ecx      # 0x17034
cmpl %ecx, %eax
jl 0x931e
callq 0x963a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9339
jmp 0x937f
movq %rax, %rbx
jmp 0x938b
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x961a
jmp 0x9382
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x961a
jmp 0x938b
jmp 0x937f
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x961a
jmp 0x9371
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x4748
jmp 0x9382
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x4748
movq %rbx, %rdi
callq 0x4650
nop