// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %esi, %r12d
movq %rdi, %rbx
xorl %r15d, %r15d
cmpl %esi, 0xb4(%rdi)
setg %r13b
movslq %esi, %rax
movq %rax, -0x50(%rbp)
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
movq 0x48(%rdi), %rdi
movq %rax, -0x48(%rbp)
addq %rax, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movb %r13b, %r15b
leal (%r15,%r15,2), %eax
addl $0x4, %eax
movl %eax, -0x2c(%rbp)
leaq 0x88(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x60(%rbx), %rax
movq %rax, -0x58(%rbp)
movl %r12d, %eax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
callq 0x24fc
movq %rax, %r13
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x2150
testq %r13, %r13
je 0x3e93
movl 0x10(%r13), %eax
cmpl $0x9, %eax
je 0x3cf4
cmpl $0x8, %eax
jne 0x3d31
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x2150
movq %r13, %rdi
callq 0x2260
movl $0x1, %eax
jmp 0x3e8f
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
callq 0x483a
movq %r13, %rdi
callq 0x2260
movq %r14, %rdi
callq 0x2150
movl $0x2, %eax
jmp 0x3e8f
movl 0x4(%r13), %eax
cmpl $-0x1, %eax
movl %eax, -0x3c(%rbp)
je 0x3dbc
movslq %eax, %r15
leaq (%r15,%r15,4), %r12
shlq $0x3, %r12
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0x46ca
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
movq 0xc0(%rbx), %rdi
callq 0x44fa
movq %r14, %rdi
callq 0x2150
addq 0x48(%rbx), %r12
movq %r12, %rdi
callq 0x2150
jmp 0x3e4f
cmpl $0x0, 0xb0(%rbx)
jle 0x3e4f
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpq %r15, -0x60(%rbp)
je 0x3e3c
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movl %r15d, 0x4(%r13)
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
movq 0xc0(%rbx), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0x46ca
movq %r14, %rdi
callq 0x2150
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edi
movl $0x20, %edx
movq %r13, %rsi
callq 0x20b0
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x2150
incq %r15
movslq 0xb0(%rbx), %rax
addq $0x28, %r12
cmpq %rax, %r15
jl 0x3dcf
movl -0x3c(%rbp), %eax
movl %eax, 0x4(%r13)
movq -0x58(%rbp), %rdi
callq 0x22c0
testl %eax, %eax
jne 0x3ea7
cmpb $0x1, 0xb8(%rbx)
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
jne 0x3e7c
movq %r13, %rdi
callq 0x25dd
movq -0x58(%rbp), %rdi
callq 0x2150
movq %r13, %rdi
callq 0x2260
xorl %eax, %eax
testb $0x1, %al
jne 0x3eae
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x22c0
testl %eax, %eax
je 0x3c76
movl %eax, %edi
callq 0x2120
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop