// File: /workspace/github_cpp_makefile_star2_O3/sidscrazy[P]Paxos/./paxos_controller.cpp
// Function: PaxosController::PaxosController(int, int)
PaxosController (int n, int p){
		nodes = n;
		proposers = p;
		children = std::vector<int> (n);
		sockets = std::vector<int> (n);
		threads = std::vector<std::thread> (n);
		mutexes = std::vector<std::mutex> (n);
		log = new PaxosNodeLogger (CONTROLLER_LOG);



		for (int i = 0; i < nodes; i++){
			
			int *s = (int *) malloc (2 * sizeof (int));
			
			if (s == NULL){
				exit (1);
			}

			if (socketpair(AF_UNIX, SOCK_DGRAM, 0, s) < 0){
				exit (1);
			}

			sockets[i] = s[0];

			int pid = fork ();
			if (pid == 0 ){
				close (s[0]);
				dup2 (s[1], 0);
				dup2 (s[1], 1);
				char *args[2];
				args[0] = (char *)malloc (7);
				if (args[0] == NULL){
					exit (1);
				}
				memcpy (args[0], "./node", 6);
				args[0][7] = '\0';
				args[1] = NULL;
				execvp (args[0], args);
			} else {
				children[i] = pid;
				close (s[1]);
			}

			int role = ACCEPTOR;
			if (i < proposers){
				role |= PROPOSER;
				role |= LEARNER;
			}
			message init_message (i, role, nodes, -1, MSG_INIT);
			mutexes[i].lock ();
			send_packet (sockets[i], &init_message);
			mutexes[i].unlock ();
			free (s);
			threads[i] = std::thread ( [this, i] { this->network_simulator(i); } );
		}

	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x30(%rdi), %rax
movq %rax, -0x58(%rbp)
movb $0x0, 0xb8(%rdi)
movl $0xb0, %edx
xorl %esi, %esi
callq 0x2110
movl %r15d, 0xb0(%rbx)
movl %r14d, 0xb4(%rbx)
movslq %r15d, %r14
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rdx
movq %r14, %rsi
callq 0x38c2
movq (%rbx), %rdi
movq -0x50(%rbp), %rax
movq %rax, (%rbx)
movq -0x48(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
testq %rdi, %rdi
je 0x34d9
callq 0x21f0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x34d9
callq 0x21f0
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rdx
movq %r14, %rsi
callq 0x38c2
movq 0x18(%rbx), %rdi
movq -0x50(%rbp), %rax
movq %rax, 0x18(%rbx)
movq -0x48(%rbp), %rax
movq %rax, 0x20(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x28(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
testq %rdi, %rdi
je 0x352c
callq 0x21f0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x352c
callq 0x21f0
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %r14, %rsi
callq 0x3958
movups 0x30(%rbx), %xmm0
movq 0x40(%rbx), %rax
leaq -0x80(%rbp), %r15
movq (%r15), %rcx
movq %rcx, 0x30(%rbx)
movq 0x8(%r15), %rcx
movq %rcx, 0x38(%rbx)
movq 0x10(%r15), %rcx
movq %rcx, 0x40(%rbx)
leaq -0x50(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0x39d0
movq %r15, %rdi
callq 0x39d0
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rdx
movq %r14, %rsi
callq 0x3a08
movq 0x48(%rbx), %rdi
movq -0x50(%rbp), %rax
movq %rax, 0x48(%rbx)
movq -0x48(%rbp), %rax
movq %rax, 0x50(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x58(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
testq %rdi, %rdi
je 0x35d9
callq 0x21f0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x35d9
callq 0x21f0
movl $0x228, %edi            # imm = 0x228
callq 0x2220
movq %rax, %r15
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x3f50
movq %r15, 0xc0(%rbx)
cmpl $0x0, 0xb0(%rbx)
jle 0x376f
xorl %r12d, %r12d
leaq -0x50(%rbp), %r15
xorl %r13d, %r13d
movl $0x8, %edi
callq 0x22a0
testq %rax, %rax
je 0x377e
movq %rax, %r14
movl $0x1, %edi
movl $0x2, %esi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21b0
testl %eax, %eax
js 0x377e
movl (%r14), %eax
movq 0x18(%rbx), %rcx
movl %eax, (%rcx,%r13,4)
callq 0x2060
testl %eax, %eax
je 0x3669
movq (%rbx), %rcx
movl %eax, (%rcx,%r13,4)
movl 0x4(%r14), %edi
callq 0x2370
jmp 0x36c4
movl (%r14), %edi
callq 0x2370
movl 0x4(%r14), %edi
xorl %esi, %esi
callq 0x21e0
movl 0x4(%r14), %edi
movl $0x1, %esi
callq 0x21e0
movl $0x7, %edi
callq 0x22a0
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x377e
movw $0x6564, 0x4(%rax)      # imm = 0x6564
movl $0x6f6e2f2e, (%rax)     # imm = 0x6F6E2F2E
movb $0x0, 0x7(%rax)
movq $0x0, -0x48(%rbp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movslq 0xb4(%rbx), %rax
xorl %ecx, %ecx
cmpq %rax, %r13
setl %cl
leal 0x4(%rcx,%rcx,2), %eax
movl 0xb0(%rbx), %ecx
movl %r13d, -0x50(%rbp)
movl %eax, -0x4c(%rbp)
movl %ecx, -0x48(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x44(%rbp)
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x378d
movq 0x18(%rbx), %rax
movl (%rax,%r13,4), %edi
movl $0x20, %edx
movq %r15, %rsi
callq 0x20b0
movq 0x48(%rbx), %rdi
addq %r12, %rdi
callq 0x2150
movq %r14, %rdi
callq 0x2260
movq %rbx, -0x80(%rbp)
movl %r13d, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3a86
movq -0x58(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax,%r13,8)
jne 0x3788
movq -0x60(%rbp), %rcx
movq %rcx, (%rax,%r13,8)
incq %r13
movslq 0xb0(%rbx), %rax
addq $0x28, %r12
cmpq %rax, %r13
jl 0x3611
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2270
callq 0x2070
movl %eax, %edi
callq 0x2120
movq %rax, %r14
movq %r15, %rdi
callq 0x21f0
jmp 0x37b4
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
jmp 0x37b1
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x37c2
callq 0x21f0
movq -0x58(%rbp), %rdi
callq 0x39d0
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x37d9
callq 0x21f0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x37e6
callq 0x21f0
movq %r14, %rdi
callq 0x2340