// File: /workspace/github_c_makefile_star2_O0/wierton[P]socket-based-naive-game/server.c
// Function: main
int main() {
	srand(time(NULL));

	pthread_t thread;

	if(signal(SIGINT, terminate_process) == SIG_ERR) {
		eprintf("An error occurred while setting a signal handler.\n");
	}

	for(int i = 0; i < USER_CNT; i++) {
		pthread_mutex_init(&items_lock[i], NULL);
	}

	server_fd = server_start();

	for(int i = 0; i < USER_CNT; i++)
		sessions[i].conn = -1;

	struct sockaddr_in client_addr;
	socklen_t length = sizeof(client_addr);
	while(1) {
		int conn = accept(server_fd, (struct sockaddr*)&client_addr, &length);
		log("connected by %s:%d, conn:%d\n", inet_ntoa(client_addr.sin_addr), client_addr.sin_port, conn);
		if(conn < 0) {
			loge("fail to accept client.\n");
		}else if(pthread_create(&thread, NULL, session_start, (void *)(uintptr_t)conn) != 0) {
			loge("fail to create thread.\n");
		}
		logi("bind thread #%lu\n", thread);
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x1110
movl %eax, %edi
callq 0x10e0
movl $0x2, %edi
leaq -0x17b(%rip), %rsi      # 0x54c0
callq 0x1100
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x5679
jmp 0x564e
movq 0x49a3(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2175(%rip), %rsi      # 0x77d4
leaq 0x21bb(%rip), %rdx      # 0x7821
movl $0x41c, %ecx            # imm = 0x41C
movb $0x0, %al
callq 0x10f0
xorl %edi, %edi
callq 0x1170
movl $0x0, -0x14(%rbp)
cmpl $0x5, -0x14(%rbp)
jge 0x56ac
movslq -0x14(%rbp), %rax
leaq 0x842f(%rip), %rdi      # 0xdac0
imulq $0x28, %rax, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1180
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5680
callq 0x53b0
movl %eax, 0x4b61(%rip)      # 0xa218
movl $0x0, -0x18(%rbp)
cmpl $0x5, -0x18(%rbp)
jge 0x56e8
movslq -0x18(%rbp), %rcx
leaq 0x4b51(%rip), %rax      # 0xa220
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x56be
movl $0x10, -0x2c(%rbp)
movl 0x4b23(%rip), %edi      # 0xa218
leaq -0x28(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x1160
movl %eax, -0x30(%rbp)
movq 0x48ec(%rip), %rax      # 0x9ff8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %edi
callq 0x1060
movq -0x38(%rbp), %rdi
movq %rax, %r8
movzwl -0x26(%rbp), %r9d
movl -0x30(%rbp), %eax
leaq 0x20f5(%rip), %rsi      # 0x7826
leaq 0x20e9(%rip), %rdx      # 0x7821
movl $0x42c, %ecx            # imm = 0x42C
movl %eax, (%rsp)
movb $0x0, %al
callq 0x10f0
cmpl $0x0, -0x30(%rbp)
jge 0x5773
movq 0x48a4(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x20fd(%rip), %rsi      # 0x785b
leaq 0x20bc(%rip), %rdx      # 0x7821
movl $0x42e, %ecx            # imm = 0x42E
movb $0x0, %al
callq 0x10f0
jmp 0x57b6
movslq -0x30(%rbp), %rcx
leaq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x566(%rip), %rdx      # 0x5220
callq 0x1150
cmpl $0x0, %eax
je 0x57b4
movq 0x4861(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x20ec(%rip), %rsi      # 0x788d
leaq 0x2079(%rip), %rdx      # 0x7821
movl $0x430, %ecx            # imm = 0x430
movb $0x0, %al
callq 0x10f0
jmp 0x57b6
movq 0x483b(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq -0x10(%rbp), %r8
leaq 0x20f4(%rip), %rsi      # 0x78bf
leaq 0x204f(%rip), %rdx      # 0x7821
movl $0x432, %ecx            # imm = 0x432
movb $0x0, %al
callq 0x10f0
jmp 0x56ef