// File: /workspace/github_cpp_makefile_star2_O2/hunterlxt[P]swim-membership-protocol/Application.cpp
// Function: Application::mp1Run()
void Application::mp1Run() {
	int i;

	// For all the nodes in the system
	for( i = 0; i <= par->EN_GPSZ-1; i++) {

		/*
		 * Receive messages from the network and queue them in the membership protocol queue
		 */
		if( par->getcurrtime() > (int)(par->STEP_RATE*i) && !(mp1[i]->getMemberNode()->bFailed) ) {
			// Receive messages from the network and queue them
			mp1[i]->recvLoop();
		}

	}

	// For all the nodes in the system
	for( i = par->EN_GPSZ - 1; i >= 0; i-- ) {

		/*
		 * Introduce nodes into the distributed system
		 */
		if( par->getcurrtime() == (int)(par->STEP_RATE*i) ) {
			// introduce the ith node into the system at time STEPRATE*i
			mp1[i]->nodeStart(JOINADDR, par->PORTNUM);
			cout<<i<<"-th introduced node is assigned with the address: "<<mp1[i]->getMemberNode()->addr.getAddress() << endl;
			nodeCount += i;
		}

		/*
		 * Handle all the messages in your queue and send heartbeats
		 */
		else if( par->getcurrtime() > (int)(par->STEP_RATE*i) && !(mp1[i]->getMemberNode()->bFailed) ) {
			// handle messages and send heartbeats
			mp1[i]->nodeLoop();
			#ifdef DEBUGLOG
			if( (i == 0) && (par->globaltime % 500 == 0) ) {
				log->LOG(&mp1[i]->getMemberNode()->addr, "@@time=%d", par->getcurrtime());
			}
			#endif
		}

	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x40(%rbx), %rdi
movslq 0x18(%rdi), %rax
cmpq %rax, %r14
jge 0x451c
callq 0x51f8
movq 0x40(%rbx), %rcx
cvtsi2sd %r14d, %xmm0
mulsd 0x10(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x4517
movq 0x38(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq 0x20(%rdi), %rax
cmpb $0x0, 0x10(%rax)
jne 0x4517
callq 0x257c
incq %r14
jmp 0x44d8
movl %eax, %r14d
leaq 0x8(%rbx), %r15
decq %r14
leaq 0x8(%rsp), %rbp
leal 0x1(%r14), %eax
testl %eax, %eax
jle 0x4661
movq 0x40(%rbx), %rdi
callq 0x51f8
movq 0x40(%rbx), %rdi
cvtsi2sd %r14d, %xmm1
movsd 0x10(%rdi), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jne 0x45d8
movq 0x38(%rbx), %rax
movl %r14d, %r13d
shlq $0x3, %r13
movq (%rax,%r13), %rax
movswl 0x30(%rdi), %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x25b4
movq 0x6a51(%rip), %rdi      # 0xafd0
movl %r14d, %esi
callq 0x22c0
movq %rax, %rdi
leaq 0x2d02(%rip), %rsi      # 0x7293
callq 0x2160
movq %rax, %r12
movq 0x38(%rbx), %rax
movq (%rax,%r13), %rax
movq 0x20(%rax), %rsi
addq $0x8, %rsi
movq %rbp, %rdi
callq 0x4824
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2120
movq %rax, %rdi
callq 0x20b0
movq %rbp, %rdi
callq 0x2090
addl %r14d, 0x7411(%rip)     # 0xb9e4
jmp 0x4659
movsd %xmm1, (%rsp)
callq 0x51f8
movq 0x40(%rbx), %rcx
movsd (%rsp), %xmm0
mulsd 0x10(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x4659
movq 0x38(%rbx), %rax
movl %r14d, %r12d
movq (%rax,%r12,8), %rdi
movq 0x20(%rdi), %rax
cmpb $0x0, 0x10(%rax)
jne 0x4659
callq 0x2706
testl %r14d, %r14d
jne 0x4659
movq 0x40(%rbx), %rdi
movl 0x28(%rdi), %eax
cltd
movl $0x1f4, %ecx            # imm = 0x1F4
idivl %ecx
testl %edx, %edx
jne 0x4659
movq 0x30(%rbx), %r13
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x20(%rax), %r12
addq $0x8, %r12
callq 0x51f8
movq %r13, %rdi
movq %r12, %rsi
leaq 0x2c76(%rip), %rdx      # 0x72c6
movl %eax, %ecx
xorl %eax, %eax
callq 0x4cd2
decq %r14
jmp 0x452b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x22d0
nop