// File: wekan[P]sps/sps.cxx
// Function: main
int main (int argc, char * argv[])
{
	if (argc < 3)
	{
		use();
		return EX_USAGE; // 64
	}
	
	std::string host = argv[1];
	std::map<std::string, bool> target_list;
	for (int i = 2 ; i < argc ; i++)
		target_list[argv[i]] = true;

	std::ios_base::sync_with_stdio(false);
	if (std::cin.rdbuf()->in_avail() <= 0)
	{
		std::cerr << "No data on standard input" << std::endl;
		return EX_NOINPUT; // 65
	}

	std::string line, section, exec_cmd;
	char * str = nullptr;
	int len = 0;
	int exit_code = 0;
	bool exec_remote = true;
	bool in_section = false;
	bool in_exec = false;
	
	auto check_section = [&]() -> void
	{
		section = line.substr(2, len - 2);
		if (target_list.find(section) != target_list.end())
			in_section = true;
	};
	
	while (!std::cin.eof() && exit_code == 0)
	{
		getline(std::cin, line);
		str = (char*) line.c_str();
		len = line.length();

		if (!in_section)
		{
			if (strncmp(str, "# ", 2) == 0)
				check_section();
		}
		else
		{
			if (!in_exec)
			{
				if (strncmp(str, "# ", 2) == 0)
				{
					in_section = false;
					in_exec = false;
					exec_remote = true;
					check_section();
				}

				if (strncmp(str, "* GET", 5) == 0)
				{
					if (len > 6)
						exit_code = get_transfert(host, str + 6);
				}
				if (strncmp(str, "* PUT", 5) == 0)
				{
					if (len > 6)
						exit_code = put_transfert(host, str + 6);
				}
				if (strncmp(str, "* REMOTE_EXECUTION", 18) == 0)
					exec_remote = true;
				if (strncmp(str, "* LOCAL_EXECUTION", 17) == 0)
					exec_remote = false;

				if (strncmp(str, "```", 3) == 0)
				{
					in_exec = true;
					exec_cmd = "";
				}
			}
			else
			{
				if (strncmp(str, "```", 3) == 0)
				{
					in_exec = false;
					exit_code = exec_remote ? remote_execution(host, exec_cmd) : local_execution(exec_cmd);
				}
				else
				{
					exec_cmd += line + "\n";
				}
			}
		}
	}
	
	return exit_code;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x4210
callq 0x35f0
movl $0x40, -0x4(%rbp)
jmp 0x49c7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x208(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x33a0
movq -0x208(%rbp), %rsi
movq -0x200(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x4a80
jmp 0x4248
leaq -0x31(%rbp), %rdi
callq 0x32a0
leaq -0x78(%rbp), %rdi
callq 0x5050
movl $0x2, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x4349
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x218(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x33a0
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x4a80
jmp 0x42af
leaq -0x78(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x5070
movq %rax, -0x220(%rbp)
jmp 0x42c8
movq -0x220(%rbp), %rax
movb $0x1, (%rax)
leaq -0xa0(%rbp), %rdi
callq 0x3438
leaq -0xa1(%rbp), %rdi
callq 0x32a0
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x4261
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x32a0
jmp 0x49d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4338
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3438
leaq -0xa1(%rbp), %rdi
callq 0x32a0
jmp 0x49b3
xorl %edi, %edi
callq 0x3100
jmp 0x4352
movq 0x7c7f(%rip), %rdi      # 0xbfd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3130
movq %rax, -0x228(%rbp)
jmp 0x4371
movq -0x228(%rbp), %rdi
callq 0x33c0
movq %rax, -0x230(%rbp)
jmp 0x4386
movq -0x230(%rbp), %rax
cmpq $0x0, %rax
jg 0x43eb
movq 0x7c56(%rip), %rdi      # 0xbff0
leaq 0x3dde(%rip), %rsi      # 0x817f
callq 0x3230
movq %rax, -0x238(%rbp)
jmp 0x43af
movq -0x238(%rbp), %rdi
movq 0x7bf3(%rip), %rsi      # 0xbfb0
callq 0x3280
jmp 0x43c4
movl $0x42, -0x4(%rbp)
movl $0x1, -0xa8(%rbp)
jmp 0x499f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x49b3
leaq -0xc8(%rbp), %rdi
callq 0x3310
leaq -0xe8(%rbp), %rdi
callq 0x3310
leaq -0x108(%rbp), %rdi
callq 0x3310
movq $0x0, -0x110(%rbp)
movl $0x0, -0x114(%rbp)
movl $0x0, -0x118(%rbp)
movb $0x1, -0x119(%rbp)
movb $0x0, -0x11a(%rbp)
movb $0x0, -0x11b(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x114(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x11a(%rbp), %rax
movq %rax, -0x128(%rbp)
movq 0x7b4b(%rip), %rdi      # 0xbfd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x33d0
movb %al, -0x239(%rbp)
jmp 0x44a4
movb -0x239(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x23a(%rbp)
jne 0x44c9
jmp 0x44b9
cmpl $0x0, -0x118(%rbp)
sete %al
movb %al, -0x23a(%rbp)
movb -0x23a(%rbp), %al
testb $0x1, %al
jne 0x44d8
jmp 0x4940
movq 0x7af9(%rip), %rdi      # 0xbfd8
leaq -0xc8(%rbp), %rsi
callq 0x3070
jmp 0x44ed
leaq -0xc8(%rbp), %rdi
callq 0x30f0
movq %rax, -0x110(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3330
movl %eax, -0x114(%rbp)
testb $0x1, -0x11a(%rbp)
jne 0x455e
movq -0x110(%rbp), %rdi
leaq 0x3c70(%rip), %rsi      # 0x8199
movl $0x2, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x4559
leaq -0x148(%rbp), %rdi
callq 0x49e0
jmp 0x4546
jmp 0x4559
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4979
jmp 0x493b
testb $0x1, -0x11b(%rbp)
jne 0x485b
movq -0x110(%rbp), %rdi
leaq 0x3c20(%rip), %rsi      # 0x8199
movl $0x2, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x45ad
movb $0x0, -0x11a(%rbp)
movb $0x0, -0x11b(%rbp)
movb $0x1, -0x119(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x49e0
jmp 0x45ab
jmp 0x45ad
movq -0x110(%rbp), %rdi
leaq 0x3be1(%rip), %rsi      # 0x819c
movl $0x5, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x46c0
cmpl $0x6, -0x114(%rbp)
jle 0x46be
leaq -0x168(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3110
jmp 0x45ed
movq -0x110(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x250(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x33a0
movq -0x250(%rbp), %rsi
movq -0x248(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0x4a80
jmp 0x462e
leaq -0x168(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x3bc0
movl %eax, -0x254(%rbp)
jmp 0x4649
movl -0x254(%rbp), %eax
movl %eax, -0x118(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x3438
leaq -0x189(%rbp), %rdi
callq 0x32a0
leaq -0x168(%rbp), %rdi
callq 0x3438
jmp 0x46be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x46a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x3438
leaq -0x189(%rbp), %rdi
callq 0x32a0
leaq -0x168(%rbp), %rdi
callq 0x3438
jmp 0x4979
jmp 0x46c0
movq -0x110(%rbp), %rdi
leaq 0x3ad4(%rip), %rsi      # 0x81a2
movl $0x5, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x47d3
cmpl $0x6, -0x114(%rbp)
jle 0x47d1
leaq -0x1b0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3110
jmp 0x4700
movq -0x110(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x268(%rbp)
leaq -0x1d1(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x33a0
movq -0x268(%rbp), %rsi
movq -0x260(%rbp), %rdx
leaq -0x1d0(%rbp), %rdi
callq 0x4a80
jmp 0x4741
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x3ed0
movl %eax, -0x26c(%rbp)
jmp 0x475c
movl -0x26c(%rbp), %eax
movl %eax, -0x118(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3438
leaq -0x1d1(%rbp), %rdi
callq 0x32a0
leaq -0x1b0(%rbp), %rdi
callq 0x3438
jmp 0x47d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x47b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3438
leaq -0x1d1(%rbp), %rdi
callq 0x32a0
leaq -0x1b0(%rbp), %rdi
callq 0x3438
jmp 0x4979
jmp 0x47d3
movq -0x110(%rbp), %rdi
leaq 0x39c7(%rip), %rsi      # 0x81a8
movl $0x12, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x47f7
movb $0x1, -0x119(%rbp)
movq -0x110(%rbp), %rdi
leaq 0x39b6(%rip), %rsi      # 0x81bb
movl $0x11, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x481b
movb $0x0, -0x119(%rbp)
movq -0x110(%rbp), %rdi
leaq 0x39a4(%rip), %rsi      # 0x81cd
movl $0x3, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x4856
movb $0x1, -0x11b(%rbp)
leaq 0x38f6(%rip), %rsi      # 0x813c
leaq -0x108(%rbp), %rdi
callq 0x3300
jmp 0x4854
jmp 0x4856
jmp 0x4939
movq -0x110(%rbp), %rdi
leaq 0x3964(%rip), %rsi      # 0x81cd
movl $0x3, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0x48de
movb $0x0, -0x11b(%rbp)
testb $0x1, -0x119(%rbp)
je 0x48ae
leaq -0x30(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3880
movl %eax, -0x270(%rbp)
jmp 0x48a0
movl -0x270(%rbp), %eax
movl %eax, -0x274(%rbp)
jmp 0x48d0
leaq -0x108(%rbp), %rdi
callq 0x3b90
movl %eax, -0x278(%rbp)
jmp 0x48c2
movl -0x278(%rbp), %eax
movl %eax, -0x274(%rbp)
jmp 0x48d0
movl -0x274(%rbp), %eax
movl %eax, -0x118(%rbp)
jmp 0x4937
leaq 0x3856(%rip), %rdx      # 0x813b
leaq -0x1f8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x5150
jmp 0x48fa
leaq -0x108(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x32f0
jmp 0x490f
leaq -0x1f8(%rbp), %rdi
callq 0x3438
jmp 0x4937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x3438
jmp 0x4979
jmp 0x4939
jmp 0x493b
jmp 0x4486
movl -0x118(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0xa8(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3438
leaq -0xe8(%rbp), %rdi
callq 0x3438
leaq -0xc8(%rbp), %rdi
callq 0x3438
jmp 0x499f
leaq -0x108(%rbp), %rdi
callq 0x3438
leaq -0xe8(%rbp), %rdi
callq 0x3438
leaq -0xc8(%rbp), %rdi
callq 0x3438
jmp 0x49b3
leaq -0x78(%rbp), %rdi
callq 0x51d0
leaq -0x30(%rbp), %rdi
callq 0x3438
jmp 0x49c7
leaq -0x78(%rbp), %rdi
callq 0x51d0
leaq -0x30(%rbp), %rdi
callq 0x3438
jmp 0x49d3
movl -0x4(%rbp), %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3390
nopl (%rax)