// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movl %edi, -0x2c(%rbp)
movslq %edi, %rax
imulq $0x48, %rax, %rax
leaq 0x5b66(%rip), %rcx      # 0x8180
leaq (%rax,%rcx), %r14
addq $0x19, %r14
leaq 0x20(%rax,%rcx), %r9
movq 0x59c2(%rip), %rax      # 0x7ff0
movq (%rax), %rdi
leaq 0x2223(%rip), %rsi      # 0x485b
leaq 0x2264(%rip), %rdx      # 0x48a3
xorl %r12d, %r12d
movl $0x1ff, %ecx            # imm = 0x1FF
movq %r14, %r8
movq %r9, -0x38(%rbp)
xorl %eax, %eax
callq 0x10d0
leaq 0x9494(%rip), %rbx      # 0xbaf0
pushq $0x6
popq %r13
leaq 0xe(%r12), %r15
cmpq $0x9a, %r15
je 0x26b8
addq %rbx, %r12
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1050
movq %r15, %r12
testl %eax, %eax
jne 0x2660
movq 0x5963(%rip), %rax      # 0x7ff0
movq (%rax), %rdi
leaq 0x2229(%rip), %rsi      # 0x48c0
leaq 0x2205(%rip), %rdx      # 0x48a3
movl $0x205, %ecx            # imm = 0x205
movq %r14, %r8
movq -0x38(%rbp), %r9
xorl %eax, %eax
callq 0x10d0
pushq $0x3
jmp 0x278c
leaq 0x5a41(%rip), %rdi      # 0x8100
callq 0x1170
movl 0x94b1(%rip), %r12d     # 0xbb7c
cmpl $0x9, %r12d
jg 0x26de
leal 0x1(%r12), %eax
movl %eax, 0x94a0(%rip)      # 0xbb7c
jmp 0x26e2
pushq $-0x1
popq %r12
leaq 0x5a17(%rip), %rdi      # 0x8100
callq 0x1100
movq 0x58fb(%rip), %r15      # 0x7ff0
movq (%r15), %rdi
leaq 0x21fd(%rip), %rsi      # 0x48fc
leaq 0x219d(%rip), %rdx      # 0x48a3
movl $0x20f, %ecx            # imm = 0x20F
movl %r12d, %r8d
xorl %eax, %eax
callq 0x10d0
movq (%r15), %rdi
cmpl $-0x1, %r12d
jne 0x273f
leaq 0x2210(%rip), %rsi      # 0x4935
leaq 0x2177(%rip), %rdx      # 0x48a3
movl $0x211, %ecx            # imm = 0x211
movq %r14, %r8
xorl %eax, %eax
callq 0x10d0
pushq $0x2
jmp 0x278c
leaq 0x2221(%rip), %rsi      # 0x4967
leaq 0x2156(%rip), %rdx      # 0x48a3
movl $0x214, %ecx            # imm = 0x214
movq %r14, %r8
xorl %eax, %eax
callq 0x10d0
movslq %r12d, %rax
imulq $0xe, %rax, %r15
leaq (%rbx,%r15), %rdi
pushq $0x6
popq %r12
movq %r14, %rsi
movq %r12, %rdx
callq 0x1040
leaq (%r15,%rbx), %rdi
addq $0x7, %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
callq 0x1040
pushq $0x1
popq %rsi
movl -0x2c(%rbp), %edi
callq 0x1e05
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq