// File: 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
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x290(%rbp)
movb %cl, %al
movq %rdx, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq 0x6cde4(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x18a20
leaq 0x6cdc7(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x18a20
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x24f10
testb $0x1, %al
jne 0x23495
jmp 0x237d2
leaq -0x28(%rbp), %rdi
callq 0x24f40
movq -0x290(%rbp), %rsi
movq %rax, %rdi
addq $0x88, %rdi
callq 0x18960
testb $0x1, %al
jne 0x234bd
jmp 0x237c4
movq -0x290(%rbp), %rdi
movw $0x0, -0x42(%rbp)
movb $0x0, -0x43(%rbp)
callq 0x58d0
testb $0x1, %al
jne 0x23579
movq -0x290(%rbp), %rdi
callq 0x5340
movq -0x290(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x5a10
movsbl (%rax), %edi
callq 0x5480
cmpl $0x0, %eax
je 0x23579
movq -0x290(%rbp), %rdi
callq 0x5340
movq -0x290(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x5a10
movq -0x290(%rbp), %rdi
movsbl (%rax), %ecx
subl $0x30, %ecx
movzwl -0x42(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x42(%rbp)
callq 0x52c0
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rdi
movl $0x1, %esi
callq 0x268e0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x26920
movq -0x290(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x5650
movq %rax, -0x68(%rbp)
movq -0x290(%rbp), %rdi
callq 0x58d0
testb $0x1, %al
jne 0x23635
movq -0x290(%rbp), %rdi
callq 0x5340
movq -0x290(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x5a10
movsbl (%rax), %edi
callq 0x5480
cmpl $0x0, %eax
je 0x23635
movq -0x290(%rbp), %rdi
callq 0x5340
movq -0x290(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x5a10
movq -0x290(%rbp), %rdi
movsbl (%rax), %eax
subl $0x30, %eax
imull $0xa, %eax, %ecx
movzwl -0x42(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x42(%rbp)
callq 0x52c0
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x268e0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x26920
movq -0x290(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x5650
movq %rax, -0x88(%rbp)
movb $0x1, -0x43(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5770
movw -0x42(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x42(%rbp)
movzwl -0x42(%rbp), %eax
cmpl $0x64, %eax
jne 0x23690
leaq 0x3e368(%rip), %rsi     # 0x619c5
leaq -0xa8(%rbp), %rdi
callq 0x5760
jmp 0x2366b
jmp 0x236c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a48
jmp 0x23c5f
movzwl -0x42(%rbp), %esi
leaq -0xd8(%rbp), %rdi
callq 0x609d0
jmp 0x236a2
leaq -0xa8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5640
leaq -0xd8(%rbp), %rdi
callq 0x5a48
testb $0x1, -0x43(%rbp)
je 0x236f7
leaq -0xa8(%rbp), %rdi
callq 0x5340
cmpq $0x1, %rax
jne 0x236f7
xorl %eax, %eax
movl %eax, %esi
leaq -0xa8(%rbp), %rdi
movl $0x1, %edx
movl $0x30, %ecx
callq 0x5a20
jmp 0x236f5
jmp 0x236f7
jmp 0x236f9
movq -0x290(%rbp), %rdi
callq 0x5fe20
movw %ax, -0x292(%rbp)
jmp 0x2370e
movw -0x292(%rbp), %ax
movswq %ax, %rax
movq %rax, -0x2a0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5340
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
addq %rcx, %rax
cmpq $0xa, %rax
jbe 0x23770
movq -0x290(%rbp), %rdi
callq 0x5fe20
movw %ax, -0x2a2(%rbp)
jmp 0x23754
movq -0x290(%rbp), %rdi
movw -0x2a2(%rbp), %ax
movswl %ax, %esi
decl %esi
callq 0x5f890
jmp 0x2376e
jmp 0x236f9
movq -0x290(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x56e0
jmp 0x23785
leaq 0x6caa4(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x18a20
movq -0xe0(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a48
jmp 0x237cd
leaq -0x28(%rbp), %rdi
callq 0x250a0
jmp 0x23462
leaq 0x6ca57(%rip), %rdi     # 0x90230
movq %rdi, -0x2c0(%rbp)
callq 0x189f0
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x18a20
leaq -0x268(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x269a0
movq -0x2c0(%rbp), %rdi
movq -0x2b8(%rbp), %rdx
movq -0xf8(%rbp), %rsi
callq 0x26960
movq %rax, -0x2b0(%rbp)
jmp 0x23835
movq -0x2b0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x21c20
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq %rcx, 0x80(%rax)
callq 0x1b050
movq %rax, %rdi
subq $-0x80, %rdi
callq 0x1b390
movq %rax, %rdi
addq $0x128, %rdi            # imm = 0x128
callq 0x54c0
leaq -0x8(%rbp), %rdi
callq 0x1b390
movq -0x290(%rbp), %rsi
movq %rax, %rdi
addq $0x10, %rdi
callq 0x5050
movq -0x2d0(%rbp), %rdi
movq %rax, -0x2f0(%rbp)
callq 0x1b050
movq -0x2f0(%rbp), %rsi
movq %rax, %rdi
addq $0x88, %rdi
callq 0x5050
movq -0x2d0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x2e8(%rbp)
callq 0x1b050
movq -0x2e8(%rbp), %rcx
movq -0x2d0(%rbp), %rdi
movq %rax, -0x2e0(%rbp)
movups 0x70(%rcx), %xmm0
movups %xmm0, 0x70(%rax)
movups 0x60(%rcx), %xmm0
movups %xmm0, 0x60(%rax)
movups 0x50(%rcx), %xmm0
movups %xmm0, 0x50(%rax)
movups 0x40(%rcx), %xmm0
movups %xmm0, 0x40(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups 0x30(%rcx), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movb $0x0, 0x14d(%rax)
callq 0x1b050
movb $0x0, 0xaa(%rax)
leaq 0x6c8c7(%rip), %rdi     # 0x90230
callq 0x189f0
movq -0x2d0(%rbp), %rdi
movq %rax, -0x270(%rbp)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movq -0x270(%rbp), %rcx
movq %rcx, 0x150(%rax)
callq 0x1b050
movq %rax, %rdi
callq 0x21c90
movq -0x2d0(%rbp), %rdi
leaq 0x6e41f(%rip), %rax     # 0x91dd0
movw (%rax), %ax
movw %ax, -0x2d2(%rbp)
callq 0x1b050
movw -0x2d2(%rbp), %cx
movq -0x2d0(%rbp), %rdi
movw %cx, 0xa8(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0x0, 0x158(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0x8, 0x12c(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0x8, 0x15c(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0x2, 0xac(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0xb, 0xb4(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movl $0xb, 0xb0(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movb $0x0, 0x162(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movb $0x0, 0x132(%rax)
callq 0x1b050
movq -0x2d0(%rbp), %rdi
movb $0x0, 0x143(%rax)
callq 0x1b050
movl $0xffffffff, 0x164(%rax) # imm = 0xFFFFFFFF
movl $0x48, %edi
callq 0x5520
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x2c8(%rbp)
callq 0x40d10
jmp 0x23abf
leaq -0xf0(%rbp), %rdi
callq 0x1b050
movq -0x2c8(%rbp), %rcx
movq %rcx, 0xc0(%rax)
leaq -0x278(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x18a20
movq -0x2c8(%rbp), %rdi
movq -0x278(%rbp), %rsi
callq 0x26a30
leaq -0xf0(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
movq -0xf0(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rsi
callq 0x42770
leaq -0xf0(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rax
movq %rax, -0x2f8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x1b050
movq -0x2f8(%rbp), %rcx
movq %rcx, 0xc8(%rax)
testb $0x1, -0x19(%rbp)
jne 0x23c56
leaq 0x6be9f(%rip), %rax     # 0x8fa10
cmpl $0x0, 0x2c(%rax)
je 0x23c56
leaq 0x6c6ae(%rip), %rdi     # 0x90230
callq 0x25070
leaq 0x6be82(%rip), %rcx     # 0x8fa10
movl 0x2c(%rcx), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x23bed
callq 0x5d300
jmp 0x23c54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x21c20
jmp 0x23c5f
movq -0x2c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
movl $0x48, %esi
callq 0x5530
jmp 0x23c5f
leaq 0x6c63c(%rip), %rdi     # 0x90230
callq 0x25070
cmpq $0x1, %rax
jne 0x23c52
movw $0x1, -0x282(%rbp)
movzwl -0x282(%rbp), %ecx
xorl %eax, %eax
leaq 0x6bdf8(%rip), %rdx     # 0x8fa10
cmpl 0x2c(%rdx), %ecx
movb %al, -0x2f9(%rbp)
jae 0x23c30
callq 0x5d0d0
xorb $-0x1, %al
movb %al, -0x2f9(%rbp)
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x23c3c
jmp 0x23c50
movw -0x282(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x282(%rbp)
jmp 0x23c08
jmp 0x23c52
jmp 0x23c54
jmp 0x23c56
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x5920
nopl (%rax,%rax)