// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/mmulti.c
// Function: initmultiplayerscycle
int initmultiplayerscycle(void)
{
	int i, k, dnetready = 1;

	getpacket(&i,0);

	tims = GetTickCount();

	if (networkmode == MMULTI_MODE_MS && myconnectindex == connecthead)
	{
		// The master waits for all players to check in.
		for(i=numplayers-1;i>0;i--) {
			if (i == myconnectindex) continue;
			if (otherhost[i].ss_family == AF_UNSPEC) {
				// There's a slot to be filled.
				dnetready = 0;
			} else if (lastrecvtims[i] == 0) {
				// There's a player who hasn't checked in.
				dnetready = 0;
			} else if (prevlastrecvtims[i] != lastrecvtims[i]) {
				if (!playerslive[i]) {
					printf("mmulti: Player %d is here\n", i);
					playerslive[i] = 1;
				}
				prevlastrecvtims[i] = lastrecvtims[i];
			} else if (tims - lastrecvtims[i] > PRESENCETIMEOUT) {
				if (playerslive[i]) {
					printf("mmulti: Player %d has gone\n", i);
					playerslive[i] = 0;
				}
				prevlastrecvtims[i] = lastrecvtims[i];
				dnetready = 0;
			}
		}
	}
	else
	{
		if (networkmode == MMULTI_MODE_MS) {
			// As a slave, we send the master pings. The netready flag gets
			// set by getpacket() and is sent by the master when it is OK
			// to launch.
			dnetready = 0;
			i = connecthead;

		} else {
			// In peer-to-peer mode we send pings to our peer group members
			// and wait for them all to check in. The netready flag is set
			// when everyone responds together within the timeout.
			i = numplayers - 1;
		}
		while (1) {
			if (i != myconnectindex) {
				if (tims < lastsendtims[i]) lastsendtims[i] = tims;
				if (tims >= lastsendtims[i]+250) //1000/PAKRATE)
				{
#ifdef MMULTI_DEBUG_SENDRECV
					debugprintf("mmulti debug: sending player %d a ping\n", i);
#endif

					lastsendtims[i] = tims;

						//   short crc16ofs;       //offset of crc16
						//   int icnt0;           //-1 (special packet for MMULTI.C's player collection)
						//   ...
						//   unsigned short crc16; //CRC16 of everything except crc16
					k = 2;
					*(int *)&pakbuf[k] = -1; k += 4;
					pakbuf[k++] = 0xaa;
					*(unsigned short *)&pakbuf[0] = (unsigned short)k;
					*(unsigned short *)&pakbuf[k] = getcrc16(pakbuf,k); k += 2;
					netsend(i,pakbuf,k);
				}

				if (lastrecvtims[i] == 0) {
					// There's a player who hasn't checked in.
					dnetready = 0;
				} else if (prevlastrecvtims[i] != lastrecvtims[i]) {
					if (!playerslive[i]) {
						printf("mmulti: Player %d is here\n", i);
						playerslive[i] = 1;
					}
					prevlastrecvtims[i] = lastrecvtims[i];
				} else if (prevlastrecvtims[i] - tims > PRESENCETIMEOUT) {
					if (playerslive[i]) {
						printf("mmulti: Player %d has gone\n", i);
						playerslive[i] = 0;
					}
					prevlastrecvtims[i] = lastrecvtims[i];
					dnetready = 0;
				}
			}

			if (networkmode == MMULTI_MODE_MS) {
				break;
			} else {
				if (--i < 0) break;
			}
		}
	}

	netready = netready || dnetready;

	return !netready;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x4(%rsp), %rdi
xorl %esi, %esi
callq 0x5486a
callq 0x54db7
movl %eax, 0x7475cb(%rip)    # 0x79bb84
movl 0x852a9(%rip), %ecx     # 0xd9868
movl 0x74756b(%rip), %eax    # 0x79bb30
movl 0x747561(%rip), %edi    # 0x79bb2c
testl %ecx, %ecx
jne 0x5470f
cmpl %eax, 0x74754b(%rip)    # 0x79bb24
jne 0x5470f
pushq $0x1
popq %r14
leaq 0x746b66(%rip), %r10    # 0x79b150
leaq 0x74759f(%rip), %r11    # 0x79bb90
leaq 0x7475d8(%rip), %r12    # 0x79bbd0
movl 0x747586(%rip), %eax    # 0x79bb84
xorl %ecx, %ecx
subl 0x74751e(%rip), %ecx    # 0x79bb24
leal -0x1(%rdi), %r13d
addq %r13, %rcx
movq %r13, %rdx
shlq $0x7, %rdx
addq %r10, %rdx
leaq (,%r13,4), %rsi
movl %edi, %ebx
xorl %ebp, %ebp
leal (%rbx,%rbp), %edi
cmpl $0x2, %edi
jl 0x54844
leaq (%rcx,%rbp), %rdi
testl %edi, %edi
je 0x54669
xorl %r8d, %r8d
cmpw $0x0, (%rdx)
je 0x54702
leaq (%rsi,%rbp,4), %r9
movl (%r11,%r9), %edi
testl %edi, %edi
je 0x54702
cmpl %edi, (%r12,%r9)
jne 0x54672
movl %eax, %r8d
subl %edi, %r8d
cmpl $0x7d0, %r8d            # imm = 0x7D0
jg 0x546a6
decq %rbp
addq $-0x80, %rdx
jmp 0x54623
leal -0x1(%rbx), %r15d
addq %rbp, %r15
leaq 0x747590(%rip), %rax    # 0x79bc10
cmpb $0x0, (%rax,%r15)
jne 0x546f8
leaq 0x4446e(%rip), %rdi     # 0x98afc
movl %r15d, %esi
xorl %eax, %eax
callq 0x33127
leaq 0x747571(%rip), %rax    # 0x79bc10
movb $0x1, (%rax,%r15)
jmp 0x546db
leal -0x1(%rbx), %r15d
addq %rbp, %r15
leaq 0x74755c(%rip), %rax    # 0x79bc10
cmpb $0x0, (%rax,%r15)
je 0x546f5
xorl %r14d, %r14d
leaq 0x44452(%rip), %rdi     # 0x98b17
movl %r15d, %esi
xorl %eax, %eax
callq 0x33127
leaq 0x74753a(%rip), %rax    # 0x79bc10
movb $0x0, (%rax,%r15)
leal -0x1(%rbx), %eax
leaq 0x7474ab(%rip), %r11    # 0x79bb90
leaq (%r11,%rax,4), %rax
movl (%rax,%rbp,4), %edi
leaq 0x746a5d(%rip), %r10    # 0x79b150
jmp 0x546f8
xorl %r14d, %r14d
leaq (%r12,%r13,4), %rax
movl %edi, (%rax,%rbp,4)
movl %r14d, %r8d
leal (%rbx,%rbp), %edi
decl %edi
movl %r8d, %r14d
jmp 0x545f8
decl %edi
xorl %r14d, %r14d
testl %ecx, %ecx
cmovnel %edi, %eax
setne %r14b
movslq %eax, %rbx
leaq (,%rbx,4), %r15
leaq 0x7474f1(%rip), %r12    # 0x79bc20
leaq 0x74745a(%rip), %rbp    # 0x79bb90
leaq 0x747493(%rip), %r13    # 0x79bbd0
leaq 0x7474cc(%rip), %rdx    # 0x79bc10
cmpl 0x7473da(%rip), %ebx    # 0x79bb24
je 0x54827
movl 0x74742e(%rip), %eax    # 0x79bb84
movl (%r15,%r12), %ecx
cmpl %ecx, %eax
jge 0x54764
movl %eax, (%r15,%r12)
movl %eax, %ecx
addl $0xfa, %ecx
cmpl %ecx, %eax
jl 0x547b0
orl $-0x1, 0x7474ed(%rip)   # 0x79bc62
movl %eax, (%r15,%r12)
movb $-0x56, 0x7474e6(%rip)  # 0x79bc66
movw $0x7, 0x7474d7(%rip)    # 0x79bc60
pushq $0x7
popq %rdi
callq 0x54def
movw %ax, 0x7474cf(%rip)     # 0x79bc67
movl %ebx, %edi
leaq 0x7474bf(%rip), %rsi    # 0x79bc60
pushq $0x9
popq %rdx
callq 0x53ab2
leaq 0x747460(%rip), %rdx    # 0x79bc10
movl (%r15,%rbp), %eax
testl %eax, %eax
je 0x547f4
cmpl %eax, (%r15,%r13)
jne 0x547f9
movl %eax, %ecx
subl 0x7473be(%rip), %ecx    # 0x79bb84
cmpl $0x7d1, %ecx            # imm = 0x7D1
jl 0x54827
cmpb $0x0, (%rbx,%rdx)
je 0x54820
xorl %r14d, %r14d
leaq 0x44339(%rip), %rdi     # 0x98b17
movl %ebx, %esi
xorl %eax, %eax
callq 0x33127
leaq 0x747422(%rip), %rdx    # 0x79bc10
movb $0x0, (%rbx,%rdx)
jmp 0x5481a
xorl %r14d, %r14d
jmp 0x54827
cmpb $0x0, (%rbx,%rdx)
jne 0x54823
leaq 0x442f6(%rip), %rdi     # 0x98afc
movl %ebx, %esi
xorl %eax, %eax
callq 0x33127
leaq 0x7473fa(%rip), %rdx    # 0x79bc10
movb $0x1, (%rbx,%rdx)
movl (%r15,%rbp), %eax
jmp 0x54823
xorl %r14d, %r14d
movl %eax, (%r15,%r13)
cmpl $0x0, 0x8503a(%rip)     # 0xd9868
je 0x54844
leaq -0x1(%rbx), %rax
addq $-0x4, %r15
testq %rbx, %rbx
movq %rax, %rbx
jg 0x54744
xorl %eax, %eax
xorl %ecx, %ecx
orl 0x747331(%rip), %r14d   # 0x79bb80
sete %al
setne %cl
movl %ecx, 0x747325(%rip)    # 0x79bb80
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq