// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x1108, %rsp           # imm = 0x1108
movq %rdi, %rbx
leaq 0xe8(%rdi), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xec2e
cmpl $0x2, (%rax)
jne 0x9ead
movq %rax, %r15
movq %r14, -0xa0(%rbp)
leaq 0xfb4(%rax), %r12
leaq -0x48(%rbp), %r13
movq %r13, -0x10(%r13)
movq %r12, %rdi
callq 0x3170
leaq (%r15,%rax), %rdx
addq $0xfb4, %rdx            # imm = 0xFB4
leaq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x630e
leaq 0x14(%r15), %r12
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, %rdi
callq 0x3170
leaq (%r15,%rax), %rdx
addq $0x14, %rdx
leaq -0x78(%rbp), %rdi
movq %r12, %rsi
callq 0x630e
leaq -0x138(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %rdi
callq 0x6270
leaq -0x148(%rbp), %rsi
movq %rbx, %rdi
callq 0xae5a
movq %rax, %r15
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x9afa
callq 0x3320
movq %r15, -0x30(%rbp)
testq %r15, %r15
je 0x9b47
addq $0x70, %r15
movq %r15, %rdi
callq 0x3470
testl %eax, %eax
jne 0x9ec6
movq -0x30(%rbp), %rdi
callq 0xe564
movq -0x30(%rbp), %rsi
cmpl $0x2, %eax
jne 0x9bca
movq %rbx, %rdi
callq 0xaf28
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
callq 0x3280
jmp 0x9e8d
movl $0x98, %edi
callq 0x3340
movq %rax, %r15
leaq -0x118(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x6270
leaq -0x1128(%rbp), %rdi
leaq -0x58(%rbp), %rdx
movq %rbx, %rsi
callq 0x61a0
leaq 0x6862(%rip), %rsi      # 0x103f3
leaq -0x1128(%rbp), %rdi
callq 0x35c0
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9bdb
movq %rdx, -0xc8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xb8(%rbp)
jmp 0x9be2
addq $0x70, %rsi
movq %rsi, %rdi
callq 0x3280
jmp 0x9c7b
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rsi
leaq -0xc8(%rbp), %rdx
movq %rsi, 0x8(%rdx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x128(%rbp), %rsi
movq %r15, %rdi
callq 0xe0a4
movq %r15, -0x30(%rbp)
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9c24
callq 0x3320
leaq -0x1118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c39
callq 0x3320
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x9c4a
callq 0x3320
movq 0x960(%rbx), %rsi
cmpq 0x968(%rbx), %rsi
je 0x9c6b
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x960(%rbx)
jmp 0x9c7b
leaq 0x958(%rbx), %rdi
leaq -0x30(%rbp), %rdx
callq 0xdf22
movq %rbx, %rdi
callq 0xab96
movl %eax, %r15d
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x9ce6
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x9cdd
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x9ce3
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x9ce6
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x9caa
addl $-0x3, %r13d
jmp 0x9ce6
addl $-0x2, %r13d
jmp 0x9ce6
decl %r13d
movl %r15d, %r14d
shrl $0x1f, %r14d
leal (%r14,%r13), %esi
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x98(%rbp), %rdi
movl $0x2d, %edx
callq 0x33b0
movl %r14d, %edi
addq -0x98(%rbp), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x61fe
movq -0x98(%rbp), %r9
leaq -0x1128(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x65b0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
leaq -0x48(%rbp), %r13
je 0x9d66
callq 0x3320
movl $0x48, %edi
callq 0x3340
movq %rax, %r12
movq %rax, %rdi
movl %r15d, %esi
callq 0xe6b0
movq %r12, -0xa8(%rbp)
leaq -0x1128(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0xea3c
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
callq 0x3470
testl %eax, %eax
jne 0x9ebf
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0xe576
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
callq 0x3280
leaq -0xf8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x6270
leaq -0xd8(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x6270
leaq -0x108(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
movq %rbx, %rdi
callq 0xb1ce
movq -0xe8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9e31
callq 0x3320
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x9e42
callq 0x3320
leaq 0x1429(%rip), %rax      # 0xb272
leaq -0x98(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x150(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x38(%rbp), %rdi
leaq -0xa8(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0xd364
leaq -0x38(%rbp), %rdi
callq 0x3570
cmpq $0x0, -0x38(%rbp)
jne 0x9f22
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x9e9f
callq 0x3320
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x9ead
callq 0x3320
addq $0x1108, %rsp           # imm = 0x1108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x3250
movl %eax, %edi
callq 0x3250
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9ee6
callq 0x3320
jmp 0x9ee6
movq %rax, %rbx
leaq -0x1118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9f00
callq 0x3320
jmp 0x9f00
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x9f16
callq 0x3320
jmp 0x9f16
movq %rax, %rbx
movq %r15, %rdi
jmp 0x9f7e
cmpq $0x0, -0x38(%rbp)
je 0x9f8c
callq 0x30e0
jmp 0x9f8c
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9f42
callq 0x3320
jmp 0x9f42
movq %rax, %rbx
movq -0x108(%rbp), %rdi
jmp 0x9f79
movq %rax, %rbx
movq %r12, %rdi
jmp 0x9f7e
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
jne 0x9f7e
jmp 0x9f8f
jmp 0x9f8c
jmp 0x9f8c
movq %rax, %rbx
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x9f8f
callq 0x3320
jmp 0x9f8f
movq %rax, %rbx
jmp 0x9fa1
jmp 0x9f8c
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x9fa1
callq 0x3320
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9fb3
callq 0x3320
movq %rbx, %rdi
callq 0x3580
nop