// File: /workspace/github_cpp_makefile_star2_O3/sidscrazy[P]Paxos/./paxos_controller.cpp
// Function: PaxosController::network_simulator(int)
void network_simulator (int id){
		int role = ACCEPTOR;
		if (id < proposers){
			role |= PROPOSER;
			role |= LEARNER;
		}
		message *m;
		while (true){
			mutexes[id].lock ();
			m = receive_packet (sockets[id]);
			mutexes[id].unlock ();
			if (m != NULL){
				int receiver = m->receiver;
				
				/* Special Sequence for Ending Connection
				   and exiting program safely. */
				if (m->type == MSG_TEARDOWN) {
					mutexes[id].lock ();
					send_packet (sockets[id], m);
					mutexes[id].unlock ();
					free (m);
					return;
				}

				if (m->type == MSG_CRASH){
					log_mutex.lock ();
					log->CrashSequence (m);
					free (m);
					log_mutex.unlock ();
					continue;
				} 

				/* Broadcast Packet. */
				if (receiver == -1) {
					for (int i = 0; i < nodes; i++){
						if (i != id){
							mutexes[i].lock ();
							m->receiver = i;
							log_mutex.lock ();
							log->AddMsg (m, role);
							log_mutex.unlock ();
							send_packet (sockets[i], m);
							mutexes[i].unlock ();
						}
					}
				/* Send to single recipient. */
				} else {

				
					mutexes[receiver].lock ();
					log_mutex.lock ();
					log->AddMsg (m, role);
					send_packet (sockets[receiver], m);
					log->FlushToDisk();
					log_mutex.unlock ();
					mutexes[receiver].unlock ();
				}

				m->receiver = receiver;
				cout_mutex.lock ();
				if (dump_messages){
					dump_message (m);
				}
				cout_mutex.unlock ();
				free (m);

			}
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r15d
movq %rdi, %rbx
xorl %r14d, %r14d
cmpl %esi, 0xb4(%rdi)
setg %r12b
movslq %esi, %rax
movq %rax, -0x38(%rbp)
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
movq 0x48(%rdi), %rdi
movq %rax, -0x40(%rbp)
addq %rax, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movb %r12b, %r14b
leal (%r14,%r14,2), %eax
addl $0x4, %eax
movl %eax, -0x2c(%rbp)
leaq 0x88(%rbx), %r12
leaq 0x60(%rbx), %rax
movq %rax, -0x48(%rbp)
movl %r15d, %eax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
callq 0x24fc
movq %rax, %r13
movq 0x48(%rbx), %rdi
addq %r14, %rdi
callq 0x2150
testq %r13, %r13
je 0x3dd0
movl 0x10(%r13), %eax
cmpl $0x9, %eax
je 0x3ccc
cmpl $0x8, %eax
je 0x3deb
movl 0x4(%r13), %eax
cmpl $-0x1, %eax
movl %eax, -0x30(%rbp)
je 0x3d00
movslq %eax, %r14
leaq (%r14,%r14,4), %r15
shlq $0x3, %r15
movq 0x48(%rbx), %rdi
addq %r15, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0x4642
movq 0x18(%rbx), %rax
movl (%rax,%r14,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
movq 0xc0(%rbx), %rdi
callq 0x4472
movq %r12, %rdi
callq 0x2150
addq 0x48(%rbx), %r15
movq %r15, %rdi
callq 0x2150
jmp 0x3d92
movq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
callq 0x47b2
movq %r13, %rdi
callq 0x2260
movq %r12, %rdi
callq 0x2150
jmp 0x3dd0
movl 0xb0(%rbx), %eax
testl %eax, %eax
jle 0x3d92
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpq %r14, -0x50(%rbp)
je 0x3d83
movq 0x48(%rbx), %rdi
addq %r15, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movl %r14d, 0x4(%r13)
movq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0x4642
movq %r12, %rdi
callq 0x2150
movq 0x18(%rbx), %rax
movl (%rax,%r14,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
movq 0x48(%rbx), %rdi
addq %r15, %rdi
callq 0x2150
movl 0xb0(%rbx), %eax
incq %r14
movslq %eax, %rcx
addq $0x28, %r15
cmpq %rcx, %r14
jl 0x3d14
movl -0x30(%rbp), %eax
movl %eax, 0x4(%r13)
movq -0x48(%rbp), %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
cmpb $0x1, 0xb8(%rbx)
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
jne 0x3dbf
movq %r13, %rdi
callq 0x25dd
movq -0x48(%rbp), %rdi
callq 0x2150
movq %r13, %rdi
callq 0x2260
movq 0x48(%rbx), %rdi
addq %r14, %rdi
callq 0x22c0
testl %eax, %eax
je 0x3c06
movl %eax, %edi
callq 0x2120
movq 0x48(%rbx), %rdi
addq %r14, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3de4
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
addq 0x48(%rbx), %r14
movq %r14, %rdi
callq 0x2150
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2260