// File: /workspace/github_cpp_makefile_star2_O1/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 0xed22
cmpl $0x2, (%rax)
jne 0x9ede
movq %rax, %r15
movq %r14, -0xa8(%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 0x62de
leaq 0x14(%r15), %r12
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, %rdi
callq 0x3170
leaq (%r15,%rax), %rdx
addq $0x14, %rdx
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
callq 0x62de
leaq -0x138(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %rdi
callq 0x6244
leaq -0x148(%rbp), %rsi
movq %rbx, %rdi
callq 0xaed8
movq %rax, %r15
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x9b30
callq 0x3320
movq %r15, -0x30(%rbp)
testq %r15, %r15
je 0x9b7d
addq $0x70, %r15
movq %r15, %rdi
callq 0x3470
testl %eax, %eax
jne 0x9ef7
movq -0x30(%rbp), %rdi
callq 0xe5b0
movq -0x30(%rbp), %rsi
cmpl $0x2, %eax
jne 0x9c00
movq %rbx, %rdi
callq 0xaf9c
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
callq 0x3280
jmp 0x9ebe
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 0x6244
leaq -0x1128(%rbp), %rdi
leaq -0x58(%rbp), %rdx
movq %rbx, %rsi
callq 0x6174
leaq 0x682c(%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 0x9c11
movq %rdx, -0xc8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xb8(%rbp)
jmp 0x9c18
addq $0x70, %rsi
movq %rsi, %rdi
callq 0x3280
jmp 0x9cb1
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 0xe108
movq %r15, -0x30(%rbp)
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9c5a
callq 0x3320
leaq -0x1118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c6f
callq 0x3320
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x9c80
callq 0x3320
movq 0x960(%rbx), %rsi
cmpq 0x968(%rbx), %rsi
je 0x9ca1
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x960(%rbx)
jmp 0x9cb1
leaq 0x958(%rbx), %rdi
leaq -0x30(%rbp), %rdx
callq 0xdf86
movq %rbx, %rdi
callq 0xabe8
movl %eax, %r15d
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x9d1c
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x9d13
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x9d19
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x9d1c
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x9ce0
addl $-0x3, %r13d
jmp 0x9d1c
addl $-0x2, %r13d
jmp 0x9d1c
decl %r13d
movl %r15d, %r14d
shrl $0x1f, %r14d
leal (%r14,%r13), %esi
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0xa0(%rbp), %rdi
movl $0x2d, %edx
callq 0x33b0
movl %r14d, %edi
addq -0xa0(%rbp), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x61d2
movq -0xa0(%rbp), %r9
leaq -0x1128(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x657c
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
leaq -0x48(%rbp), %r13
je 0x9d9c
callq 0x3320
movl $0x48, %edi
callq 0x3340
movq %rax, %r12
movq %rax, %rdi
movl %r15d, %esi
callq 0xe6f4
movq %r12, -0x60(%rbp)
leaq -0x1128(%rbp), %rsi
movq -0xa8(%rbp), %rdi
callq 0xeae4
movq -0x30(%rbp), %rdi
addq $0x70, %rdi
callq 0x3470
testl %eax, %eax
jne 0x9ef0
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0xe5c2
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 0x6244
leaq -0xd8(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x6244
leaq -0x108(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
movq %rbx, %rdi
callq 0xb242
movq -0xe8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9e65
callq 0x3320
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x9e76
callq 0x3320
leaq 0x1469(%rip), %rax      # 0xb2e6
leaq -0xa0(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x150(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0xd3b2
leaq -0x38(%rbp), %rdi
callq 0x3570
cmpq $0x0, -0x38(%rbp)
jne 0x9f53
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9ed0
callq 0x3320
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x9ede
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 0x9f17
callq 0x3320
jmp 0x9f17
movq %rax, %rbx
leaq -0x1118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9f31
callq 0x3320
jmp 0x9f31
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x9f47
callq 0x3320
jmp 0x9f47
movq %rax, %rbx
movq %r15, %rdi
jmp 0x9faf
cmpq $0x0, -0x38(%rbp)
je 0x9fbd
callq 0x30e0
jmp 0x9fbd
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9f73
callq 0x3320
jmp 0x9f73
movq %rax, %rbx
movq -0x108(%rbp), %rdi
jmp 0x9faa
movq %rax, %rbx
movq %r12, %rdi
jmp 0x9faf
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
jne 0x9faf
jmp 0x9fc0
jmp 0x9fbd
jmp 0x9fbd
movq %rax, %rbx
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x9fc0
callq 0x3320
jmp 0x9fc0
movq %rax, %rbx
jmp 0x9fd2
jmp 0x9fbd
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9fd2
callq 0x3320
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9fe4
callq 0x3320
movq %rbx, %rdi
callq 0x3580