// File: Thomas1995[P]Rentz/src/server.cpp
// Function: main
int main(int argc, char ** argv) {

  if(argc != 2) {
    printf("Usage: %s number-of-clients\n", argv[0]);
    exit(1);
  }

  int clientsNumber = atoi(argv[1]);

  require(clientsNumber >= 3 && clientsNumber <= 6,
    "The numbers of clients in a game should be between 3 and 6.\n");

  Table::TABLE_SIZE = clientsNumber;

  Table table;
  Server server;

  while(true) {
    const int n = server.poll();
    //there are n new incoming connections
    for(int i = 0; i < n; ++i) {
      const int client = server.acceptConnection();
      
      if(table.GAME_END) {
          Table newTable;
          table = newTable;
      }

      table.addPlayer(client);
    }

    std::this_thread::sleep_for(std::chrono::milliseconds(100));
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x649e
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xfc16(%rip), %rdi      # 0x160a3
movb $0x0, %al
callq 0x3060
movl $0x1, %edi
callq 0x33a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3490
movl %eax, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x3, -0x14(%rbp)
movb %al, -0x135(%rbp)
jl 0x64c9
cmpl $0x6, -0x14(%rbp)
setle %al
movb %al, -0x135(%rbp)
movb -0x135(%rbp), %al
movb %al, -0x141(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x34e0
movq -0x140(%rbp), %rdx
leaq 0xfbcd(%rip), %rsi      # 0x160c0
leaq -0x38(%rbp), %rdi
callq 0x5640
jmp 0x64fe
movb -0x141(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq -0x38(%rbp), %rsi
callq 0x14a60
jmp 0x6515
leaq -0x38(%rbp), %rdi
callq 0x31c0
leaq -0x39(%rbp), %rdi
callq 0x3330
movl -0x14(%rbp), %ecx
leaq 0x1ae6f(%rip), %rax     # 0x213a0
movl %ecx, (%rax)
leaq -0xb0(%rbp), %rdi
callq 0xedf0
leaq -0xb8(%rbp), %rdi
callq 0x66e0
jmp 0x654d
jmp 0x654f
jmp 0x6551
leaq -0xb8(%rbp), %rdi
callq 0x68b0
movl %eax, -0x148(%rbp)
jmp 0x6565
movl -0x148(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0x667f
leaq -0xb8(%rbp), %rdi
callq 0x69c0
movl %eax, -0x14c(%rbp)
jmp 0x65a1
movl -0x14c(%rbp), %eax
movl %eax, -0xc4(%rbp)
testb $0x1, -0xb0(%rbp)
je 0x6655
leaq -0x128(%rbp), %rdi
callq 0xedf0
jmp 0x65c8
leaq -0xb0(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x6b10
jmp 0x65dd
leaq -0x128(%rbp), %rdi
callq 0x6ba0
jmp 0x6655
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x660e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31c0
leaq -0x39(%rbp), %rdi
callq 0x3330
jmp 0x66c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x66bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x66b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x6ba0
jmp 0x66b1
movl -0xc4(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0x10100
jmp 0x6669
jmp 0x666b
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x657b
movl $0x64, -0x134(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x134(%rbp), %rsi
callq 0x6c90
jmp 0x669e
leaq -0x130(%rbp), %rdi
callq 0x6be0
jmp 0x66ac
jmp 0x654f
leaq -0xb8(%rbp), %rdi
callq 0x6cb0
leaq -0xb0(%rbp), %rdi
callq 0x6ba0
movq -0x48(%rbp), %rdi
callq 0x34d0
nopw %cs:(%rax,%rax)
nopl (%rax)