// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x1, -0xc(%rbp)
leaq -0x4(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x88500
callq 0x88de0
movl %eax, 0x71ce9d(%rip)    # 0x7a4fa4
cmpl $0x0, 0xa3ff2(%rip)     # 0x12c100
jne 0x88286
movl 0x71ce2a(%rip), %eax    # 0x7a4f44
cmpl 0x71ce30(%rip), %eax    # 0x7a4f50
jne 0x88286
movl 0x71ce20(%rip), %eax    # 0x7a4f4c
subl $0x1, %eax
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jle 0x88281
movl -0x4(%rbp), %eax
cmpl 0x71cdff(%rip), %eax    # 0x7a4f44
jne 0x8814c
jmp 0x88273
movslq -0x4(%rbp), %rcx
leaq 0x71c419(%rip), %rax    # 0x7a4570
shlq $0x7, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x88172
movl $0x0, -0xc(%rbp)
jmp 0x88271
movslq -0x4(%rbp), %rcx
leaq 0x71ce33(%rip), %rax    # 0x7a4fb0
cmpl $0x0, (%rax,%rcx,4)
jne 0x8818f
movl $0x0, -0xc(%rbp)
jmp 0x8826f
movslq -0x4(%rbp), %rcx
leaq 0x71ce56(%rip), %rax    # 0x7a4ff0
movl (%rax,%rcx,4), %eax
movslq -0x4(%rbp), %rdx
leaq 0x71ce08(%rip), %rcx    # 0x7a4fb0
cmpl (%rcx,%rdx,4), %eax
je 0x881fc
movslq -0x4(%rbp), %rcx
leaq 0x71ce78(%rip), %rax    # 0x7a5030
cmpb $0x0, (%rax,%rcx)
jne 0x881de
movl -0x4(%rbp), %esi
leaq 0x68b74(%rip), %rdi     # 0xf0d3c
movb $0x0, %al
callq 0x52630
movslq -0x4(%rbp), %rcx
leaq 0x71ce56(%rip), %rax    # 0x7a5030
movb $0x1, (%rax,%rcx)
movslq -0x4(%rbp), %rcx
leaq 0x71cdc7(%rip), %rax    # 0x7a4fb0
movl (%rax,%rcx,4), %edx
movslq -0x4(%rbp), %rcx
leaq 0x71cdf9(%rip), %rax    # 0x7a4ff0
movl %edx, (%rax,%rcx,4)
jmp 0x8826d
movl 0x71cda2(%rip), %eax    # 0x7a4fa4
movslq -0x4(%rbp), %rdx
leaq 0x71cda3(%rip), %rcx    # 0x7a4fb0
subl (%rcx,%rdx,4), %eax
cmpl $0x7d0, %eax            # imm = 0x7D0
jle 0x8826b
movslq -0x4(%rbp), %rcx
leaq 0x71ce0e(%rip), %rax    # 0x7a5030
cmpb $0x0, (%rax,%rcx)
je 0x88248
movl -0x4(%rbp), %esi
leaq 0x68b25(%rip), %rdi     # 0xf0d57
movb $0x0, %al
callq 0x52630
movslq -0x4(%rbp), %rcx
leaq 0x71cdec(%rip), %rax    # 0x7a5030
movb $0x0, (%rax,%rcx)
movslq -0x4(%rbp), %rcx
leaq 0x71cd5d(%rip), %rax    # 0x7a4fb0
movl (%rax,%rcx,4), %edx
movslq -0x4(%rbp), %rcx
leaq 0x71cd8f(%rip), %rax    # 0x7a4ff0
movl %edx, (%rax,%rcx,4)
movl $0x0, -0xc(%rbp)
jmp 0x8826d
jmp 0x8826f
jmp 0x88271
jmp 0x88273
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x88132
jmp 0x884c2
cmpl $0x0, 0xa3e73(%rip)     # 0x12c100
jne 0x882a1
movl $0x0, -0xc(%rbp)
movl 0x71ccb4(%rip), %eax    # 0x7a4f50
movl %eax, -0x4(%rbp)
jmp 0x882ad
movl 0x71cca5(%rip), %eax    # 0x7a4f4c
subl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x882af
movl -0x4(%rbp), %eax
cmpl 0x71cc8c(%rip), %eax    # 0x7a4f44
je 0x8849e
movl 0x71cce0(%rip), %eax    # 0x7a4fa4
movslq -0x4(%rbp), %rdx
leaq 0x71cd71(%rip), %rcx    # 0x7a5040
cmpl (%rcx,%rdx,4), %eax
jge 0x882e8
movl 0x71ccca(%rip), %edx    # 0x7a4fa4
movslq -0x4(%rbp), %rcx
leaq 0x71cd5b(%rip), %rax    # 0x7a5040
movl %edx, (%rax,%rcx,4)
movl 0x71ccb6(%rip), %eax    # 0x7a4fa4
movslq -0x4(%rbp), %rdx
leaq 0x71cd47(%rip), %rcx    # 0x7a5040
movl (%rcx,%rdx,4), %ecx
addl $0xfa, %ecx
cmpl %ecx, %eax
jl 0x8839f
movl 0x71cc94(%rip), %edx    # 0x7a4fa4
movslq -0x4(%rbp), %rcx
leaq 0x71cd25(%rip), %rax    # 0x7a5040
movl %edx, (%rax,%rcx,4)
movl $0x2, -0x8(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71cd50(%rip), %rax    # 0x7a5080
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x8(%rbp)
movslq %eax, %rcx
leaq 0x71cd2b(%rip), %rax    # 0x7a5080
movb $-0x56, (%rax,%rcx)
movl -0x8(%rbp), %eax
movw %ax, 0x71cd1d(%rip)     # 0x7a5080
movl -0x8(%rbp), %esi
leaq 0x71cd13(%rip), %rdi    # 0x7a5080
callq 0x88e40
movw %ax, %dx
movslq -0x8(%rbp), %rcx
leaq 0x71cd00(%rip), %rax    # 0x7a5080
movw %dx, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %edx
leaq 0x71cce6(%rip), %rsi    # 0x7a5080
callq 0x86e60
movslq -0x4(%rbp), %rcx
leaq 0x71cc06(%rip), %rax    # 0x7a4fb0
cmpl $0x0, (%rax,%rcx,4)
jne 0x883bc
movl $0x0, -0xc(%rbp)
jmp 0x8849c
movslq -0x4(%rbp), %rcx
leaq 0x71cc29(%rip), %rax    # 0x7a4ff0
movl (%rax,%rcx,4), %eax
movslq -0x4(%rbp), %rdx
leaq 0x71cbdb(%rip), %rcx    # 0x7a4fb0
cmpl (%rcx,%rdx,4), %eax
je 0x88429
movslq -0x4(%rbp), %rcx
leaq 0x71cc4b(%rip), %rax    # 0x7a5030
cmpb $0x0, (%rax,%rcx)
jne 0x8840b
movl -0x4(%rbp), %esi
leaq 0x68947(%rip), %rdi     # 0xf0d3c
movb $0x0, %al
callq 0x52630
movslq -0x4(%rbp), %rcx
leaq 0x71cc29(%rip), %rax    # 0x7a5030
movb $0x1, (%rax,%rcx)
movslq -0x4(%rbp), %rcx
leaq 0x71cb9a(%rip), %rax    # 0x7a4fb0
movl (%rax,%rcx,4), %edx
movslq -0x4(%rbp), %rcx
leaq 0x71cbcc(%rip), %rax    # 0x7a4ff0
movl %edx, (%rax,%rcx,4)
jmp 0x8849a
movslq -0x4(%rbp), %rcx
leaq 0x71cbbc(%rip), %rax    # 0x7a4ff0
movl (%rax,%rcx,4), %eax
subl 0x71cb67(%rip), %eax    # 0x7a4fa4
cmpl $0x7d0, %eax            # imm = 0x7D0
jle 0x88498
movslq -0x4(%rbp), %rcx
leaq 0x71cbe1(%rip), %rax    # 0x7a5030
cmpb $0x0, (%rax,%rcx)
je 0x88475
movl -0x4(%rbp), %esi
leaq 0x688f8(%rip), %rdi     # 0xf0d57
movb $0x0, %al
callq 0x52630
movslq -0x4(%rbp), %rcx
leaq 0x71cbbf(%rip), %rax    # 0x7a5030
movb $0x0, (%rax,%rcx)
movslq -0x4(%rbp), %rcx
leaq 0x71cb30(%rip), %rax    # 0x7a4fb0
movl (%rax,%rcx,4), %edx
movslq -0x4(%rbp), %rcx
leaq 0x71cb62(%rip), %rax    # 0x7a4ff0
movl %edx, (%rax,%rcx,4)
movl $0x0, -0xc(%rbp)
jmp 0x8849a
jmp 0x8849c
jmp 0x8849e
cmpl $0x0, 0xa3c5b(%rip)     # 0x12c100
jne 0x884a9
jmp 0x884c0
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
cmpl $0x0, %eax
jge 0x884b9
jmp 0x884c0
jmp 0x884bb
jmp 0x882af
jmp 0x884c2
movb $0x1, %al
cmpl $0x0, 0x71cad5(%rip)    # 0x7a4fa0
movb %al, -0xd(%rbp)
jne 0x884da
cmpl $0x0, -0xc(%rbp)
setne %al
movb %al, -0xd(%rbp)
movb -0xd(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x71cab8(%rip)    # 0x7a4fa0
cmpl $0x0, 0x71cab1(%rip)    # 0x7a4fa0
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addq $0x10, %rsp
popq %rbp
retq
nop