// File: /workspace/github_c_makefile_star2_O0/wierton[P]socket-based-naive-game/server.c
// Function: user_quit_battle
void user_quit_battle(uint32_t bid, uint32_t uid) {
	assert(bid < USER_CNT && uid < USER_CNT);

	log("user %s quit from battle %d(%d users)\n", sessions[uid].user_name, bid, battles[bid].nr_users);
	battles[bid].nr_users --;
	battles[bid].users[uid].battle_state = BATTLE_STATE_UNJOINED;
	sessions[uid].state = USER_STATE_LOGIN;

	if(battles[bid].nr_users == 0) {
		// disband battle
		log("disband battle %d\n", bid);
		battles[bid].is_alloced = false;
	}else{
		server_message_t sm;
		sm.message = SERVER_MESSAGE_USER_QUIT_BATTLE;
		strncpy(sm.friend_name, sessions[uid].user_name, USERNAME_SIZE - 1);

		for(int i = 0; i < USER_CNT; i++) {
			if(battles[bid].users[i].battle_state != BATTLE_STATE_UNJOINED) {

				wrap_send(sessions[i].conn, &sm);
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
cmpl $0x5, -0x4(%rbp)
jae 0x136f
cmpl $0x5, -0x8(%rbp)
jae 0x136f
jmp 0x138e
leaq 0x4cc9(%rip), %rdi      # 0x603f
leaq 0x4c97(%rip), %rsi      # 0x6014
movl $0x55, %edx
leaq 0x4cd7(%rip), %rcx      # 0x6060
callq 0x10a0
movq 0x8c63(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0x8(%rbp), %eax
leaq 0x8e7e(%rip), %r8       # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %r8
movl -0x4(%rbp), %r9d
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8fd7(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
movq 0x8(%rax), %rax
leaq 0x4cbc(%rip), %rsi      # 0x608a
leaq 0x4cf4(%rip), %rdx      # 0x60c9
movl $0x57, %ecx
movq %rax, (%rsp)
movb $0x0, %al
callq 0x10f0
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8f9f(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8f7d(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
addq $0x10, %rax
movl -0x8(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x8de3(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x2, 0xc(%rax)
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8f39(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x14b1
movq 0x8b89(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0x4(%rbp), %r8d
leaq 0x4c5d(%rip), %rsi      # 0x60da
leaq 0x4c45(%rip), %rdx      # 0x60c9
movl $0x5e, %ecx
movb $0x0, %al
callq 0x10f0
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8ef4(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
movl $0x0, (%rax)
jmp 0x1557
movb $0x1c, -0x1ab(%rbp)
leaq -0x1ab(%rbp), %rdi
addq $0x1, %rdi
movl -0x8(%rbp), %eax
leaq 0x8d53(%rip), %rsi      # 0xa220
imulq $0x48, %rax, %rax
addq %rax, %rsi
movl $0x6, %edx
callq 0x1040
movl $0x0, -0x1b0(%rbp)
cmpl $0x5, -0x1b0(%rbp)
jge 0x1555
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x8e93(%rip), %rax      # 0xa390
imulq $0xb08, %rcx, %rcx      # imm = 0xB08
addq %rcx, %rax
addq $0x10, %rax
movslq -0x1b0(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
je 0x1542
movslq -0x1b0(%rbp), %rcx
leaq 0x8cf4(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edi
leaq -0x1ab(%rbp), %rsi
callq 0x1560
jmp 0x1544
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x14e8
jmp 0x1557
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq