// File: /workspace/github_c_makefile_star2_O0/wierton[P]socket-based-naive-game/server.c
// Function: client_command_user_login
int client_command_user_login(int uid) {
	int is_dup = 0;
	client_message_t *pcm = &sessions[uid].cm;
	char *user_name = pcm->user_name;
	char *password = pcm->password;
	log("user '%s' try to login\n", user_name);
	int message = check_user_registered(user_name, password);

	if(query_session_built(uid)) {
		log("user '%s' has logined\n", sessions[uid].user_name);
		send_to_client(uid, SERVER_RESPONSE_YOU_HAVE_LOGINED);
		return 0;
	}


	for(int i = 0; i < USER_CNT; i++) {
		if(query_session_built(i)) {
			logi("check dup user id: '%s' vs. '%s'\n", user_name, sessions[i].user_name);
			if(strncmp(user_name, sessions[i].user_name, USERNAME_SIZE - 1) == 0) {
				log("user %d@%s duplicate with %dth user '%s'\n", uid, user_name, i, sessions[i].user_name);
				is_dup = 1;
				break;
			}
		}
	}

	// no duplicate user ids found
	if(is_dup) {
		log("send fail dup id message to client.\n");
		send_to_client(uid, SERVER_RESPONSE_LOGIN_FAIL_DUP_USERID);
		sessions[uid].state = USER_STATE_NOT_LOGIN;
	}else if(message == SERVER_RESPONSE_LOGIN_SUCCESS){
		log("user '%s' login success\n", user_name);
		sessions[uid].state = USER_STATE_LOGIN;
		send_to_client(uid, SERVER_RESPONSE_LOGIN_SUCCESS);
		strncpy(sessions[uid].user_name, user_name, USERNAME_SIZE - 1);
		inform_friends(uid, SERVER_MESSAGE_FRIEND_LOGIN);
	}else{
		send_to_client(uid, message);
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x6aa3(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq 0x684d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq -0x20(%rbp), %r8
leaq 0x31e3(%rip), %rsi      # 0x699c
leaq 0x320c(%rip), %rdx      # 0x69cc
movl $0x223, %ecx            # imm = 0x223
movb $0x0, %al
callq 0x10f0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x33b0
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %edi
callq 0x12d0
cmpl $0x0, %eax
je 0x3838
movq 0x6808(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0x8(%rbp), %rax
leaq 0x6a22(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
leaq 0x31da(%rip), %rsi      # 0x69e6
leaq 0x31b9(%rip), %rdx      # 0x69cc
movl $0x227, %ecx            # imm = 0x227
movb $0x0, %al
callq 0x10f0
movl -0x8(%rbp), %edi
movl $0x5, %esi
callq 0x25e0
movl $0x0, -0x4(%rbp)
jmp 0x3a0b
movl $0x0, -0x30(%rbp)
cmpl $0x5, -0x30(%rbp)
jge 0x391f
movl -0x30(%rbp), %edi
callq 0x12d0
cmpl $0x0, %eax
je 0x390f
movq 0x6797(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq -0x20(%rbp), %r8
movslq -0x30(%rbp), %rax
leaq 0x69ad(%rip), %r9       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r9
leaq 0x3194(%rip), %rsi      # 0x6a15
leaq 0x3144(%rip), %rdx      # 0x69cc
movl $0x22f, %ecx            # imm = 0x22F
movb $0x0, %al
callq 0x10f0
movq -0x20(%rbp), %rdi
movslq -0x30(%rbp), %rax
leaq 0x697d(%rip), %rsi      # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %rsi
movl $0x6, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x390d
movq 0x6738(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0x8(%rbp), %r8d
movq -0x20(%rbp), %r9
movl -0x30(%rbp), %r10d
movslq -0x30(%rbp), %rcx
leaq 0x6946(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
leaq 0x316b(%rip), %rsi      # 0x6a53
leaq 0x30dd(%rip), %rdx      # 0x69cc
movl $0x231, %ecx            # imm = 0x231
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x10f0
movl $0x1, -0xc(%rbp)
jmp 0x391f
jmp 0x390f
jmp 0x3911
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x383f
cmpl $0x0, -0xc(%rbp)
je 0x3974
movq 0x66cc(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x315f(%rip), %rsi      # 0x6a95
leaq 0x308f(%rip), %rdx      # 0x69cc
movl $0x23a, %ecx            # imm = 0x23A
movb $0x0, %al
callq 0x10f0
movl -0x8(%rbp), %edi
movl $0x9, %esi
callq 0x25e0
movslq -0x8(%rbp), %rcx
leaq 0x68bf(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0xc(%rax)
jmp 0x3a04
cmpl $0x4, -0x2c(%rbp)
jne 0x39f7
movq 0x6677(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq -0x20(%rbp), %r8
leaq 0x3143(%rip), %rsi      # 0x6ad2
leaq 0x3036(%rip), %rdx      # 0x69cc
movl $0x23e, %ecx            # imm = 0x23E
movb $0x0, %al
callq 0x10f0
movslq -0x8(%rbp), %rcx
leaq 0x6873(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x2, 0xc(%rax)
movl -0x8(%rbp), %edi
movl $0x4, %esi
callq 0x25e0
movslq -0x8(%rbp), %rax
leaq 0x684d(%rip), %rdi      # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl $0x6, %edx
callq 0x1040
movl -0x8(%rbp), %edi
movl $0x14, %esi
callq 0x1da0
jmp 0x3a02
movl -0x8(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x25e0
jmp 0x3a04
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)