// File: /workspace/github_cpp_makefile_star2_O2/vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::listenMaster()
void Client::listenMaster() {
	while(1) {
		MessageData * data = this->listenToMaster->receive(TIMEOUT_OFF);
		if (data->type == TYPE_NEW_BOSS) {
			
			while(1) {
				WrapperSocket socketToGetPort(string(data->payload), 4000);
				MessageData request = make_packet(TYPE_MAKE_CONNECTION, 1, 1, this->localIp.length(), this->localIp.c_str(), this->username.c_str());
				socketToGetPort.send(&request);
				MessageData *newPort = socketToGetPort.receive(TIMEOUT_ON, 1500);
				if(newPort != NULL && newPort->type == TYPE_MAKE_CONNECTION){
				
					socketMtx.lock();
					this->socket = new WrapperSocket(string(data->payload), stoi(newPort->payload));
					this->payload1 = string(data->payload);
					this->payload2 = stoi(newPort->payload);
					socketMtx.unlock();
					break;
				} 
				else if(newPort != NULL && newPort->type == TYPE_REJECT_TO_LISTEN) {
					cout << newPort->payload << endl;
					std::exit(1);
				}
			}
			
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10a8, %rsp           # imm = 0x10A8
movq %rdi, %rbx
leaq 0x98(%rdi), %rax
movq %rax, -0x40(%rbp)
leaq 0xd8(%rdi), %rax
movq %rax, -0x48(%rbp)
leaq -0xf0(%rbp), %r15
pushq $0x1
popq %r14
movq 0x48(%rbx), %rdi
xorl %esi, %esi
callq 0xb9d4
cmpl $0x13, (%rax)
jne 0x3ec8
movq %rax, %r12
addq $0x14, %r12
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq -0x10c4(%rbp), %rdx
callq 0x3130
movq %r15, %rdi
movq %r13, %rsi
movl $0xfa0, %edx            # imm = 0xFA0
callq 0xb422
movq %r13, %rdi
callq 0x3170
movl 0x28(%rbx), %r8d
movq (%rbx), %rax
movq 0x20(%rbx), %r9
movq %rax, (%rsp)
leaq -0x10c4(%rbp), %r13
movq %r13, %rdi
pushq $0x2
popq %rsi
movl %r14d, %edx
movl %r14d, %ecx
callq 0x5844
movq %r15, %rdi
movq %r13, %rsi
callq 0xb850
movq %r15, %rdi
movl %r14d, %esi
movl $0x5dc, %edx            # imm = 0x5DC
callq 0xb734
movq %rax, %r13
testq %rax, %rax
je 0x3f6c
movl (%r13), %eax
cmpl $0x2, %eax
je 0x3f79
cmpl $0x5, %eax
je 0x405a
movq %r15, %rdi
callq 0xb4c4
jmp 0x3edf
movq -0x40(%rbp), %rdi
callq 0x50d8
pushq $0x48
popq %rdi
callq 0x3320
movq %rax, -0x38(%rbp)
leaq -0x88(%rbp), %rdi
movq %r12, %rsi
leaq -0x29(%rbp), %rdx
callq 0x3130
addq $0x14, %r13
leaq -0x68(%rbp), %rdi
movq %r13, %rsi
leaq -0x2a(%rbp), %rdx
callq 0x3130
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5029
movq -0x38(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl %eax, %edx
callq 0xb422
movq -0x38(%rbp), %rax
movq %rax, 0x40(%rbx)
leaq -0x68(%rbp), %rdi
callq 0x3170
leaq -0x88(%rbp), %rdi
callq 0x3170
leaq -0x68(%rbp), %rdi
movq %r12, %rsi
leaq -0x29(%rbp), %rdx
callq 0x3130
movq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %r12
movq %r12, %rsi
callq 0x3380
movq %r12, %rdi
callq 0x3170
movq %r12, %rdi
movq %r13, %rsi
leaq -0x29(%rbp), %rdx
callq 0x3130
movq %r12, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5029
movl %eax, 0xf8(%rbx)
movq %r12, %rdi
callq 0x3170
movq -0x40(%rbp), %rdi
callq 0x3250
movq %r15, %rdi
callq 0xb4c4
jmp 0x3ec8
addq $0x14, %r13
movq 0xcf63(%rip), %rdi      # 0x10fc8
movq %r13, %rsi
callq 0x3310
movq %rax, %rdi
callq 0x31c0
pushq $0x1
popq %rdi
callq 0x3370
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3170
jmp 0x40db
jmp 0x40d8
jmp 0x40d8
movq %rax, %rbx
jmp 0x40a5
movq %rax, %rbx
jmp 0x40b1
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3170
leaq -0x88(%rbp), %rdi
callq 0x3170
movq -0x38(%rbp), %rdi
callq 0x32f0
jmp 0x40db
jmp 0x40d8
jmp 0x40d8
jmp 0x40d8
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x3170
jmp 0x40e7
movq %rax, %rbx
jmp 0x40e7
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0xb4c4
movq %rbx, %rdi
callq 0x3540
nop