// File: /workspace/github_c_makefile_star2_O1/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 0x7cd9(%rip), %rcx      # 0x9180
leaq (%rax,%rcx), %r14
addq $0x19, %r14
leaq 0x20(%rax,%rcx), %r15
movq 0x7b35(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
leaq 0x4396(%rip), %rsi      # 0x585b
leaq 0x43d7(%rip), %rdx      # 0x58a3
xorl %ebx, %ebx
movl $0x1ff, %ecx            # imm = 0x1FF
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x10d0
leaq 0xb609(%rip), %r13      # 0xcaf0
pushq $0x6
popq %r12
leaq (%rbx,%r13), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x1050
testl %eax, %eax
je 0x1531
addq $0xe, %rbx
cmpq $0x8c, %rbx
jne 0x14eb
leaq 0x7bee(%rip), %rdi      # 0x9100
callq 0x1170
movl 0xb65e(%rip), %r12d     # 0xcb7c
cmpl $0x9, %r12d
jg 0x1562
leal 0x1(%r12), %eax
movl %eax, 0xb64d(%rip)      # 0xcb7c
jmp 0x1566
movq 0x7ab8(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
leaq 0x437e(%rip), %rsi      # 0x58c0
leaq 0x435a(%rip), %rdx      # 0x58a3
movl $0x205, %ecx            # imm = 0x205
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x10d0
pushq $0x3
jmp 0x160f
pushq $-0x1
popq %r12
movq 0x7a83(%rip), %rbx      # 0x8ff0
leaq 0x7b8c(%rip), %rdi      # 0x9100
callq 0x1100
movq (%rbx), %rdi
leaq 0x4379(%rip), %rsi      # 0x58fc
leaq 0x4319(%rip), %rdx      # 0x58a3
movl $0x20f, %ecx            # imm = 0x20F
movl %r12d, %r8d
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rdi
cmpl $-0x1, %r12d
jne 0x15c3
leaq 0x438c(%rip), %rsi      # 0x5935
leaq 0x42f3(%rip), %rdx      # 0x58a3
movl $0x211, %ecx            # imm = 0x211
movq %r14, %r8
xorl %eax, %eax
callq 0x10d0
pushq $0x2
jmp 0x160f
leaq 0x439d(%rip), %rsi      # 0x5967
leaq 0x42d2(%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 0x357d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq