// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1a8, %rsp            # imm = 0x1A8
movl %ecx, -0x2c(%rbp)
movq %rdx, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, %r12
movq 0x2f9ec(%rip), %r15     # 0x430c0
leaq 0x2f9e5(%rip), %rbx     # 0x430c0
cmpq %rbx, %r15
je 0x138af
leaq -0x1b8(%rbp), %r14
movq 0xa0(%r15), %rdx
movq 0x8(%r12), %r13
cmpq %r13, %rdx
jne 0x13715
testq %rdx, %rdx
je 0x1371d
movq (%r12), %rsi
movq 0x98(%r15), %rdi
callq 0x4400
testl %eax, %eax
je 0x1371d
movq (%r15), %r15
jmp 0x138a6
testq %r13, %r13
je 0x13751
movq (%r12), %rax
movsbl -0x1(%rax,%r13), %eax
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x13751
movswl %ax, %r15d
addl $-0x30, %r15d
decq %r13
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x4480
jmp 0x13754
xorl %r15d, %r15d
movq 0x8(%r12), %rsi
testq %rsi, %rsi
je 0x13799
movq (%r12), %rax
movsbl -0x1(%rax,%rsi), %eax
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x13799
cwtl
addl %eax, %eax
leal (%rax,%rax,4), %eax
movswl %r15w, %ecx
leal (%rcx,%rax), %r15d
addl $0xfffffe20, %r15d      # imm = 0xFFFFFE20
decq %rsi
movl $0x1, %edx
movq %r12, %rdi
callq 0x4480
movb $0x1, %r13b
jmp 0x1379c
xorl %r13d, %r13d
movq %r14, -0x1c8(%rbp)
movq $0x0, -0x1c0(%rbp)
movb $0x0, -0x1b8(%rbp)
incl %r15d
cmpw $0x64, %r15w
jne 0x137de
movl $0x2, %r8d
leaq -0x1c8(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x191e9(%rip), %rcx     # 0x2c9c0
callq 0x4640
jmp 0x13816
movzwl %r15w, %esi
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x2be77
leaq -0x1c8(%rbp), %rdi
movq %r15, %rsi
callq 0x44c0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x13816
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43f0
cmpq $0x1, -0x1c0(%rbp)
sete %al
andb %al, %r13b
cmpb $0x1, %r13b
jne 0x13842
movl $0x1, %edx
leaq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %ecx
callq 0x47f0
movq %r12, %rdi
callq 0x2b890
movswq %ax, %rax
movq -0x1c0(%rbp), %rdx
addq %rdx, %rax
cmpq $0xb, %rax
jb 0x13875
movq %r12, %rdi
callq 0x2b890
movswl %ax, %esi
decl %esi
movq %r12, %rdi
callq 0x2b564
jmp 0x13842
movq -0x1c8(%rbp), %rsi
movq %r12, %rdi
callq 0x4130
movq 0x2f835(%rip), %r15     # 0x430c0
movq -0x1c8(%rbp), %rdi
cmpq %r14, %rdi
je 0x138a6
movq -0x1b8(%rbp), %rsi
incq %rsi
callq 0x43f0
cmpq %rbx, %r15
jne 0x136eb
leaq -0x1c8(%rbp), %rbx
movq %rbx, %rdi
callq 0x14a0a
leaq 0x2f7fb(%rip), %r14     # 0x430c0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x14ab0
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4060
incq 0x2f7eb(%rip)           # 0x430d0
leaq -0x1c8(%rbp), %rdi
callq 0x12560
leaq 0x10(%rbx), %r13
movq -0x38(%rbp), %r15
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 -0x40(%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 0x312e8(%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 0x1de70
movq %r14, 0xd0(%rbx)
movq %rbx, 0x28(%r14)
movq 0xd0(%rbx), %rdi
movq %rbx, %rsi
callq 0x1ed84
movq 0xd0(%rbx), %rax
movq %rax, 0xd8(%rbx)
leaq 0x2ee88(%rip), %rbx     # 0x428a0
movl 0x2c(%rbx), %eax
testl %eax, %eax
sete %cl
orb -0x2c(%rbp), %cl
jne 0x13a38
movq 0x2f6a4(%rip), %rcx     # 0x430d0
incl %eax
cmpq %rax, %rcx
jne 0x13a4a
callq 0x2abe8
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x1, %rcx
jne 0x13a38
cmpl $0x2, 0x2c(%rbx)
jb 0x13a38
movw $0x2, %r14w
callq 0x2aaab
testb %al, %al
jne 0x13a38
movzwl %r14w, %eax
incl %r14d
cmpl %eax, 0x2c(%rbx)
ja 0x13a5b
jmp 0x13a38
movq %rax, %rbx
movl $0x48, %esi
movq %r14, %rdi
jmp 0x13aad
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0x12560
jmp 0x13ab2
jmp 0x13a94
jmp 0x13a94
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
cmpq %r14, %rdi
je 0x13ab2
movq -0x1b8(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %rbx, %rdi
callq 0x4750