// File: /workspace/github_cpp_makefile_star2_O2/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 0x30d82(%rip), %rbx     # 0x400b0
leaq 0x30d7b(%rip), %r15     # 0x400b0
leaq -0x1c8(%rbp), %r14
cmpq %r15, %rbx
je 0xf4aa
leaq 0x98(%rbx), %rdi
movq %r12, %rsi
callq 0xb2dd
testb %al, %al
je 0xf394
movq 0x8(%r12), %rax
testq %rax, %rax
je 0xf399
movq (%r12), %rdx
movsbl -0x1(%rdx,%rax), %ecx
leal -0x30(%rcx), %esi
cmpl $0x9, %esi
ja 0xf3a0
leaq (%rdx,%rax), %rsi
decq %rsi
movswl %cx, %ebx
addl $-0x30, %ebx
movq %r12, %rdi
callq 0x44c0
movq 0x8(%r12), %rax
testq %rax, %rax
jne 0xf3a2
jmp 0xf3d9
movq (%rbx), %rbx
jmp 0xf33c
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0xf3dc
xorl %ebx, %ebx
movq (%r12), %rdx
movsbl -0x1(%rdx,%rax), %ecx
leal -0x30(%rcx), %esi
cmpl $0x9, %esi
ja 0xf3d9
leaq (%rdx,%rax), %rsi
decq %rsi
movswl %cx, %eax
imull $0xa, %eax, %eax
movswl %bx, %ecx
leal (%rcx,%rax), %ebx
addl $0xfffffe20, %ebx       # imm = 0xFFFFFE20
movq %r12, %rdi
callq 0x44c0
movb $0x1, %r13b
jmp 0xf3dc
xorl %r13d, %r13d
leaq -0x1b8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
andq $0x0, -0x1c0(%rbp)
movb $0x0, -0x1b8(%rbp)
movswl %bx, %eax
incl %eax
cmpw $0x64, %ax
jne 0xf415
movq %r14, %rdi
leaq 0x175e7(%rip), %rsi     # 0x269f5
callq 0x4780
jmp 0xf437
movzwl %ax, %esi
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x24fde
movq %r14, %rdi
movq %rbx, %rsi
callq 0x44b0
movq %rbx, %rdi
callq 0x47e8
cmpq $0x1, -0x1c0(%rbp)
sete %al
andb %al, %r13b
cmpb $0x1, %r13b
jne 0xf45b
movq %r14, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
pushq $0x30
popq %rcx
callq 0x47c0
movq %r12, %rdi
callq 0x24af0
movswq %ax, %rax
addq -0x1c0(%rbp), %rax
cmpq $0xb, %rax
jb 0xf48b
movq %r12, %rdi
callq 0x24af0
movswl %ax, %esi
decl %esi
movq %r12, %rdi
callq 0x24904
jmp 0xf45b
movq %r12, %rdi
movq %r14, %rsi
callq 0x4790
movq 0x30c13(%rip), %rbx     # 0x400b0
movq %r14, %rdi
callq 0x47e8
jmp 0xf33c
leaq -0x1c8(%rbp), %rbx
movq %rbx, %rdi
callq 0x101b0
leaq 0x30bf0(%rip), %r14     # 0x400b0
movq %r14, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1021a
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0xe61c
leaq 0x10(%rbx), %r13
movq -0x38(%rbp), %r15
movq %r15, 0x90(%rbx)
leaq 0x138(%r15), %rdi
callq 0x43c0
addq $0x20, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x4200
movq %rbx, %rdi
addq $0x98, %rdi
movq %r15, %rsi
callq 0x4200
pushq $0x10
popq %rcx
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)
andw $0x0, 0x13a(%rbx)
andw $0x0, 0xe0(%rbx)
movb %al, 0x138(%rbx)
leaq 0x326ec(%rip), %rcx     # 0x41c50
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)
orl $-0x1, 0x174(%rbx)
pushq $0x48
popq %rdi
callq 0x43f0
movq %rax, %r14
movq %rax, %rdi
callq 0x187ac
movq %r14, 0xd0(%rbx)
movq %rbx, 0x28(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x19522
movq 0xd0(%rbx), %rax
movq %rax, 0xd8(%rbx)
leaq 0x30295(%rip), %rbx     # 0x3f890
movl 0x2c(%rbx), %eax
testl %eax, %eax
sete %cl
movl -0x2c(%rbp), %edx
orb %cl, %dl
jne 0xf63f
movq 0x30aaf(%rip), %rcx     # 0x400c0
incl %eax
cmpq %rax, %rcx
jne 0xf61f
callq 0x23ecd
jmp 0xf63f
cmpq $0x1, %rcx
jne 0xf63f
movw $0x1, %r14w
movzwl %r14w, %eax
cmpl %eax, 0x2c(%rbx)
jbe 0xf63f
callq 0x23dd2
incl %r14d
testb %al, %al
je 0xf62a
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r14, %rdi
callq 0x4400
jmp 0xf685
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0xe61c
jmp 0xf685
jmp 0xf676
jmp 0xf676
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0x47e8
movq %rbx, %rdi
callq 0x4710