// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/mmulti.c
// Function: initmultiplayersparms
int initmultiplayersparms(int argc, char const * const argv[])
{
	int i, j, daindex, danumplayers, danetmode, portnum = NETPORT;
	struct sockaddr_storage resolvhost;

	initmultiplayers_reset();
	danetmode = 255; daindex = 0; danumplayers = 0;

	for (i=0;i<argc;i++) {
		if (argv[i][0] != '-' && argv[i][0] != '/') continue;

		// -p1234 = Listen port
		if ((argv[i][1] == 'p' || argv[i][1] == 'P') && argv[i][2]) {
			char *p;
			j = (int)strtol(argv[i]+2, &p, 10);
			if (!(*p) && j > 0 && j<65535) portnum = j;

			printf("mmulti: Using port %d\n", portnum);
			continue;
		}

		// -nm,   -n0   = Master/slave, 2 players
		// -nm:n, -n0:n = Master/slave, n players
		// -np,   -n1   = Peer-to-peer
		if ((argv[i][1] == 'N') || (argv[i][1] == 'n') || (argv[i][1] == 'I') || (argv[i][1] == 'i'))
		{
			danumplayers = 2;
			if (argv[i][2] == '0' || argv[i][2] == 'm' || argv[i][2] == 'M')
			{
				danetmode = MMULTI_MODE_MS;
				printf("mmulti: Master-slave mode\n");

				if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9'))
				{
					char *p;
					j = (int)strtol(argv[i]+4, &p, 10);
					if (!(*p) && j > 0 && j <= MAXPLAYERS) {
						danumplayers = j;
						printf("mmulti: %d-player game\n", danumplayers);
					} else {
						printf("mmulti error: Invalid number of players\n");
						return 0;
					}
				}
			}
			else if (argv[i][2] == '1' || argv[i][2] == 'p' || argv[i][2] == 'P')
			{
				danetmode = MMULTI_MODE_P2P;
				printf("mmulti: Peer-to-peer mode\n");
			}
			continue;
		}
	}

	if (!netinit(portnum)) {
		printf("mmulti error: Could not initialise networking\n");
		return 0;
	}

	for(i=0;i<argc;i++)
	{
		if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
			continue;
		}

		if (danetmode == MMULTI_MODE_MS && daindex >= 1) {
			printf("mmulti warning: Too many host names given for master-slave mode\n");
			continue;
		}
		if (daindex >= MAXPLAYERS) {
			printf("mmulti error: More than %d players provided\n", MAXPLAYERS);
			netuninit();
			return 0;
		}

		if ((argv[i][0] == '*' || argv[i][0] == '.') && argv[i][1] == 0) {
			// 'self' placeholder
			if (danetmode == MMULTI_MODE_MS) {
				printf("mmulti: %c is not valid in master-slave mode\n", argv[i][0]);
				netuninit();
				return 0;
			} else {
				myconnectindex = daindex++;
				printf("mmulti: This machine is player %d\n", myconnectindex);
			}
			continue;
		}

		if (!lookuphost(argv[i], (struct sockaddr *)&resolvhost, danetmode == MMULTI_MODE_P2P)) {
			printf("mmulti error: Could not resolve %s\n", argv[i]);
			netuninit();
			return 0;
		} else {
			memcpy(&otherhost[daindex], &resolvhost, sizeof(resolvhost));
			printf("mmulti: Player %d at %s (%s)\n", daindex,
				presentaddress((struct sockaddr *)&resolvhost), argv[i]);
			daindex++;
		}
	}

	if ((danetmode == 255) && (daindex)) { danumplayers = 2; danetmode = MMULTI_MODE_MS; } //an IP w/o /n# defaults to /n0
	if ((danumplayers >= 2) && (daindex) && (danetmode == MMULTI_MODE_MS)) myconnectindex = 1;
	if (daindex > danumplayers) danumplayers = daindex;
	else if (danumplayers == 0) danumplayers = 1;

	if (danetmode == MMULTI_MODE_MS && myconnectindex == 0) {
		printf("mmulti: This machine is master\n");
	}

	networkmode = danetmode;
	numplayers = danumplayers;

	connecthead = 0;
	for(i=0;i<numplayers-1;i++) connectpoint2[i] = i+1;
	connectpoint2[numplayers-1] = -1;

	netready = 0;

	if (((danetmode == MMULTI_MODE_MS) && (numplayers >= 2)) || (numplayers == 2)) {
		return 1;
	} else {
		netuninit();
		return 0;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %rbx
movl %edi, %r14d
callq 0x53db8
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
movl $0x5bd9, 0x8(%rsp)      # imm = 0x5BD9
movl $0xff, 0x4(%rsp)
movabsq $0x2100000021, %r12     # imm = 0x2100000021
pushq $0x2
popq %r13
movabsq $-0x7fffffff7fffffff, %r15 # imm = 0x8000000080000001
xorl %ebp, %ebp
xorl %edx, %edx
movq %rbx, 0x28(%rsp)
cmpq %rbp, %r14
je 0x54100
movq (%rbx,%rbp,8), %rdi
movzbl (%rdi), %eax
orl $0x2, %eax
cmpl $0x2f, %eax
jne 0x540e4
movzbl 0x1(%rdi), %eax
leal -0x49(%rax), %ecx
cmpl $0x27, %ecx
ja 0x540e4
btq %rcx, %r12
jae 0x53fb9
movzbl 0x2(%rdi), %eax
leal -0x31(%rax), %ecx
cmpl $0x3f, %ecx
ja 0x5405d
btq %rcx, %r15
jae 0x5404d
leaq 0x449ee(%rip), %rdi     # 0x98991
xorl %eax, %eax
callq 0x33127
movl %r13d, %edx
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
jmp 0x540e4
movabsq $0x8000000080, %rsi     # imm = 0x8000000080
btq %rcx, %rsi
jae 0x540e4
cmpb $0x0, 0x2(%rdi)
je 0x540ec
addq $0x2, %rdi
leaq 0x60(%rsp), %rsi
movq %r14, %rbx
movl %r13d, %r14d
movq %r12, %r13
movq %rdx, %r12
pushq $0xa
popq %rdx
callq 0x8cd0
movq %rax, %r15
movq 0x60(%rsp), %rax
leal -0x1(%r15), %ecx
cmpl $0xfffe, %ecx           # imm = 0xFFFE
movl 0x8(%rsp), %ecx
cmovael %ecx, %r15d
cmpb $0x0, (%rax)
cmovnel %ecx, %r15d
leaq 0x44902(%rip), %rdi     # 0x9891e
movl %r15d, %esi
xorl %eax, %eax
callq 0x33127
movq %r12, %rdx
movq %r13, %r12
movl %r14d, %r13d
movq %rbx, %r14
movq 0x28(%rsp), %rbx
movl %r15d, %eax
movabsq $-0x7fffffff7fffffff, %r15 # imm = 0x8000000080000001
movl %eax, 0x8(%rsp)
jmp 0x540e4
movabsq $0x1000000010000000, %rdx # imm = 0x1000000010000000
btq %rcx, %rdx
jb 0x54062
cmpl $0x30, %eax
jne 0x540e1
movl $0x0, 0x4(%rsp)
leaq 0x448c4(%rip), %rdi     # 0x98935
xorl %eax, %eax
callq 0x33127
movq (%rbx,%rbp,8), %rdi
cmpb $0x3a, 0x3(%rdi)
jne 0x540e1
movb 0x4(%rdi), %al
addb $-0x30, %al
cmpb $0x9, %al
ja 0x540e1
addq $0x4, %rdi
leaq 0x60(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x8cd0
movq %rax, %rsi
movq 0x60(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x544d6
leal -0x1(%rsi), %eax
cmpl $0xf, %eax
ja 0x544d6
movl $0x0, 0x4(%rsp)
leaq 0x44888(%rip), %rdi     # 0x98950
xorl %eax, %eax
movq %rsi, %r15
callq 0x33127
movq %r15, %rdx
movabsq $-0x7fffffff7fffffff, %r15 # imm = 0x8000000080000001
jmp 0x540e4
movl %r13d, %edx
incq %rbp
jmp 0x53f50
cmpl $0x6e, %eax
je 0x53f82
cmpl $0x69, %eax
je 0x53f82
jmp 0x540e4
movq %rdx, 0x18(%rsp)
movl 0x8(%rsp), %edi
callq 0x5389b
testl %eax, %eax
je 0x543b8
leaq 0x10(%rsp), %rbp
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq %r14, %r12
je 0x54371
movq (%rbx,%r12,8), %r15
movzbl (%r15), %esi
movl %esi, %eax
orl $0x2, %eax
cmpl $0x2f, %eax
jne 0x54141
incq %r12
jmp 0x54121
cmpl $0x0, 0x4(%rsp)
sete %al
testl %r13d, %r13d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x54166
leaq 0x4487e(%rip), %rdi     # 0x989db
xorl %eax, %eax
callq 0x33127
jmp 0x5413c
cmpl $0x10, %r13d
jge 0x5446f
movl %esi, %eax
orl $0x4, %eax
cmpl $0x2e, %eax
jne 0x54185
cmpb $0x0, 0x1(%r15)
je 0x5433c
movq %r15, %rdi
callq 0x8070
testq %rax, %rax
je 0x544a9
movq %r13, 0x20(%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %rdi
pushq $0x3a
popq %rsi
callq 0x8dd0
xorl %r13d, %r13d
testq %rax, %rax
je 0x541cf
movb $0x0, (%rax)
cmpb $0x0, 0x1(%rax)
je 0x541cf
incq %rax
movq %rax, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x8cd0
movq %rax, %r13
leaq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl $0x20, 0x30(%rsp)
movl 0x746f54(%rip), %eax    # 0x79b140
movl %eax, 0x34(%rsp)
cmpl $0xa, %eax
jne 0x541fd
movl $0x28, 0x30(%rsp)
movabsq $0x1100000002, %rax     # imm = 0x1100000002
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rdi
xorl %esi, %esi
leaq 0x30(%rsp), %rdx
movq %rbp, %rcx
callq 0x9000
testl %eax, %eax
jne 0x54484
leal -0xffff(%r13), %eax
cmpl $0xffff0402, %eax       # imm = 0xFFFF0402
movl $0x5bd9, %eax           # imm = 0x5BD9
cmovbl %eax, %r13d
rolw $0x8, %r13w
movq %rbp, %r15
xorl %ebp, %ebp
pushq $0x1
popq %rdx
movq (%r15), %r15
testq %r15, %r15
je 0x542cf
movl 0x4(%r15), %eax
movl %eax, %ecx
xorl $0x2, %ecx
orl %ebp, %ecx
je 0x5429b
xorl $0xa, %eax
orl %ebp, %eax
je 0x542a9
testl %ebp, %ebp
sete %al
cmpl $0x1, 0x4(%rsp)
setne %cl
orb %al, %cl
jne 0x542c6
movq 0x18(%r15), %rdi
callq 0x544ed
leaq 0x4496f(%rip), %rdi     # 0x98bf6
movq 0x8(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x33127
pushq $0x1
popq %rdx
jmp 0x542c4
movq 0x18(%r15), %rax
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
jmp 0x542be
movq 0x18(%r15), %rax
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movaps %xmm0, 0x60(%rsp)
movups %xmm1, 0x6c(%rsp)
movw %r13w, 0x62(%rsp)
movl %edx, %ebp
addq $0x28, %r15
jmp 0x5424a
movq 0x10(%rsp), %rdi
callq 0x8960
movq 0x8(%rsp), %rdi
callq 0x8270
testl %ebp, %ebp
je 0x544a9
movq 0x20(%rsp), %r13
movslq %r13d, %rdi
shlq $0x7, %rdi
leaq 0x746e52(%rip), %rax    # 0x79b150
addq %rax, %rdi
pushq $0x10
popq %rcx
leaq 0x60(%rsp), %rax
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x544ed
movq (%rbx,%r12,8), %rcx
leaq 0x4479c(%rip), %rdi     # 0x98abe
movl %r13d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x33127
incl %r13d
leaq 0x10(%rsp), %rbp
jmp 0x5413c
cmpl $0x0, 0x4(%rsp)
je 0x544e2
movq %rbp, %r15
leal 0x1(%r13), %ebp
movl %r13d, 0x7477cf(%rip)   # 0x79bb24
leaq 0x4471b(%rip), %rdi     # 0x98a77
movl %r13d, %esi
xorl %eax, %eax
callq 0x33127
movl %ebp, %r13d
movq %r15, %rbp
jmp 0x5413c
movl 0x4(%rsp), %edx
cmpl $0xff, %edx
sete %al
testl %r13d, %r13d
setne %cl
xorl %ebx, %ebx
testb %cl, %al
pushq $0x2
popq %rax
movq 0x18(%rsp), %rsi
cmovnel %eax, %esi
cmovel %edx, %ebx
movq %rsi, %rdx
cmpl $0x2, %edx
setge %al
andb %cl, %al
testl %ebx, %ebx
sete %cl
testb %cl, %al
je 0x543cd
movl $0x1, 0x747770(%rip)    # 0x79bb24
xorl %eax, %eax
jmp 0x543d7
leaq 0x445ed(%rip), %rdi     # 0x989ac
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x33127
jmp 0x544c2
cmpl $0x0, 0x747750(%rip)    # 0x79bb24
sete %al
cmpl $0x1, %edx
movl %edx, %r14d
adcl $0x0, %r14d
cmpl %edx, %r13d
cmovgl %r13d, %r14d
testl %ebx, %ebx
jne 0x543fe
testb %al, %al
je 0x543fe
leaq 0x446e5(%rip), %rdi     # 0x98adc
xorl %eax, %eax
callq 0x33127
andl $0x0, 0x74772b(%rip)    # 0x79bb30
movl %ebx, 0x8545d(%rip)     # 0xd9868
leal -0x1(%r14), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movl %r14d, 0x74770a(%rip)   # 0x79bb2c
shlq $0x2, %rdx
pushq $0x1
popq %rdi
leaq 0x747710(%rip), %rsi    # 0x79bb40
cmpq %rcx, %rdx
je 0x54440
movl %edi, (%rcx,%rsi)
addq $0x4, %rcx
incl %edi
jmp 0x54430
testl %ebx, %ebx
sete %cl
cltq
orl $-0x1, (%rsi,%rax,4)
andl $0x0, 0x74772e(%rip)    # 0x79bb80
cmpl $0x2, %r14d
setge %al
pushq $0x1
popq %rbx
testb %al, %cl
jne 0x544c2
cmpl $0x2, %r14d
je 0x544c2
callq 0x53878
xorl %ebx, %ebx
jmp 0x544c2
leaq 0x445a6(%rip), %rdi     # 0x98a1c
xorl %ebx, %ebx
pushq $0x10
popq %rsi
xorl %eax, %eax
callq 0x33127
jmp 0x544bd
movl %eax, %edi
callq 0x91f0
leaq 0x4473b(%rip), %rdi     # 0x98bcd
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x33127
movq 0x8(%rsp), %rdi
callq 0x8270
movq (%rbx,%r12,8), %rsi
leaq 0x445e6(%rip), %rdi     # 0x98a9a
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x33127
callq 0x53878
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4448b(%rip), %rdi     # 0x98968
jmp 0x543bf
leaq 0x44560(%rip), %rdi     # 0x98a49
xorl %ebx, %ebx
jmp 0x5447b