// File: /workspace/github_c_makefile_star2_O3/wierton[P]socket-based-naive-game/server.c
// Function: client_command_user_register
int client_command_user_register(int uid) {
	int ul_index = -1;
	char *user_name = sessions[uid].cm.user_name;
	char *password = sessions[uid].cm.password;
	log("user '%s' tries to register with password '%s'\n", user_name, password);

	for(int i = 0; i < REGISTERED_USER_LIST_SIZE; i++) {
		if(strncmp(user_name, registered_user_list[i].user_name, USERNAME_SIZE - 1) != 0)
			continue;

		log("user '%s'&'%s' has been registered\n", user_name, password);
		send_to_client(uid, SERVER_RESPONSE_YOU_HAVE_REGISTERED);
		return 0;
	}

	pthread_mutex_lock(&userlist_lock);
	if(user_list_size < REGISTERED_USER_LIST_SIZE)
		ul_index = user_list_size ++;
	pthread_mutex_unlock(&userlist_lock);

	log("fetch empty user list index #%d\n", ul_index);
	if(ul_index == -1) {
		log("user '%s' registers fail\n", user_name);
		send_to_client(uid, SERVER_RESPONSE_REGISTER_FAIL);
	}else{
		log("user '%s' registers success\n", user_name);
		strncpy(registered_user_list[ul_index].user_name,
				user_name, USERNAME_SIZE - 1);
		strncpy(registered_user_list[ul_index].password,
				password, PASSWORD_SIZE - 1);
		send_to_client(uid, SERVER_RESPONSE_REGISTER_SUCCESS);
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, -0x2c(%rbp)
movslq %edi, %rax
imulq $0x48, %rax, %rax
leaq 0x7cf0(%rip), %rcx      # 0x9180
leaq (%rax,%rcx), %r14
addq $0x19, %r14
leaq 0x20(%rax,%rcx), %r15
movq 0x7b4c(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
leaq 0x43ad(%rip), %rsi      # 0x585b
leaq 0x43ee(%rip), %rdx      # 0x58a3
xorl %ebx, %ebx
movl $0x1ff, %ecx            # imm = 0x1FF
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x10d0
leaq 0xb620(%rip), %r13      # 0xcaf0
pushq $0x6
popq %r12
leaq (%rbx,%r13), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x1050
testl %eax, %eax
je 0x151a
addq $0xe, %rbx
cmpq $0x8c, %rbx
jne 0x14d4
leaq 0x7c05(%rip), %rdi      # 0x9100
callq 0x1170
movl 0xb675(%rip), %r12d     # 0xcb7c
cmpl $0x9, %r12d
jg 0x154b
leal 0x1(%r12), %eax
movl %eax, 0xb664(%rip)      # 0xcb7c
jmp 0x154f
movq 0x7acf(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
leaq 0x4395(%rip), %rsi      # 0x58c0
leaq 0x4371(%rip), %rdx      # 0x58a3
movl $0x205, %ecx            # imm = 0x205
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x10d0
pushq $0x3
jmp 0x15f8
pushq $-0x1
popq %r12
movq 0x7a9a(%rip), %rbx      # 0x8ff0
leaq 0x7ba3(%rip), %rdi      # 0x9100
callq 0x1100
movq (%rbx), %rdi
leaq 0x4390(%rip), %rsi      # 0x58fc
leaq 0x4330(%rip), %rdx      # 0x58a3
movl $0x20f, %ecx            # imm = 0x20F
movl %r12d, %r8d
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rdi
cmpl $-0x1, %r12d
jne 0x15ac
leaq 0x43a3(%rip), %rsi      # 0x5935
leaq 0x430a(%rip), %rdx      # 0x58a3
movl $0x211, %ecx            # imm = 0x211
movq %r14, %r8
xorl %eax, %eax
callq 0x10d0
pushq $0x2
jmp 0x15f8
leaq 0x43b4(%rip), %rsi      # 0x5967
leaq 0x42e9(%rip), %rdx      # 0x58a3
movl $0x214, %ecx            # imm = 0x214
movq %r14, %r8
xorl %eax, %eax
callq 0x10d0
movslq %r12d, %rax
imulq $0xe, %rax, %rbx
leaq (%rbx,%r13), %rdi
pushq $0x6
popq %r12
movq %r14, %rsi
movq %r12, %rdx
callq 0x1040
leaq (%rbx,%r13), %rdi
addq $0x7, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1040
pushq $0x1
popq %rsi
movl -0x2c(%rbp), %edi
callq 0x359e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq