// File: lotuskip[P]yuxtapa/client/client.cpp
// Function: main
int main(int argc, char *argv[])
{
	setlocale(LC_ALL, "");

	string server = "";
	if(argc >= 2) // command line argument should be a server name
	{
		if((server = argv[1]) == "--help" || server == "-h")
		{
			cout << "Flag \'-v\' prints the version. Other than that, any command line"
				<< endl << "argument should be either a server address or a server name"
				<< endl << "defined in the configuration." << endl;
			return 0;
		}
		if(server == "-v" || server == "--version")
		{
			cout << PACKAGE << " client v." << VERSION << endl;
			return 0;
		}
	}
	Config::read_config(server);
	if(!Base::init_ncurses())
		return 1;
	init_msgs();
	// reuse server-string for connection errors:
	if(!Network::connect(server))
	{
		Base::deinit_ncurses();
		cerr << server << endl;
		return 1;
	}
	// If here, we are connected, and 'server' string is unmodified.
	// Print server info, which is constant for the whole session:
	server.insert(0, "Server: ");
	fix_str_to_fit(server);
	Base::print_str(server.c_str(), 7, 0, 3, STAT_WIN, false);
	// an IPv6 address might be too long to fit on one line:
	fix_str_to_fit((server = Config::get_server_ip()));
	Base::print_str(server.c_str(), 7, 0, 4, STAT_WIN, false);
	
	bool server_disconnect = false;
	while(!(server_disconnect = Network::receive_n_handle())
		&& !Input::inputhandle())
		upd_msgs();

	Network::disconnect();
	Base::deinit_ncurses();
	Config::save_msg_memory();
	if(server_disconnect)
		cout << "Server disconnected." << endl;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x10589(%rip), %rsi     # 0x1c489
movq %rsi, -0x60(%rbp)
movl $0x6, %edi
callq 0x5440
leaq -0x31(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x5840
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0xa030
jmp 0xbf2e
leaq -0x31(%rbp), %rdi
callq 0x5540
cmpl $0x2, -0x8(%rbp)
jl 0xc139
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x30(%rbp), %rdi
callq 0x56d0
movq %rax, -0x68(%rbp)
jmp 0xbf58
movq -0x68(%rbp), %rdi
leaq 0x10547(%rip), %rsi     # 0x1c4aa
callq 0xc3b0
movb %al, -0x69(%rbp)
jmp 0xbf6d
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0xbf97
jmp 0xbf76
leaq 0x10534(%rip), %rsi     # 0x1c4b1
leaq -0x30(%rbp), %rdi
callq 0xc3b0
movb %al, -0x6a(%rbp)
jmp 0xbf8b
movb -0x6a(%rbp), %al
testb $0x1, %al
jne 0xbf97
jmp 0xc073
movq 0x1c022(%rip), %rdi     # 0x27fc0
leaq 0x1050f(%rip), %rsi     # 0x1c4b4
callq 0x54b0
movq %rax, -0x78(%rbp)
jmp 0xbfb0
movq -0x78(%rbp), %rdi
movq 0x1bfe5(%rip), %rsi     # 0x27fa0
callq 0x5510
movq %rax, -0x80(%rbp)
jmp 0xbfc6
movq -0x80(%rbp), %rdi
leaq 0x10523(%rip), %rsi     # 0x1c4f4
callq 0x54b0
movq %rax, -0x88(%rbp)
jmp 0xbfdf
movq -0x88(%rbp), %rdi
movq 0x1bfb3(%rip), %rsi     # 0x27fa0
callq 0x5510
movq %rax, -0x90(%rbp)
jmp 0xbffb
movq -0x90(%rbp), %rdi
leaq 0x10527(%rip), %rsi     # 0x1c530
callq 0x54b0
movq %rax, -0x98(%rbp)
jmp 0xc017
movq -0x98(%rbp), %rdi
movq 0x1bf7b(%rip), %rsi     # 0x27fa0
callq 0x5510
jmp 0xc02c
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xc335
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x5540
jmp 0xc34a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5968
jmp 0xc34a
leaq 0x104d4(%rip), %rsi     # 0x1c54e
leaq -0x30(%rbp), %rdi
callq 0xc3b0
movb %al, -0x99(%rbp)
jmp 0xc08b
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0xc0bb
jmp 0xc097
leaq 0x104b3(%rip), %rsi     # 0x1c551
leaq -0x30(%rbp), %rdi
callq 0xc3b0
movb %al, -0x9a(%rbp)
jmp 0xc0af
movb -0x9a(%rbp), %al
testb $0x1, %al
jne 0xc0bb
jmp 0xc137
movq 0x1befe(%rip), %rdi     # 0x27fc0
leaq 0x10492(%rip), %rsi     # 0x1c55b
callq 0x54b0
movq %rax, -0xa8(%rbp)
jmp 0xc0d7
movq -0xa8(%rbp), %rdi
leaq 0x1047e(%rip), %rsi     # 0x1c563
callq 0x54b0
movq %rax, -0xb0(%rbp)
jmp 0xc0f3
movq -0xb0(%rbp), %rdi
leaq 0x1046d(%rip), %rsi     # 0x1c56e
callq 0x54b0
movq %rax, -0xb8(%rbp)
jmp 0xc10f
movq -0xb8(%rbp), %rdi
movq 0x1be83(%rip), %rsi     # 0x27fa0
callq 0x5510
jmp 0xc124
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xc335
jmp 0xc139
leaq -0x30(%rbp), %rdi
callq 0x148a0
jmp 0xc144
callq 0x8c70
movb %al, -0xb9(%rbp)
jmp 0xc151
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0xc170
jmp 0xc15d
movl $0x1, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xc335
callq 0xe150
jmp 0xc177
leaq -0x30(%rbp), %rdi
callq 0x12c10
movb %al, -0xba(%rbp)
jmp 0xc188
movb -0xba(%rbp), %al
testb $0x1, %al
jne 0xc1dc
jmp 0xc194
callq 0x93a0
jmp 0xc19b
movq 0x1be46(%rip), %rdi     # 0x27fe8
leaq -0x30(%rbp), %rsi
callq 0x5430
movq %rax, -0xc8(%rbp)
jmp 0xc1b4
movq -0xc8(%rbp), %rdi
movq 0x1bdde(%rip), %rsi     # 0x27fa0
callq 0x5510
jmp 0xc1c9
movl $0x1, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xc335
leaq 0x1038e(%rip), %rdx     # 0x1c571
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x5140
jmp 0xc1f2
leaq -0x30(%rbp), %rdi
callq 0xc360
jmp 0xc1fd
leaq -0x30(%rbp), %rdi
callq 0x5200
movq %rax, %rdi
movl $0x7, %esi
movl $0x3, %ecx
xorl %r9d, %r9d
movl %r9d, %edx
movl %r9d, %r8d
callq 0x9480
jmp 0xc223
callq 0x16150
movq %rax, -0xd0(%rbp)
jmp 0xc231
movq -0xd0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x5060
movq %rax, -0xd8(%rbp)
jmp 0xc24a
movq -0xd8(%rbp), %rdi
callq 0xc360
jmp 0xc258
leaq -0x30(%rbp), %rdi
callq 0x5200
movq %rax, %rdi
movl $0x7, %esi
movl $0x4, %ecx
xorl %r9d, %r9d
movl %r9d, %edx
movl %r9d, %r8d
callq 0x9480
jmp 0xc27e
movb $0x0, -0x49(%rbp)
callq 0x13cd0
movb %al, -0xd9(%rbp)
jmp 0xc28f
movb -0xd9(%rbp), %cl
movb %cl, %al
andb $0x1, %al
movb %al, -0x49(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xda(%rbp)
jne 0xc2c4
callq 0xc3e0
movb %al, -0xdb(%rbp)
jmp 0xc2b6
movb -0xdb(%rbp), %al
xorb $-0x1, %al
movb %al, -0xda(%rbp)
movb -0xda(%rbp), %al
testb $0x1, %al
jne 0xc2d0
jmp 0xc2d9
callq 0xe7a0
jmp 0xc2d7
jmp 0xc282
callq 0x13c70
jmp 0xc2e0
callq 0x93a0
jmp 0xc2e7
callq 0x15ef0
jmp 0xc2ee
testb $0x1, -0x49(%rbp)
je 0xc327
movq 0x1bcc5(%rip), %rdi     # 0x27fc0
leaq 0x10278(%rip), %rsi     # 0x1c57a
callq 0x54b0
movq %rax, -0xe8(%rbp)
jmp 0xc310
movq -0xe8(%rbp), %rdi
movq 0x1bc82(%rip), %rsi     # 0x27fa0
callq 0x5510
jmp 0xc325
jmp 0xc327
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5968
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x5830
nopw %cs:(%rax,%rax)