// File: /workspace/github_cpp_makefile_star2_O2/csMOOC[P]UIUC/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 0x3d48
callq 0x4a24
movq 0x40(%rbx), %rcx
cvtsi2sd %r14d, %xmm0
mulsd 0x10(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x3d43
movq 0x38(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq 0x20(%rdi), %rax
cmpb $0x0, 0x10(%rax)
jne 0x3d43
callq 0x258c
incq %r14
jmp 0x3d04
movl %eax, %r14d
leaq 0x8(%rbx), %r15
decq %r14
leaq 0x8(%rsp), %rbp
leal 0x1(%r14), %eax
testl %eax, %eax
jle 0x3e8d
movq 0x40(%rbx), %rdi
callq 0x4a24
movq 0x40(%rbx), %rdi
cvtsi2sd %r14d, %xmm1
movsd 0x10(%rdi), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jne 0x3e04
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 0x25c4
movq 0x7225(%rip), %rdi      # 0xafd0
movl %r14d, %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x349e(%rip), %rsi      # 0x725b
callq 0x2170
movq %rax, %r12
movq 0x38(%rbx), %rax
movq (%rax,%r13), %rax
movq 0x20(%rax), %rsi
addq $0x8, %rsi
movq %rbp, %rdi
callq 0x4050
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20c0
movq %rbp, %rdi
callq 0x20a0
addl %r14d, 0x7ff5(%rip)     # 0xbdf4
jmp 0x3e85
movsd %xmm1, (%rsp)
callq 0x4a24
movq 0x40(%rbx), %rcx
movsd (%rsp), %xmm0
mulsd 0x10(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x3e85
movq 0x38(%rbx), %rax
movl %r14d, %r12d
movq (%rax,%r12,8), %rdi
movq 0x20(%rdi), %rax
cmpb $0x0, 0x10(%rax)
jne 0x3e85
callq 0x2824
testl %r14d, %r14d
jne 0x3e85
movq 0x40(%rbx), %rdi
movl 0x28(%rdi), %eax
cltd
movl $0x1f4, %ecx            # imm = 0x1F4
idivl %ecx
testl %edx, %edx
jne 0x3e85
movq 0x30(%rbx), %r13
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x20(%rax), %r12
addq $0x8, %r12
callq 0x4a24
movq %r13, %rdi
movq %r12, %rsi
leaq 0x3412(%rip), %rdx      # 0x728e
movl %eax, %ecx
xorl %eax, %eax
callq 0x44fe
decq %r14
jmp 0x3d57
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x22e0
nop