// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x5bd9, -0x28(%rbp)    # imm = 0x5BD9
callq 0x875e0
movl $0xff, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x879d6
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x87763
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x87763
jmp 0x879c8
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x70, %eax
je 0x8778d
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x50, %eax
jne 0x877fd
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x877fd
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x2, %rdi
leaq -0xb0(%rbp), %rsi
movl $0xa, %edx
callq 0x8c30
movl %eax, -0x18(%rbp)
movq -0xb0(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x877e7
cmpl $0x0, -0x18(%rbp)
jle 0x877e7
cmpl $0xffff, -0x18(%rbp)    # imm = 0xFFFF
jge 0x877e7
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %esi
leaq 0x6936d(%rip), %rdi     # 0xf0b5e
movb $0x0, %al
callq 0x52630
jmp 0x879c8
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x4e, %eax
je 0x87855
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x6e, %eax
je 0x87855
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x49, %eax
je 0x87855
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x69, %eax
jne 0x879c6
movl $0x2, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x30, %eax
je 0x8789f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x6d, %eax
je 0x8789f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x4d, %eax
jne 0x8796e
movl $0x0, -0x24(%rbp)
leaq 0x692c8(%rip), %rdi     # 0xf0b75
movb $0x0, %al
callq 0x52630
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x3(%rax), %eax
cmpl $0x3a, %eax
jne 0x8796c
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x4(%rax), %eax
cmpl $0x30, %eax
jl 0x8796c
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x4(%rax), %eax
cmpl $0x39, %eax
jg 0x8796c
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x4, %rdi
leaq -0xb8(%rbp), %rsi
movl $0xa, %edx
callq 0x8c30
movl %eax, -0x18(%rbp)
movq -0xb8(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x87950
cmpl $0x0, -0x18(%rbp)
jle 0x87950
cmpl $0x10, -0x18(%rbp)
jg 0x87950
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %esi
leaq 0x69249(%rip), %rdi     # 0xf0b90
movb $0x0, %al
callq 0x52630
jmp 0x8796a
leaq 0x69251(%rip), %rdi     # 0xf0ba8
movb $0x0, %al
callq 0x52630
movl $0x0, -0x4(%rbp)
jmp 0x87d01
jmp 0x8796c
jmp 0x879c4
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x31, %eax
je 0x879ad
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x70, %eax
je 0x879ad
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x50, %eax
jne 0x879c2
movl $0x1, -0x24(%rbp)
leaq 0x69216(%rip), %rdi     # 0xf0bd1
movb $0x0, %al
callq 0x52630
jmp 0x879c4
jmp 0x879c8
jmp 0x879c8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8772a
movl -0x28(%rbp), %edi
callq 0x86bb0
cmpl $0x0, %eax
jne 0x879fd
leaq 0x69202(%rip), %rdi     # 0xf0bec
movb $0x0, %al
callq 0x52630
movl $0x0, -0x4(%rbp)
jmp 0x87d01
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x87be9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x87a38
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x87a3d
jmp 0x87bdb
cmpl $0x0, -0x24(%rbp)
jne 0x87a5c
cmpl $0x1, -0x1c(%rbp)
jl 0x87a5c
leaq 0x691cb(%rip), %rdi     # 0xf0c1b
movb $0x0, %al
callq 0x52630
jmp 0x87bdb
cmpl $0x10, -0x1c(%rbp)
jl 0x87a86
leaq 0x691f3(%rip), %rdi     # 0xf0c5c
movl $0x10, %esi
movb $0x0, %al
callq 0x52630
callq 0x86b80
movl $0x0, -0x4(%rbp)
jmp 0x87d01
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
je 0x87aae
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x87b21
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x87b21
cmpl $0x0, -0x24(%rbp)
jne 0x87af7
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %esi
leaq 0x691aa(%rip), %rdi     # 0xf0c89
movb $0x0, %al
callq 0x52630
callq 0x86b80
movl $0x0, -0x4(%rbp)
jmp 0x87d01
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movl %eax, 0x71d43c(%rip)    # 0x7a4f44
movl 0x71d436(%rip), %esi    # 0x7a4f44
leaq 0x691a2(%rip), %rdi     # 0xf0cb7
movb $0x0, %al
callq 0x52630
jmp 0x87bdb
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
cmpl $0x1, -0x24(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %edx
leaq -0xa8(%rbp), %rsi
callq 0x87d10
cmpl $0x0, %eax
jne 0x87b75
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x6917d(%rip), %rdi     # 0xf0cda
movb $0x0, %al
callq 0x52630
callq 0x86b80
movl $0x0, -0x4(%rbp)
jmp 0x87d01
movslq -0x1c(%rbp), %rax
leaq 0x71c9f0(%rip), %rdi    # 0x7a4570
shlq $0x7, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
movl $0x80, %edx
callq 0x80e0
movl -0x1c(%rbp), %eax
movl %eax, -0xbc(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x87f90
movl -0xbc(%rbp), %esi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x69135(%rip), %rdi     # 0xf0cfe
movb $0x0, %al
callq 0x52630
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x87bdb
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x87a04
cmpl $0xff, -0x24(%rbp)
jne 0x87c06
cmpl $0x0, -0x1c(%rbp)
je 0x87c06
movl $0x2, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x2, -0x20(%rbp)
jl 0x87c22
cmpl $0x0, -0x1c(%rbp)
je 0x87c22
cmpl $0x0, -0x24(%rbp)
jne 0x87c22
movl $0x1, 0x71d322(%rip)    # 0x7a4f44
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x87c32
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x87c41
cmpl $0x0, -0x20(%rbp)
jne 0x87c3f
movl $0x1, -0x20(%rbp)
jmp 0x87c41
cmpl $0x0, -0x24(%rbp)
jne 0x87c5e
cmpl $0x0, 0x71d2f6(%rip)    # 0x7a4f44
jne 0x87c5e
leaq 0x690c5(%rip), %rdi     # 0xf0d1c
movb $0x0, %al
callq 0x52630
movl -0x24(%rbp), %eax
movl %eax, 0xa4499(%rip)     # 0x12c100
movl -0x20(%rbp), %eax
movl %eax, 0x71d2dc(%rip)    # 0x7a4f4c
movl $0x0, 0x71d2d6(%rip)    # 0x7a4f50
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl 0x71d2c2(%rip), %ecx    # 0x7a4f4c
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x87cb0
movl -0x14(%rbp), %edx
addl $0x1, %edx
movslq -0x14(%rbp), %rcx
leaq 0x71d2be(%rip), %rax    # 0x7a4f60
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x87c81
movl 0x71d296(%rip), %eax    # 0x7a4f4c
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x71d29d(%rip), %rax    # 0x7a4f60
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl $0x0, 0x71d2cc(%rip)    # 0x7a4fa0
cmpl $0x0, -0x24(%rbp)
jne 0x87ce3
cmpl $0x2, 0x71d26b(%rip)    # 0x7a4f4c
jge 0x87cec
cmpl $0x2, 0x71d262(%rip)    # 0x7a4f4c
jne 0x87cf5
movl $0x1, -0x4(%rbp)
jmp 0x87d01
callq 0x86b80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)