// File: huanghuide[P]SimpleNetworkTunnel/Main.cpp
// Function: ParseParamsAndInit(int, char**)
void ParseParamsAndInit(int argc, char *argv[])
{
	int ch;
	opterr = 0;

	// Default setting
	gRoleType = SERVER;
	gInnerListenPort = BB_LISTEN_PORT;

	// Read parameters
	while ((ch = getopt(argc, argv, "r:l:o:")) != EOF)
	{
		switch (ch)
		{
		case 'r': // Role
            gLog.Write("Param (r): %s", optarg);
			if (strcmp(optarg, "client") == 0)
			{
				gRoleType = CLIENT;
			}
            else if (strcmp(optarg, "middle") == 0)
			{
				gRoleType = MIDDLE;
			}
			else
			{
				gRoleType = SERVER;
			}

			break;

		case 'l': // inner listen port
            gLog.Write("Param (l): %s", optarg);
			gInnerListenPort = atoi(optarg);
			break;

		case 'o': // outer dest IP address
            gLog.Write("Param (o): %s", optarg);
            ParseIpPort(optarg);
			break;
		}
	}

	// Init variables
	gInnerInitiator = new InnerInitiator(gInnerListenPort);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x984a(%rip), %rax      # 0xffe0
movl $0x0, (%rax)
leaq 0x9afd(%rip), %rax      # 0x102a0
movl $0x2, (%rax)
leaq 0x9af4(%rip), %rax      # 0x102a4
movl $0x1e61, (%rax)         # imm = 0x1E61
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x4b1b(%rip), %rdx      # 0xb2df
callq 0x30d0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x68f4
movl -0x14(%rbp), %eax
movl %eax, -0x28(%rbp)
subl $0x6c, %eax
je 0x6886
jmp 0x67e6
movl -0x28(%rbp), %eax
subl $0x6f, %eax
je 0x68c1
jmp 0x67f4
movl -0x28(%rbp), %eax
subl $0x72, %eax
jne 0x68ef
jmp 0x6802
movq 0x97c7(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0xb6e5(%rip), %rdi      # 0x11ef8
leaq 0x4acc(%rip), %rsi      # 0xb2e6
movb $0x0, %al
callq 0x63c0
movq 0x97a8(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x4ac2(%rip), %rsi      # 0xb2f4
callq 0x3460
cmpl $0x0, %eax
jne 0x684b
leaq 0x9a5d(%rip), %rax      # 0x102a0
movl $0x0, (%rax)
jmp 0x6884
movq 0x977e(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq 0x4a9f(%rip), %rsi      # 0xb2fb
callq 0x3460
cmpl $0x0, %eax
jne 0x6875
leaq 0x9a33(%rip), %rax      # 0x102a0
movl $0x1, (%rax)
jmp 0x6882
leaq 0x9a24(%rip), %rax      # 0x102a0
movl $0x2, (%rax)
jmp 0x6884
jmp 0x68ef
movq 0x9743(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0xb661(%rip), %rdi      # 0x11ef8
leaq 0x4a64(%rip), %rsi      # 0xb302
movb $0x0, %al
callq 0x63c0
movq 0x9724(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x34a0
movl %eax, %ecx
leaq 0x99e7(%rip), %rax      # 0x102a4
movl %ecx, (%rax)
jmp 0x68ef
movq 0x9708(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0xb626(%rip), %rdi      # 0x11ef8
leaq 0x4a37(%rip), %rsi      # 0xb310
movb $0x0, %al
callq 0x63c0
movq 0x96e9(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x6580
jmp 0x67b6
movl $0x40, %edi
callq 0x3340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x30(%rbp)
leaq 0x9995(%rip), %rax      # 0x102a4
movl (%rax), %esi
callq 0x4700
jmp 0x6918
movq -0x30(%rbp), %rcx
leaq 0xb615(%rip), %rax      # 0x11f38
movq %rcx, (%rax)
addq $0x30, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x40, %esi
callq 0x3360
movq -0x20(%rbp), %rdi
callq 0x34c0
nop