// File: 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
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 0x93a8
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xae20
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 0x939b
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x9860
testb $0x1, 0x10(%rax)
jne 0x939b
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x37b0
jmp 0x939d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x932b
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x18(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x959f
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xae20
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 0x94bd
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 0x3890
movl -0xc(%rbp), %esi
movq 0xcbb3(%rip), %rdi      # 0x15fd0
callq 0x3390
movq %rax, %rdi
leaq 0x5e97(%rip), %rsi      # 0xf2c3
callq 0x31f0
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 0x9860
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x9880
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x31b0
movq %rax, -0x50(%rbp)
jmp 0x9474
movq -0x50(%rbp), %rdi
movq 0xcb41(%rip), %rsi      # 0x15fc0
callq 0x3230
jmp 0x9486
leaq -0x30(%rbp), %rdi
callq 0x3110
movl -0xc(%rbp), %eax
addl 0xd5cc(%rip), %eax      # 0x16a64
movl %eax, 0xd5c6(%rip)      # 0x16a64
jmp 0x958f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3110
jmp 0x95a5
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xae20
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 0x958d
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x9860
testb $0x1, 0x10(%rax)
jne 0x958d
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3b90
cmpl $0x0, -0xc(%rbp)
jne 0x958b
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x28(%rax), %eax
movl $0x1f4, %ecx            # imm = 0x1F4
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x958b
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 0x9860
movq %rax, %rcx
movq -0x48(%rbp), %rax
addq $0x8, %rcx
movq %rcx, -0x68(%rbp)
movq 0x40(%rax), %rdi
callq 0xae20
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl %eax, %ecx
leaq 0x5d72(%rip), %rdx      # 0xf2f6
movb $0x0, %al
callq 0xa4c0
jmp 0x958d
jmp 0x958f
jmp 0x9591
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x93b9
addq $0x70, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33a0
nop