// File: /workspace/github_cpp_makefile_star2_O3/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 0xf738
movl %eax, %r12d
movl %r15d, %eax
leaq 0xc610(%rip), %rcx      # 0x16d30
movq (%rcx,%rax,8), %rdi
callq 0x41b0
addl %r12d, %eax
movzwl %ax, %r13d
movq %rbx, %rdi
callq 0xf738
movswl %ax, %r12d
addl %r13d, %r12d
callq 0x6b37
movzwl %ax, %eax
movzbl %r15b, %r15d
cmpl %eax, %r12d
jle 0xaa00
callq 0x6b37
movzwl %ax, %eax
subl %r13d, %eax
movslq %eax, %rdx
movq %rbx, %rdi
movl $0x20, %esi
callq 0x4710
cmpl $-0x1, %eax
jne 0xa77f
callq 0x6b37
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 0x43b0
leaq -0x90(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0xaea8
leaq -0x90(%rbp), %rdi
callq 0xac5e
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa7d0
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4390
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa7e9
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4390
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa802
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x40d0
movq %rbx, %rdi
callq 0xf738
movswl %ax, %r15d
callq 0x6b37
movzwl %ax, %eax
movl $0x2, %r14d
cmpl %eax, %r15d
jle 0xa972
movw $0x2, %r15w
leaq -0xb8(%rbp), %r13
movq %rbx, %r12
leaq -0x90(%rbp), %rbx
movq %r12, -0x98(%rbp)
callq 0x6b37
movzwl %ax, %edx
movq %r12, %rdi
movl $0x20, %esi
callq 0x4710
cmpl $-0x1, %eax
jne 0xa871
callq 0x6b37
movzwl %ax, %eax
movslq %eax, %r14
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq -0x98(%rbp), %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x43b0
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq %r13, %rdi
leaq 0x5bd5(%rip), %rdx      # 0x10479
movq %rdx, %rsi
callq 0x891a
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl $0x3, %ecx
callq 0xaea8
movq %rbx, %rdi
callq 0xac5e
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xa8e0
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa8fc
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xa91e
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xa937
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
incl %r15d
movq -0x98(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x40d0
movq %r12, %rdi
callq 0xf738
movswl %ax, %r14d
callq 0x6b37
movzwl %ax, %eax
cmpl %eax, %r14d
jg 0xa84f
movswl %r15w, %r14d
movq %r12, %rbx
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x5af5(%rip), %rdx      # 0x10479
movq %rdx, %rsi
callq 0x891a
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %rbx, %rsi
movl $0x3, %ecx
callq 0xaea8
leaq -0x90(%rbp), %rdi
callq 0xac5e
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xa9c9
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa9e5
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xaa58
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
jmp 0xaa58
leaq -0x90(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0xaea8
movq %r12, %rdi
callq 0xac5e
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaa39
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4390
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaa52
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4390
movl $0x1, %r14d
movzwl 0xd5d5(%rip), %eax      # 0x18034
addw %r14w, %ax
movw %ax, 0xd5ca(%rip)       # 0x18034
cmpw $0x31, %ax
jle 0xab39
movq 0xd52d(%rip), %rbx      # 0x17fa8
movq 0xd536(%rip), %r15      # 0x17fb8
movq 0x20(%rbx), %rdi
leaq 0x30(%rbx), %rax
cmpq %rax, %rdi
je 0xaa9a
movq (%rax), %rsi
incq %rsi
callq 0x4390
movq (%rbx), %rdi
leaq 0x10(%rbx), %rax
cmpq %rax, %rdi
je 0xaab1
movq (%rax), %rsi
incq %rsi
callq 0x4390
addq $-0x48, %r15
cmpq %r15, %rbx
je 0xaac7
movq 0xd4e7(%rip), %rbx      # 0x17fa8
addq $0x48, %rbx
jmp 0xab03
movq 0xd4e2(%rip), %rdi      # 0x17fb0
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x4390
movq 0xd4e1(%rip), %rax      # 0x17fc0
leaq 0x8(%rax), %rcx
movq %rcx, 0xd4d6(%rip)      # 0x17fc0
movq 0x8(%rax), %rbx
movq %rbx, 0xd4bb(%rip)      # 0x17fb0
leaq 0x1f8(%rbx), %rax
movq %rax, 0xd4b5(%rip)      # 0x17fb8
movq %rbx, 0xd49e(%rip)      # 0x17fa8
movzwl 0xd523(%rip), %eax      # 0x18034
decl %eax
movw %ax, 0xd51a(%rip)       # 0x18034
movzwl 0xd514(%rip), %r15d     # 0x18036
decl %r15d
movw %r15w, 0xd509(%rip)     # 0x18036
cmpw $0x31, %ax
jg 0xaa7b
jmp 0xab41
movzwl 0xd4f5(%rip), %r15d     # 0x18036
movl %r15d, %eax
testw %r15w, %r15w
jg 0xab55
movw $0x0, 0xd4e3(%rip)      # 0x18036
xorl %eax, %eax
movzwl %ax, %ebx
callq 0x6b29
movzbl %al, %eax
movl %r14d, %ecx
addl %eax, %ecx
addl %ebx, %ecx
movswl 0xd4c6(%rip), %eax      # 0x18034
cmpl %eax, %ecx
jne 0xab7c
addw %r14w, 0xd4bc(%rip)     # 0x18036
jmp 0xaba0
testw %r15w, %r15w
jle 0xaba0
movswl 0xd4ad(%rip), %ebx      # 0x18036
callq 0x6b29
movzbl %al, %eax
addl %ebx, %eax
incl %eax
movswl 0xd498(%rip), %ecx      # 0x18034
cmpl %ecx, %eax
jl 0xaba5
callq 0xaf61
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf1c
jmp 0xac3c
jmp 0xac01
movq %rax, %rbx
jmp 0xac55
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf1c
jmp 0xabf7
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf1c
jmp 0xac55
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0xac44
movq %rax, %rbx
jmp 0xac3c
movq %rax, %rbx
jmp 0xac1a
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xaf1c
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xac3c
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xac55
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
movq %rbx, %rdi
callq 0x4660
nop