// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/players.cpp
// Function: (anonymous namespace)::register_player(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, sockaddr_storage&, std::_List_iterator<PlayerStats>, bool)
void register_player(string nick, sockaddr_storage &sas,
	list<PlayerStats>::iterator it, const bool is_bot)
{
	// Check if nick is taken and modify if needed:
	list<Player>::const_iterator i = cur_players.begin();
	while(i != cur_players.end())
	{
		if(i->nick == nick)
		{
			unsigned short found = 0;
			bool twodigits = false;
			if(!nick.empty() && isdigit(nick[nick.size()-1]))
			{
				found += int(nick[nick.size()-1]-'0');
				nick.erase(nick.end()-1);
			}
			if(!nick.empty() && isdigit(nick[nick.size()-1]))
			{
				found += 10*int(nick[nick.size()-1]-'0');
				nick.erase(nick.end()-1);
				twodigits = true;
			}
			string numpart;
			++found;
			if(found == 100)
				numpart = "01";
			else
				numpart = lex_cast(found);
			if(twodigits && numpart.size() == 1)
				numpart.insert(0, 1, '0');

			while(num_syms(nick) + numpart.size() > MAX_NICK_LEN)
				del(nick, num_syms(nick)-1);

			nick += numpart;
			// Nick was modified, so we must restart from the beginning (the
			// modified nick might now conflict with an earlier checked nick!)
			i = cur_players.begin();
		}
		else
			++i;
	}
	list<Player>::iterator npit = cur_players.insert(cur_players.end(),
		Player());
	npit->stats_i = it;
	time(&(npit->stats_i->last_seen));
	npit->nick = it->last_known_as = nick;
	npit->address = sas;
	npit->muted = npit->needs_state_upd = false;
	npit->poisoner = cur_players.end();
	npit->clear_acts();
	npit->last_heard_of = Game::curturn;
	npit->facing = D_N; // just to give a definite value
	npit->sector = npit->wants_to_move_to = MAX_D;
	// a newly connected player is a spectator:
	npit->team = T_SPEC;
	npit->cl = npit->next_cl = NO_CLASS;
	npit->cl_props.hp = // this assures the player is !alive()
		npit->doing_a_chore =
		npit->warned_of_chasm = 0;
	npit->botpid = -1;

	// A newly connected player is watching her own viewpoint:
	(npit->own_vp = new ViewPoint())->set_owner(npit);
	npit->own_vp->add_watcher(npit);
	npit->viewn_vp = npit->own_vp;

	if(!is_bot && Config::int_settings[Config::IS_MINPLAYERS])
	{
		// a newly connected player (including a bot) can replace a bot:
		if(cur_players.size() == Config::int_settings[Config::IS_MINPLAYERS]+1)
			drop_a_bot(); // if no bots, okay
		// or this might be our first human player?
		else if(cur_players.size() == 1)
		{
			// players won't get added to cur_players until later, so
			// record locally how many have been added
			unsigned short np = 1;
			while(np < Config::int_settings[Config::IS_MINPLAYERS]
				&& !spawn_bot())
				++np;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movl %ecx, -0x2c(%rbp)
movq %rdx, %r15
movq %rsi, -0x38(%rbp)
movq %rdi, %r12
movq 0x2fb37(%rip), %rbx     # 0x430c0
leaq 0x2fb30(%rip), %r13     # 0x430c0
cmpq %r13, %rbx
je 0x1378f
movq 0xa0(%rbx), %r14
cmpq 0x8(%r12), %r14
jne 0x135c3
testq %r14, %r14
je 0x135c8
movq (%r12), %rsi
movq 0x98(%rbx), %rdi
movq %r14, %rdx
callq 0x4400
testl %eax, %eax
je 0x135f4
movq (%rbx), %rbx
jmp 0x13590
leaq -0x1b0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq $0x0, -0x1b8(%rbp)
movb $0x0, -0x1b0(%rbp)
movw $0x1, %bx
xorl %r14d, %r14d
jmp 0x136bd
movq (%r12), %rax
movsbl -0x1(%rax,%r14), %ecx
leal -0x30(%rcx), %edx
cmpl $0x9, %edx
ja 0x1362f
leaq (%rax,%r14), %rsi
decq %rsi
movswl %cx, %ebx
addl $-0x30, %ebx
subq %rax, %rsi
movl $0x1, %edx
movq %r12, %rdi
callq 0x4480
movq 0x8(%r12), %r14
testq %r14, %r14
jne 0x13631
jmp 0x13673
xorl %ebx, %ebx
movq (%r12), %rax
movsbl -0x1(%rax,%r14), %ecx
leal -0x30(%rcx), %edx
cmpl $0x9, %edx
ja 0x13673
leaq (%rax,%r14), %rsi
decq %rsi
movswl %cx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
movswl %bx, %edx
leal (%rdx,%rcx), %ebx
addl $0xfffffe20, %ebx       # imm = 0xFFFFFE20
subq %rax, %rsi
movl $0x1, %edx
movq %r12, %rdi
callq 0x4480
movb $0x1, %r14b
jmp 0x13676
xorl %r14d, %r14d
leaq -0x1b0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq $0x0, -0x1b8(%rbp)
movb $0x0, -0x1b0(%rbp)
incl %ebx
cmpw $0x64, %bx
jne 0x136bd
movl $0x2, %r8d
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x1930a(%rip), %rcx     # 0x2c9c0
callq 0x4630
jmp 0x136f4
movzwl %bx, %esi
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x2ba03
leaq -0x1c0(%rbp), %rdi
movq %rbx, %rsi
callq 0x44c0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x136f4
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
testb %r14b, %r14b
je 0x1371b
cmpq $0x1, -0x1b8(%rbp)
jne 0x1371b
movl $0x1, %edx
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %ecx
callq 0x47e0
movq %r12, %rdi
callq 0x2b440
movswq %ax, %rax
movq -0x1b8(%rbp), %rdx
addq %rdx, %rax
cmpq $0xb, %rax
jb 0x1374e
movq %r12, %rdi
callq 0x2b440
movswl %ax, %esi
decl %esi
movq %r12, %rdi
callq 0x2b144
jmp 0x1371b
movq -0x1c0(%rbp), %rsi
movq %r12, %rdi
callq 0x4130
movq 0x2f95c(%rip), %rbx     # 0x430c0
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x13590
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x13590
leaq -0x1c0(%rbp), %rbx
movq %rbx, %rdi
callq 0x148d2
leaq 0x2f91b(%rip), %r14     # 0x430c0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x14978
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4060
incq 0x2f90b(%rip)           # 0x430d0
leaq -0x1c0(%rbp), %rdi
callq 0x12410
leaq 0x10(%rbx), %r13
movq %r15, 0x90(%rbx)
leaq 0x138(%r15), %rdi
callq 0x43b0
addq $0x20, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x41f0
movq %rbx, %rdi
addq $0x98, %rdi
movq %r15, %rsi
callq 0x41f0
movl $0x10, %ecx
movq %r13, %rdi
movq -0x38(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
movb %al, 0x15d(%rbx)
movb %al, 0xba(%rbx)
movq %r14, 0x160(%rbx)
movb %al, 0x141(%rbx)
movb %al, 0xe2(%rbx)
movw %ax, 0x13a(%rbx)
movw %ax, 0xe0(%rbx)
movb %al, 0x138(%rbx)
leaq 0x3140c(%rip), %rcx     # 0x44c60
movzwl (%rcx), %ecx
movw %cx, 0xb8(%rbx)
movabsq $0x800000000, %rcx      # imm = 0x800000000
movq %rcx, 0x168(%rbx)
movl $0x8, 0x13c(%rbx)
movabsq $0xb00000002, %rcx      # imm = 0xB00000002
movq %rcx, 0xbc(%rbx)
movl $0xb, 0xc4(%rbx)
movb %al, 0x172(%rbx)
movb %al, 0x142(%rbx)
movb %al, 0x153(%rbx)
movl $0xffffffff, 0x174(%rbx) # imm = 0xFFFFFFFF
movl $0x48, %edi
callq 0x43e0
movq %rax, %r14
movq %rax, %rdi
callq 0x1dcc0
movq %r14, 0xd0(%rbx)
movq %rbx, 0x28(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ebea
movq 0xd0(%rbx), %rax
movq %rax, 0xd8(%rbx)
leaq 0x2efb0(%rip), %rbx     # 0x428a0
movl 0x2c(%rbx), %eax
testl %eax, %eax
sete %cl
orb -0x2c(%rbp), %cl
jne 0x13940
movq 0x2f7cc(%rip), %rcx     # 0x430d0
leal 0x1(%rax), %edx
cmpq %rdx, %rcx
jne 0x13913
callq 0x2a7f1
jmp 0x13940
cmpq $0x1, %rcx
sete %cl
cmpl $0x2, %eax
setae %al
andb %cl, %al
cmpb $0x1, %al
jne 0x13940
movw $0x2, %r14w
callq 0x2a6b4
testb %al, %al
jne 0x13940
movzwl %r14w, %eax
incl %r14d
cmpl %eax, 0x2c(%rbx)
ja 0x1392b
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movl $0x48, %esi
movq %r14, %rdi
jmp 0x13994
movq %rax, %r15
leaq -0x1c0(%rbp), %rdi
callq 0x12410
jmp 0x13999
jmp 0x13974
jmp 0x13974
movq %rax, %r15
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x13999
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %r15, %rdi
callq 0x4740