// File: /workspace/github_c_makefile_star2_O0/wierton[P]socket-based-naive-game/server.c
// Function: client_command_launch_battle
int client_command_launch_battle(int uid) {
	if(sessions[uid].state == USER_STATE_BATTLE) {
		log("user '%s' who tries to launch battle has been in battle\n", sessions[uid].user_name);
		send_to_client(uid, SERVER_RESPONSE_YOURE_ALREADY_IN_BATTLE);
		return 0;
	}else{
		log("user '%s' tries to launch battle\n", sessions[uid].user_name);
	}

	int bid = get_unalloced_battle();
	client_message_t *pcm = &sessions[uid].cm;

	log("%s launch battle with %s\n", sessions[uid].user_name, pcm->user_name);

	if(bid == -1) {
		loge("fail to create battle for %s and %s\n", sessions[uid].user_name, pcm->user_name);
		send_to_client(uid, SERVER_RESPONSE_LAUNCH_BATTLE_FAIL);
		return 0;
	}else{
		logi("launch battle %d for %s, invite %s\n", bid, sessions[uid].user_name, pcm->user_name);
		user_join_battle(bid, uid);
		invite_friend_to_battle(bid, uid, pcm->user_name);
		launch_battle(bid);
		send_to_client(uid, SERVER_RESPONSE_LAUNCH_BATTLE_SUCCESS);
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x623a(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x3, 0xc(%rax)
jne 0x4042
movq 0x5ffe(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0x8(%rbp), %rax
leaq 0x6218(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
leaq 0x2dc4(%rip), %rsi      # 0x6dda
leaq 0x2e0e(%rip), %rdx      # 0x6e2b
movl $0x2aa, %ecx            # imm = 0x2AA
movb $0x0, %al
callq 0x10f0
movl -0x8(%rbp), %edi
movl $0x10, %esi
callq 0x25e0
movl $0x0, -0x4(%rbp)
jmp 0x41b5
movq 0x5faf(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0x8(%rbp), %rax
leaq 0x61c9(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
leaq 0x2de3(%rip), %rsi      # 0x6e48
leaq 0x2dbf(%rip), %rdx      # 0x6e2b
movl $0x2ae, %ecx            # imm = 0x2AE
movb $0x0, %al
callq 0x10f0
callq 0x1b80
movl %eax, -0xc(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x6195(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
movq 0x5f57(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0x8(%rbp), %rax
leaq 0x6171(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
movq -0x18(%rbp), %r9
addq $0x1, %r9
leaq 0x2dbd(%rip), %rsi      # 0x6e82
leaq 0x2d5f(%rip), %rdx      # 0x6e2b
movl $0x2b4, %ecx            # imm = 0x2B4
movb $0x0, %al
callq 0x10f0
cmpl $-0x1, -0xc(%rbp)
jne 0x4135
movq 0x5f13(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0x8(%rbp), %rax
leaq 0x612d(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
movq -0x18(%rbp), %r9
addq $0x1, %r9
leaq 0x2dab(%rip), %rsi      # 0x6eb4
leaq 0x2d1b(%rip), %rdx      # 0x6e2b
movl $0x2b7, %ecx            # imm = 0x2B7
movb $0x0, %al
callq 0x10f0
movl -0x8(%rbp), %edi
movl $0xd, %esi
callq 0x25e0
movl $0x0, -0x4(%rbp)
jmp 0x41b5
movq 0x5ebc(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0xc(%rbp), %r8d
movslq -0x8(%rbp), %rax
leaq 0x60d2(%rip), %r9       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r9
movq -0x18(%rbp), %rax
addq $0x1, %rax
leaq 0x2d8f(%rip), %rsi      # 0x6ef3
leaq 0x2cc0(%rip), %rdx      # 0x6e2b
movl $0x2bb, %ecx            # imm = 0x2BB
movq %rax, (%rsp)
movb $0x0, %al
callq 0x10f0
movl -0xc(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0x17d0
movl -0xc(%rbp), %edi
movl -0x8(%rbp), %esi
movq -0x18(%rbp), %rdx
addq $0x1, %rdx
callq 0x3e30
movl -0xc(%rbp), %edi
callq 0x34b0
movl -0x8(%rbp), %edi
movl $0xe, %esi
callq 0x25e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop