// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x48(%rbp), %rcx
movl -0xc(%rbp), %eax
movq 0x40(%rcx), %rcx
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x7da8
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x99f0
movq -0x48(%rbp), %rcx
movq 0x40(%rcx), %rcx
movsd 0x10(%rcx), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x7d9b
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8260
testb $0x1, 0x10(%rax)
jne 0x7d9b
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3800
jmp 0x7d9d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7d2b
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x18(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x7f9f
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x99f0
movq -0x48(%rbp), %rcx
movq 0x40(%rcx), %rcx
movsd 0x10(%rcx), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jne 0x7ebd
movq -0x48(%rbp), %rsi
movslq -0xc(%rbp), %rdx
movq 0x38(%rsi), %rcx
movq 0x40(%rsi), %rax
movq (%rcx,%rdx,8), %rdi
addq $0x8, %rsi
movswl 0x30(%rax), %edx
callq 0x38e0
movl -0xc(%rbp), %esi
movq 0xd1b3(%rip), %rdi      # 0x14fd0
callq 0x33a0
movq %rax, %rdi
leaq 0x747f(%rip), %rsi      # 0xf2ab
callq 0x3200
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x60(%rbp)
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8260
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x8280
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x31c0
movq %rax, -0x50(%rbp)
jmp 0x7e74
movq -0x50(%rbp), %rdi
movq 0xd141(%rip), %rsi      # 0x14fc0
callq 0x3240
jmp 0x7e86
leaq -0x30(%rbp), %rdi
callq 0x3120
movl -0xc(%rbp), %eax
addl 0xdfdc(%rip), %eax      # 0x15e74
movl %eax, 0xdfd6(%rip)      # 0x15e74
jmp 0x7f8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3120
jmp 0x7fa5
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x99f0
movq -0x48(%rbp), %rcx
movq 0x40(%rcx), %rcx
movsd 0x10(%rcx), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x7f8d
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8260
testb $0x1, 0x10(%rax)
jne 0x7f8d
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3dd0
cmpl $0x0, -0xc(%rbp)
jne 0x7f8b
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x28(%rax), %eax
movl $0x1f4, %ecx            # imm = 0x1F4
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x7f8b
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8260
movq %rax, %rcx
movq -0x48(%rbp), %rax
addq $0x8, %rcx
movq %rcx, -0x68(%rbp)
movq 0x40(%rax), %rdi
callq 0x99f0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl %eax, %ecx
leaq 0x735a(%rip), %rdx      # 0xf2de
movb $0x0, %al
callq 0x9090
jmp 0x7f8d
jmp 0x7f8f
jmp 0x7f91
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7db9
addq $0x70, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33b0
nop