// File: 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
subq $0x240, %rsp            # imm = 0x240
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a800
movswq %ax, %rax
movq %rax, -0x1f8(%rbp)
movzbl -0x11(%rbp), %eax
movl %eax, %ecx
leaq 0x19847(%rip), %rax     # 0x28500
movq (%rax,%rcx,8), %rdi
callq 0x5230
movq %rax, %rcx
movq -0x1f8(%rbp), %rax
addq %rcx, %rax
movw %ax, -0x14(%rbp)
movw $0x1, -0x16(%rbp)
movzwl -0x14(%rbp), %eax
movl %eax, -0x1ec(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1a800
movw %ax, %cx
movl -0x1ec(%rbp), %eax
movswl %cx, %ecx
addl %ecx, %eax
movl %eax, -0x1e8(%rbp)
callq 0x98f0
movw %ax, %cx
movl -0x1e8(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
jle 0xf0c0
movq -0x8(%rbp), %rax
movq %rax, -0x200(%rbp)
callq 0x98f0
movq -0x200(%rbp), %rdi
movzwl %ax, %eax
movzwl -0x14(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rdx
movl $0x20, %esi
callq 0x5910
movl %eax, -0x1c(%rbp)
cltq
cmpq $-0x1, %rax
jne 0xed62
callq 0x98f0
movzwl %ax, %eax
movzwl -0x14(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x88(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x54e0
movq -0x208(%rbp), %rsi
movq -0x10(%rbp), %rdx
movzbl -0x11(%rbp), %ecx
leaq -0x68(%rbp), %rdi
callq 0xf270
jmp 0xed9b
leaq 0x1a356(%rip), %rdi     # 0x290f8
leaq -0x68(%rbp), %rsi
callq 0xf240
jmp 0xedad
leaq -0x68(%rbp), %rdi
callq 0xf2f0
leaq -0x88(%rbp), %rdi
callq 0x5968
movw -0x16(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x16(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x5120
movq -0x8(%rbp), %rdi
callq 0x1a800
cwtl
movl %eax, -0x20c(%rbp)
callq 0x98f0
movw %ax, %cx
movl -0x20c(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
jle 0xefc4
movq -0x8(%rbp), %rax
movq %rax, -0x218(%rbp)
callq 0x98f0
movq -0x218(%rbp), %rdi
movzwl %ax, %eax
movl %eax, %edx
movl $0x20, %esi
callq 0x5910
movl %eax, -0x1c(%rbp)
cltq
cmpq $-0x1, %rax
jne 0xee86
callq 0x98f0
movzwl %ax, %eax
movl %eax, -0x1c(%rbp)
jmp 0xee86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xee75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xf2f0
leaq -0x88(%rbp), %rdi
callq 0x5968
jmp 0xf229
movq -0x8(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x100(%rbp), %rdi
callq 0x54e0
leaq -0x121(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x5840
movq -0x220(%rbp), %rdx
leaq 0xd5ca(%rip), %rsi      # 0x1c489
leaq -0x120(%rbp), %rdi
callq 0xa030
jmp 0xeecd
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x120(%rbp), %rdx
movl $0x3, %ecx
callq 0xf270
jmp 0xeeee
leaq 0x1a203(%rip), %rdi     # 0x290f8
leaq -0xe0(%rbp), %rsi
callq 0xf240
jmp 0xef03
leaq -0xe0(%rbp), %rdi
callq 0xf2f0
leaq -0x120(%rbp), %rdi
callq 0x5968
leaq -0x121(%rbp), %rdi
callq 0x5540
leaq -0x100(%rbp), %rdi
callq 0x5968
movw -0x16(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x16(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x5120
jmp 0xeddf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xefa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xef9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xf2f0
leaq -0x120(%rbp), %rdi
callq 0x5968
leaq -0x121(%rbp), %rdi
callq 0x5540
leaq -0x100(%rbp), %rdi
callq 0x5968
jmp 0xf229
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x191(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x5840
movq -0x228(%rbp), %rdx
leaq 0xd499(%rip), %rsi      # 0x1c489
leaq -0x190(%rbp), %rdi
callq 0xa030
jmp 0xeffe
movq -0x230(%rbp), %rsi
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rdx
movl $0x3, %ecx
callq 0xf270
jmp 0xf01f
leaq 0x1a0d2(%rip), %rdi     # 0x290f8
leaq -0x170(%rbp), %rsi
callq 0xf240
jmp 0xf034
leaq -0x170(%rbp), %rdi
callq 0xf2f0
leaq -0x190(%rbp), %rdi
callq 0x5968
leaq -0x191(%rbp), %rdi
callq 0x5540
jmp 0xf125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xf0af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xf0a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xf2f0
leaq -0x190(%rbp), %rdi
callq 0x5968
leaq -0x191(%rbp), %rdi
callq 0x5540
jmp 0xf229
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movzbl -0x11(%rbp), %ecx
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0xf270
movq -0x238(%rbp), %rsi
leaq 0x1a00b(%rip), %rdi     # 0x290f8
callq 0xf240
jmp 0xf0f4
leaq -0x1e0(%rbp), %rdi
callq 0xf2f0
jmp 0xf125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0xf2f0
jmp 0xf229
movswl -0x16(%rbp), %ecx
movswl 0x1a064(%rip), %eax     # 0x29194
addl %ecx, %eax
movw %ax, 0x1a05b(%rip)      # 0x29194
movb $0x0, -0x1e1(%rbp)
movswl 0x1a04d(%rip), %eax     # 0x29194
cmpl $0x32, %eax
jl 0xf17e
leaq 0x19fa5(%rip), %rdi     # 0x290f8
callq 0xf320
movw 0x1a035(%rip), %ax      # 0x29194
addw $-0x1, %ax
movw %ax, 0x1a02a(%rip)      # 0x29194
movw 0x1a025(%rip), %ax      # 0x29196
addw $-0x1, %ax
movw %ax, 0x1a01a(%rip)      # 0x29196
jmp 0xf140
movswl 0x1a011(%rip), %eax     # 0x29196
cmpl $0x0, %eax
jg 0xf19a
movw $0x0, 0x1a003(%rip)     # 0x29196
movb $0x1, -0x1e1(%rbp)
movswl 0x19ff5(%rip), %eax     # 0x29196
movl %eax, -0x23c(%rbp)
callq 0x98e0
movb %al, %cl
movl -0x23c(%rbp), %eax
movzbl %cl, %ecx
addl %ecx, %eax
movswl -0x16(%rbp), %ecx
addl %ecx, %eax
movswl 0x19fce(%rip), %ecx     # 0x29194
cmpl %ecx, %eax
jne 0xf1e5
movswl -0x16(%rbp), %ecx
movswl 0x19fc1(%rip), %eax     # 0x29196
addl %ecx, %eax
movw %ax, 0x19fb8(%rip)      # 0x29196
movb $0x1, -0x1e1(%rbp)
testb $0x1, -0x1e1(%rbp)
jne 0xf21b
movswl 0x19fa1(%rip), %eax     # 0x29196
movl %eax, -0x240(%rbp)
callq 0x98e0
movb %al, %cl
movl -0x240(%rbp), %eax
movzbl %cl, %ecx
addl %ecx, %eax
addl $0x1, %eax
movswl 0x19f7d(%rip), %ecx     # 0x29194
cmpl %ecx, %eax
jl 0xf220
callq 0xf390
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x5830
nopw %cs:(%rax,%rax)