// File: /workspace/github_c_makefile_star2_O1/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, %ebp
callq 0x5a88b
movl %ebp, %r15d
movl %ebp, 0x10(%rsp)
testl %ebp, %ebp
jle 0x5ac27
movl $0xff, 0xc(%rsp)
movl $0x5bd9, %r13d          # imm = 0x5BD9
movabsq $0x2100000021, %rbp     # imm = 0x2100000021
xorl %r12d, %r12d
xorl %r14d, %r14d
movq (%rbx,%r12,8), %rdi
movzbl (%rdi), %eax
orl $0x2, %eax
cmpl $0x2f, %eax
jne 0x5ac19
movzbl 0x1(%rdi), %eax
addl $-0x49, %eax
cmpl $0x27, %eax
ja 0x5ac19
btq %rax, %rbp
jae 0x5aacf
movzbl 0x2(%rdi), %eax
movl $0x2, %r14d
leal -0x31(%rax), %ecx
cmpl $0x3f, %ecx
ja 0x5ab56
movabsq $-0x7fffffff7fffffff, %rdx # imm = 0x8000000080000001
btq %rcx, %rdx
jae 0x5ab46
leaq 0x48e26(%rip), %rdi     # 0xa38e1
xorl %eax, %eax
callq 0x36050
movl $0x1, 0xc(%rsp)
jmp 0x5ac19
movabsq $0x8000000080, %rcx     # imm = 0x8000000080
btq %rax, %rcx
jae 0x5ac19
cmpb $0x0, 0x2(%rdi)
je 0x5abd7
addq $0x2, %rdi
leaq 0x60(%rsp), %rsi
movl $0xa, %edx
callq 0x8cd0
movq %r14, %rbp
movq %rax, %r14
movq 0x60(%rsp), %rax
leal -0x1(%r14), %ecx
cmpl $0xfffe, %ecx           # imm = 0xFFFE
cmovael %r13d, %r14d
cmpb $0x0, (%rax)
cmovnel %r13d, %r14d
leaq 0x48d47(%rip), %rdi     # 0xa386e
movl %r14d, %esi
xorl %eax, %eax
callq 0x36050
movl %r14d, %r13d
movq %rbp, %r14
movabsq $0x2100000021, %rbp     # imm = 0x2100000021
jmp 0x5ac19
movabsq $0x1000000010000000, %rdx # imm = 0x1000000010000000
btq %rcx, %rdx
jb 0x5ab5f
cmpl $0x30, %eax
jne 0x5ac19
movl $0x0, 0xc(%rsp)
leaq 0x48d17(%rip), %rdi     # 0xa3885
xorl %eax, %eax
callq 0x36050
movq (%rbx,%r12,8), %rdi
cmpb $0x3a, 0x3(%rdi)
jne 0x5ac19
movb 0x4(%rdi), %al
addb $-0x30, %al
cmpb $0x9, %al
ja 0x5ac19
addq $0x4, %rdi
leaq 0x60(%rsp), %rsi
movl $0xa, %edx
callq 0x8cd0
movq %rax, %rsi
movq 0x60(%rsp), %rax
cmpb $0x0, (%rax)
sete %al
leal -0x1(%rsi), %ecx
cmpl $0x10, %ecx
setb %r14b
andb %al, %r14b
cmpb $0x1, %r14b
jne 0x5abe8
leaq 0x48cd5(%rip), %rdi     # 0xa38a0
movq %rsi, %rbp
xorl %eax, %eax
callq 0x36050
jmp 0x5abfb
cmpl $0x25, %eax
ja 0x5ac19
btq %rax, %rbp
jb 0x5aa8a
jmp 0x5ac19
leaq 0x48cc9(%rip), %rdi     # 0xa38b8
xorl %eax, %eax
callq 0x36050
movl $0x2, %ebp
movl $0x0, 0xc(%rsp)
testb %r14b, %r14b
movq %rbp, %r14
movabsq $0x2100000021, %rbp     # imm = 0x2100000021
je 0x5b080
incq %r12
cmpq %r12, %r15
jne 0x5aa61
jmp 0x5ac38
movl $0x5bd9, %r13d          # imm = 0x5BD9
movl $0xff, 0xc(%rsp)
xorl %r14d, %r14d
movl %r13d, %edi
callq 0x5a2ed
testl %eax, %eax
je 0x5afda
movq %r14, 0x20(%rsp)
movl $0x0, %r12d
cmpl $0x0, 0x10(%rsp)
jle 0x5aebd
xorl %ebp, %ebp
xorl %r12d, %r12d
movq (%rbx,%rbp,8), %r14
movzbl (%r14), %eax
movl %eax, %ecx
orl $0x2, %ecx
cmpl $0x2f, %ecx
jne 0x5ac82
incq %rbp
cmpq %r15, %rbp
jne 0x5ac63
jmp 0x5aebd
cmpl $0x0, 0xc(%rsp)
sete %cl
testl %r12d, %r12d
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5aca7
leaq 0x48c8d(%rip), %rdi     # 0xa392b
xorl %eax, %eax
callq 0x36050
jmp 0x5ac75
cmpl $0x10, %r12d
jge 0x5aff5
movl %eax, %ecx
orb $0x4, %cl
cmpb $0x2e, %cl
jne 0x5acc6
cmpb $0x0, 0x1(%r14)
je 0x5ae8d
movq %r14, %rdi
callq 0x8070
testq %rax, %rax
je 0x5b043
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movl $0x3a, %esi
callq 0x8dd0
xorl %r13d, %r13d
testq %rax, %rax
je 0x5ad0f
movb $0x0, (%rax)
cmpb $0x0, 0x1(%rax)
je 0x5ad0f
incq %rax
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x8cd0
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movl $0x20, 0x30(%rsp)
movl 0x7473f1(%rip), %eax    # 0x7a2120
movl %eax, 0x34(%rsp)
cmpl $0xa, %eax
jne 0x5ad40
movl $0x28, 0x30(%rsp)
movabsq $0x1100000002, %rax     # imm = 0x1100000002
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
leaq 0x30(%rsp), %rdx
leaq 0x18(%rsp), %rcx
callq 0x9000
testl %eax, %eax
jne 0x5b012
movq 0x18(%rsp), %r14
testq %r14, %r14
je 0x5b02f
movq %r12, 0x28(%rsp)
leal -0xffff(%r13), %eax
cmpl $0xffff0402, %eax       # imm = 0xFFFF0402
movl $0x5bd9, %eax           # imm = 0x5BD9
cmovbl %eax, %r13d
rolw $0x8, %r13w
xorl %r12d, %r12d
movl 0x4(%r14), %eax
movl %eax, %ecx
xorl $0x2, %ecx
orl %r12d, %ecx
je 0x5ade6
xorl $0xa, %eax
orl %r12d, %eax
je 0x5adf4
testl %r12d, %r12d
sete %al
cmpl $0x1, 0xc(%rsp)
setne %cl
orb %al, %cl
jne 0x5ae15
movq 0x18(%r14), %rdi
callq 0x5b0ad
leaq 0x48d71(%rip), %rdi     # 0xa3b46
movq 0x10(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x36050
jmp 0x5ae0f
movq 0x18(%r14), %rax
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
jmp 0x5ae09
movq 0x18(%r14), %rax
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movaps %xmm0, 0x60(%rsp)
movups %xmm1, 0x6c(%rsp)
movw %r13w, 0x62(%rsp)
movl $0x1, %r12d
movq 0x28(%r14), %r14
testq %r14, %r14
jne 0x5ad9d
movq 0x18(%rsp), %rdi
callq 0x8960
movq 0x10(%rsp), %rdi
callq 0x8270
testl %r12d, %r12d
je 0x5b043
movq 0x28(%rsp), %r12
movslq %r12d, %rdi
shlq $0x7, %rdi
leaq 0x7472de(%rip), %rax    # 0x7a2130
addq %rax, %rdi
movl $0x10, %ecx
leaq 0x60(%rsp), %rax
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x5b0ad
movq (%rbx,%rbp,8), %rcx
leaq 0x48b96(%rip), %rdi     # 0xa3a0e
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x36050
incl %r12d
jmp 0x5ac75
cmpl $0x0, 0xc(%rsp)
je 0x5b096
leal 0x1(%r12), %r14d
movl %r12d, 0x747c60(%rip)   # 0x7a2b04
leaq 0x48b1c(%rip), %rdi     # 0xa39c7
movl %r12d, %esi
xorl %eax, %eax
callq 0x36050
movl %r14d, %r12d
jmp 0x5ac75
movl 0xc(%rsp), %edx
cmpl $0xff, %edx
sete %al
testl %r12d, %r12d
setne %cl
testb %cl, %al
movl $0x2, %eax
movq 0x20(%rsp), %rsi
cmovnel %eax, %esi
movl $0x0, %ebp
cmovel %edx, %ebp
cmpl $0x2, %esi
setge %al
andb %cl, %al
testl %ebp, %ebp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5af05
movl $0x1, 0x747bff(%rip)    # 0x7a2b04
cmpl $0x1, %esi
movl %esi, %ebx
adcl $0x0, %ebx
cmpl %esi, %r12d
cmovgl %r12d, %ebx
movl 0x747bea(%rip), %eax    # 0x7a2b04
orl %ebp, %eax
jne 0x5af2c
leaq 0x48b07(%rip), %rdi     # 0xa3a2c
xorl %eax, %eax
callq 0x36050
movl %ebp, 0x85936(%rip)     # 0xe0868
movl %ebx, 0x747bd4(%rip)    # 0x7a2b0c
movl $0x0, 0x747bce(%rip)    # 0x7a2b10
leal -0x1(%rbx), %eax
cmpl $0x2, %ebx
jl 0x5af6c
movl %eax, %ecx
shlq $0x2, %rcx
movl $0x1, %edx
xorl %esi, %esi
leaq 0x747bc2(%rip), %rdi    # 0x7a2b20
movl %edx, (%rsi,%rdi)
addq $0x4, %rsi
incl %edx
cmpq %rsi, %rcx
jne 0x5af5e
testl %ebp, %ebp
sete %cl
cltq
leaq 0x747ba6(%rip), %rdx    # 0x7a2b20
movl $0xffffffff, (%rdx,%rax,4) # imm = 0xFFFFFFFF
movl $0x0, 0x747bd5(%rip)    # 0x7a2b60
cmpl $0x2, %ebx
setge %al
movl $0x1, 0xc(%rsp)
testb %al, %cl
jne 0x5b080
cmpl $0x2, %ebx
je 0x5b080
movl 0x858bc(%rip), %edi     # 0xe086c
testl %edi, %edi
js 0x5afb9
callq 0x8310
movl $0xffffffff, 0x858a9(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x747153(%rip)    # 0x7a2120
movl $0x0, 0xc(%rsp)
jmp 0x5b080
leaq 0x4891b(%rip), %rdi     # 0xa38fc
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
callq 0x36050
jmp 0x5b080
leaq 0x48970(%rip), %rdi     # 0xa396c
movl $0x0, 0xc(%rsp)
movl $0x10, %esi
xorl %eax, %eax
callq 0x36050
jmp 0x5b05d
movl %eax, %edi
callq 0x91f0
leaq 0x48afd(%rip), %rdi     # 0xa3b1d
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x36050
jmp 0x5b039
movq 0x18(%rsp), %rdi
callq 0x8960
movq 0x10(%rsp), %rdi
callq 0x8270
movq (%rbx,%rbp,8), %rsi
leaq 0x4899c(%rip), %rdi     # 0xa39ea
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
callq 0x36050
movl 0x85809(%rip), %edi     # 0xe086c
testl %edi, %edi
js 0x5b06c
callq 0x8310
movl $0xffffffff, 0x857f6(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x7470a0(%rip)    # 0x7a2120
movl 0xc(%rsp), %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %al, %esi
leaq 0x488f9(%rip), %rdi     # 0xa3999
movl $0x0, 0xc(%rsp)
jmp 0x5b009