// File: /workspace/github_cpp_makefile_star2_O2/vianna274[P]dropbox/src/Server.cpp
// Function: Dropbox::Server::connectNewClient()
void Server::connectNewClient()
{

    MessageData *d = connectClientSocket.receive(TIMEOUT_OFF);
    if (d->type == TYPE_MAKE_CONNECTION) {
        string username(d->username);
        string userIp(d->payload);
        User *user = getUser(username);
        if(user == nullptr){
            user = new User(username, rootDir+username+"/");
            users.push_back(user);
        }
        else{
            user->lockDevices();
            if(user->getNumDevicesConnected() == MAX_DEVICES){
                refuseOverLimitClient(user);
                user->unlockDevices();
                return;
            }
            user->unlockDevices();
        }
        int newPort = getAvailablePort();
        MessageData packet = make_packet(TYPE_MAKE_CONNECTION, 1, 1, -1, to_string(newPort).c_str());
	    WrapperSocket *socket = new WrapperSocket(newPort);
        connectClientSocket.send(&packet);
        
        user->lockDevices();
        user->addDevice(socket);
        user->unlockDevices();

        this->propagateConnection(username, userIp);
        thread listenToClientThread(&Server::listenToClient, this, socket, user);
        listenToClientThread.detach();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1100, %rsp           # imm = 0x1100
movq %rdi, %rbx
leaq 0xe8(%rdi), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb9d4
cmpl $0x2, (%rax)
jne 0x807f
movq %rax, %r15
leaq 0xfb4(%rax), %rsi
leaq -0x58(%rbp), %rdi
leaq -0x1118(%rbp), %rdx
callq 0x3130
addq $0x14, %r15
leaq -0x98(%rbp), %rdi
leaq -0x1118(%rbp), %rdx
movq %r15, %rsi
callq 0x3130
leaq -0x140(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x33d0
leaq -0x140(%rbp), %rsi
movq %rbx, %rdi
callq 0x8c56
movq %rax, %r15
leaq -0x140(%rbp), %rdi
callq 0x3170
movq %r15, -0x28(%rbp)
testq %r15, %r15
je 0x7ea6
addq $0x70, %r15
movq %r15, %rdi
callq 0x50d8
movq -0x28(%rbp), %rdi
callq 0xb37e
movq -0x28(%rbp), %rsi
cmpl $0x2, %eax
jne 0x7f43
movq %rbx, %rdi
callq 0x8cd8
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
callq 0x3250
jmp 0x806a
movl $0x98, %edi
callq 0x3320
movq %rax, %r15
leaq -0x120(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x33d0
leaq -0x1118(%rbp), %rdi
leaq -0x58(%rbp), %rdx
movq %rbx, %rsi
callq 0x5352
leaq 0x44de(%rip), %rdx      # 0xc3bb
leaq -0x100(%rbp), %rdi
leaq -0x1118(%rbp), %rsi
callq 0x4f8a
leaq -0x120(%rbp), %rsi
leaq -0x100(%rbp), %rdx
movq %r15, %rdi
callq 0xb084
leaq -0x28(%rbp), %r12
movq %r15, (%r12)
leaq -0x100(%rbp), %rdi
callq 0x3170
leaq -0x1118(%rbp), %rdi
callq 0x3170
leaq -0x120(%rbp), %rdi
callq 0x3170
leaq 0x958(%rbx), %rdi
movq %r12, %rsi
callq 0xa374
jmp 0x7f4f
addq $0x70, %rsi
movq %rsi, %rdi
callq 0x3250
movq %rbx, %rdi
callq 0x8a46
movl %eax, %r15d
leaq -0x78(%rbp), %rdi
movl %eax, %esi
callq 0x5249
movq -0x78(%rbp), %r9
leaq -0x1118(%rbp), %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rcx
pushq $-0x1
popq %r8
movl %ecx, %edx
callq 0x57f0
leaq -0x78(%rbp), %rdi
callq 0x3170
pushq $0x48
popq %rdi
callq 0x3320
movq %rax, %r12
movq %rax, %rdi
movl %r15d, %esi
callq 0xb4da
movq %r12, -0x38(%rbp)
leaq -0x1118(%rbp), %rsi
movq %r14, %rdi
callq 0xb850
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
callq 0x50d8
movq -0x28(%rbp), %rdi
movq %r12, %rsi
callq 0xb390
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
callq 0x3250
leaq -0xe0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x33d0
leaq -0xc0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x33d0
leaq -0xe0(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movq %rbx, %rdi
callq 0x8e00
leaq -0xc0(%rbp), %rdi
callq 0x3170
leaq -0xe0(%rbp), %rdi
callq 0x3170
leaq 0xe59(%rip), %rax       # 0x8e8a
leaq -0x78(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0xa0(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0xa3a6
leaq -0x30(%rbp), %rdi
callq 0x3530
leaq -0x30(%rbp), %rdi
callq 0x50c8
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x58(%rbp), %rdi
callq 0x3170
addq $0x1100, %rsp           # imm = 0x1100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x3170
jmp 0x80a3
movq %rax, %rbx
leaq -0x1118(%rbp), %rdi
callq 0x3170
jmp 0x80b4
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x3170
jmp 0x80c5
movq %rax, %rbx
movq %r15, %rdi
jmp 0x80fd
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x50c8
jmp 0x812c
jmp 0x8129
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x3170
jmp 0x80ee
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x811b
movq %rax, %rbx
movq %r12, %rdi
callq 0x32f0
jmp 0x812c
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
jmp 0x811b
jmp 0x8129
jmp 0x8129
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x3170
jmp 0x812c
movq %rax, %rbx
jmp 0x8138
jmp 0x8129
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x58(%rbp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x3540
nop