// File: /workspace/github_c_makefile_star2_O3/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 0x5da6e
testl %ebp, %ebp
jle 0x5e070
movl %ebp, 0x8(%rsp)
movl %ebp, %r14d
movl $0xff, %r15d
movl $0x5bd9, 0x4(%rsp)      # imm = 0x5BD9
movabsq $0x2100000021, %r13     # imm = 0x2100000021
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rbx, 0x28(%rsp)
movq (%rbx,%rbp,8), %rdi
movzbl (%rdi), %eax
orl $0x2, %eax
cmpl $0x2f, %eax
jne 0x5ddd6
movzbl 0x1(%rdi), %eax
leal -0x49(%rax), %ecx
cmpl $0x27, %ecx
ja 0x5ddd6
btq %rcx, %r13
jae 0x5dcb9
movzbl 0x2(%rdi), %eax
movl $0x2, %r12d
leal -0x31(%rax), %ecx
cmpl $0x3f, %ecx
ja 0x5dd53
movabsq $-0x7fffffff7fffffff, %rdx # imm = 0x8000000080000001
btq %rcx, %rdx
jae 0x5dd43
leaq 0x48fda(%rip), %rdi     # 0xa6c81
xorl %eax, %eax
callq 0x372d1
movl $0x1, %r15d
jmp 0x5ddd6
movabsq $0x8000000080, %rdx     # imm = 0x8000000080
btq %rcx, %rdx
jae 0x5ddd6
cmpb $0x0, 0x2(%rdi)
je 0x5ddc4
addq $0x2, %rdi
leaq 0x60(%rsp), %rsi
movl $0xa, %edx
callq 0x8cd0
movq %r14, %rbx
movq %r12, %r14
movq %r13, %r12
movl %r15d, %r13d
movq %rax, %r15
movq 0x60(%rsp), %rax
leal -0x1(%r15), %ecx
cmpl $0xfffe, %ecx           # imm = 0xFFFE
movl 0x4(%rsp), %ecx
cmovael %ecx, %r15d
cmpb $0x0, (%rax)
cmovnel %ecx, %r15d
leaq 0x48ef0(%rip), %rdi     # 0xa6c0e
movl %r15d, %esi
xorl %eax, %eax
callq 0x372d1
movl %r15d, 0x4(%rsp)
movl %r13d, %r15d
movq %r12, %r13
movq %r14, %r12
movq %rbx, %r14
movq 0x28(%rsp), %rbx
jmp 0x5ddd6
movabsq $0x1000000010000000, %rdx # imm = 0x1000000010000000
btq %rcx, %rdx
jb 0x5dd58
cmpl $0x30, %eax
jne 0x5ddd6
xorl %r15d, %r15d
leaq 0x48ec3(%rip), %rdi     # 0xa6c25
xorl %eax, %eax
callq 0x372d1
movq (%rbx,%rbp,8), %rdi
cmpb $0x3a, 0x3(%rdi)
jne 0x5ddd6
movb 0x4(%rdi), %al
addb $-0x30, %al
cmpb $0x9, %al
ja 0x5ddd6
addq $0x4, %rdi
leaq 0x60(%rsp), %rsi
movl $0xa, %edx
callq 0x8cd0
movq %rax, %r12
movq 0x60(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x5e26b
leal -0x1(%r12), %eax
cmpl $0xf, %eax
ja 0x5e26b
xorl %r15d, %r15d
leaq 0x48e88(%rip), %rdi     # 0xa6c40
movl %r12d, %esi
xorl %eax, %eax
callq 0x372d1
jmp 0x5ddd6
cmpl $0x6e, %eax
je 0x5dc76
cmpl $0x69, %eax
je 0x5dc76
incq %rbp
cmpq %rbp, %r14
jne 0x5dc4d
movl 0x4(%rsp), %edi
callq 0x5d4c5
testl %eax, %eax
je 0x5e08c
cmpl $0x0, 0x8(%rsp)
jle 0x5e087
movl %r15d, 0x4(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r12, 0x18(%rsp)
movq (%rbx,%r15,8), %rbp
movzbl (%rbp), %esi
movl %esi, %eax
orl $0x2, %eax
cmpl $0x2f, %eax
jne 0x5de2d
incq %r15
cmpq %r14, %r15
jne 0x5de0e
jmp 0x5e0a1
cmpl $0x0, 0x4(%rsp)
sete %al
testl %r13d, %r13d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5de52
leaq 0x48e82(%rip), %rdi     # 0xa6ccb
xorl %eax, %eax
callq 0x372d1
jmp 0x5de20
cmpl $0x10, %r13d
jge 0x5e277
movl %esi, %eax
orl $0x4, %eax
cmpl $0x2e, %eax
jne 0x5de70
cmpb $0x0, 0x1(%rbp)
je 0x5e041
movq %rbp, %rdi
callq 0x8070
testq %rax, %rax
je 0x5e2bc
movq %r13, 0x20(%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movl $0x3a, %esi
callq 0x8dd0
xorl %r13d, %r13d
testq %rax, %rax
je 0x5debe
movb $0x0, (%rax)
cmpb $0x0, 0x1(%rax)
je 0x5debe
incq %rax
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x8cd0
movq %rax, %r13
leaq 0x40(%rsp), %rax
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%rax)
movdqu %xmm0, (%rax)
movl $0x20, 0x30(%rsp)
movl 0x747262(%rip), %eax    # 0x7a5140
movl %eax, 0x34(%rsp)
cmpl $0xa, %eax
jne 0x5deef
movl $0x28, 0x30(%rsp)
movabsq $0x1100000002, %rax     # imm = 0x1100000002
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rdi
xorl %esi, %esi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x9000
testl %eax, %eax
jne 0x5e28e
movq 0x10(%rsp), %rbp
testq %rbp, %rbp
je 0x5e2ab
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(%rbp), %eax
movl %eax, %ecx
xorl $0x2, %ecx
orl %r12d, %ecx
je 0x5df8f
xorl $0xa, %eax
orl %r12d, %eax
je 0x5df9f
testl %r12d, %r12d
sete %al
cmpl $0x1, 0x4(%rsp)
setne %cl
orb %al, %cl
jne 0x5dfc4
movq 0x18(%rbp), %rdi
callq 0x5e315
leaq 0x48f68(%rip), %rdi     # 0xa6ee6
movq 0x8(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x372d1
jmp 0x5dfbe
movq 0x18(%rbp), %rax
movdqu (%rax), %xmm0
movdqa %xmm0, 0x60(%rsp)
jmp 0x5dfb8
movq 0x18(%rbp), %rax
movdqu (%rax), %xmm0
movdqu 0xc(%rax), %xmm1
movdqa %xmm0, 0x60(%rsp)
movdqu %xmm1, 0x6c(%rsp)
movw %r13w, 0x62(%rsp)
movl $0x1, %r12d
movq 0x28(%rbp), %rbp
testq %rbp, %rbp
jne 0x5df47
movq 0x10(%rsp), %rdi
callq 0x8960
movq 0x8(%rsp), %rdi
callq 0x8270
testl %r12d, %r12d
je 0x5e2bc
movq 0x20(%rsp), %r13
movslq %r13d, %rdi
shlq $0x7, %rdi
leaq 0x74714f(%rip), %rax    # 0x7a5150
addq %rax, %rdi
movl $0x10, %ecx
leaq 0x60(%rsp), %rax
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x5e315
movq (%rbx,%r15,8), %rcx
leaq 0x48d87(%rip), %rdi     # 0xa6dae
movl %r13d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x372d1
incl %r13d
movq 0x18(%rsp), %r12
jmp 0x5de20
cmpl $0x0, 0x4(%rsp)
je 0x5e307
leal 0x1(%r13), %ebp
movl %r13d, 0x747acd(%rip)   # 0x7a5b24
leaq 0x48d09(%rip), %rdi     # 0xa6d67
movl %r13d, %esi
xorl %eax, %eax
callq 0x372d1
movl %ebp, %r13d
jmp 0x5de20
movl $0x5bd9, %edi           # imm = 0x5BD9
callq 0x5d4c5
testl %eax, %eax
je 0x5e08c
movl $0xff, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x5e0a6
leaq 0x48c09(%rip), %rdi     # 0xa6c9c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x372d1
jmp 0x5e2f3
movl 0x4(%rsp), %r15d
cmpl $0xff, %r15d
sete %al
testl %r13d, %r13d
sete %dl
setne %cl
xorl %ebx, %ebx
testb %cl, %al
movl $0x2, %ecx
cmovel %r12d, %ecx
cmovel %r15d, %ebx
cmpl $0x2, %ecx
setl %al
orb %dl, %al
testl %ebx, %ebx
setne %dl
orb %al, %dl
jne 0x5e10a
movl $0x1, 0x747a3f(%rip)    # 0x7a5b24
cmpl %ecx, %r13d
cmovgl %r13d, %ecx
movl %ebx, 0x85776(%rip)     # 0xe3868
movl %ecx, 0x747a34(%rip)    # 0x7a5b2c
movl $0x0, 0x747a2e(%rip)    # 0x7a5b30
leal -0x1(%rcx), %eax
movl %ecx, %r14d
jmp 0x5e158
cmpl $0x1, %ecx
movl %ecx, %r14d
adcl $0x0, %r14d
cmpl %ecx, %r13d
cmovgl %r13d, %r14d
movl 0x747a03(%rip), %eax    # 0x7a5b24
orl %ebx, %eax
jne 0x5e133
leaq 0x48ca0(%rip), %rdi     # 0xa6dcc
xorl %eax, %eax
callq 0x372d1
movl %ebx, 0x8572f(%rip)     # 0xe3868
movl %r14d, 0x7479ec(%rip)   # 0x7a5b2c
movl $0x0, 0x7479e6(%rip)    # 0x7a5b30
leal -0x1(%r14), %eax
cmpl $0x2, %r14d
jl 0x5e207
movl %eax, %edx
leal 0x1(%rax), %ecx
andl $-0x2, %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x31cab(%rip), %xmm1    # 0x8fe20
xorl %edx, %edx
movdqa 0x321c1(%rip), %xmm2    # 0x90340
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
leaq 0x7479b2(%rip), %rsi    # 0x7a5b40
movdqa 0x31cba(%rip), %xmm4    # 0x8fe50
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pand %xmm6, %xmm5
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
por %xmm5, %xmm6
movdqa %xmm1, %xmm5
psubq %xmm3, %xmm5
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0x5e1d5
movd %xmm5, (%rsi,%rdx,4)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x5e1ef
pshufd $0xee, %xmm5, %xmm5     # xmm5 = xmm5[2,3,2,3]
movd %xmm5, 0x4(%rsi,%rdx,4)
addq $0x2, %rdx
paddq %xmm4, %xmm1
cmpq %rdx, %rcx
jne 0x5e196
cmpl $0x2, %r14d
sete %dl
movb $0x1, %cl
jmp 0x5e20b
xorl %ecx, %ecx
xorl %edx, %edx
testl %ebx, %ebx
sete %sil
cltq
leaq 0x747926(%rip), %rdi    # 0x7a5b40
movl $0xffffffff, (%rdi,%rax,4) # imm = 0xFFFFFFFF
movl $0x0, 0x747955(%rip)    # 0x7a5b80
movl $0x1, %ebx
testb %cl, %sil
jne 0x5e2f3
testb %dl, %dl
jne 0x5e2f3
movl 0x85625(%rip), %edi     # 0xe386c
testl %edi, %edi
js 0x5e250
callq 0x8310
movl $0xffffffff, 0x85612(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x746edc(%rip)    # 0x7a5140
xorl %ebx, %ebx
jmp 0x5e2f3
leaq 0x489e6(%rip), %rdi     # 0xa6c58
jmp 0x5e093
leaq 0x48a8e(%rip), %rdi     # 0xa6d0c
xorl %ebx, %ebx
movl $0x10, %esi
xorl %eax, %eax
callq 0x372d1
jmp 0x5e2d0
movl %eax, %edi
callq 0x91f0
leaq 0x48c21(%rip), %rdi     # 0xa6ebd
movq %rbp, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x372d1
jmp 0x5e2b2
xorl %edi, %edi
callq 0x8960
movq 0x8(%rsp), %rdi
callq 0x8270
movq (%rbx,%r15,8), %rsi
leaq 0x48ac3(%rip), %rdi     # 0xa6d8a
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x372d1
movl 0x85596(%rip), %edi     # 0xe386c
testl %edi, %edi
js 0x5e2df
callq 0x8310
movl $0xffffffff, 0x85583(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x746e4d(%rip)    # 0x7a5140
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48a2b(%rip), %rdi     # 0xa6d39
xorl %ebx, %ebx
jmp 0x5e285