// File: /workspace/github_cpp_makefile_star2_O2/lotka[P]prologplusplus/predicate.cpp
// Function: Predicate::Predicate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<Predicate*, std::allocator<Predicate*>>&)
Predicate::Predicate(string s, vector<Predicate *> &predicates)
{
	s = strip_ws(s);
	// Count up to ":-"
	// commas
	int commas 	= 0;
	// left brackets
	int lb 		= 0;
	// right brackets
	int rb	    = 0;
	// conditionals
	int cond 	= 0;
	// dots
	int dot 	= 0;
	for(int i = 0; i < s.size(); ++i)
	{
		if(s[i] == ':')
		{
			if(s[i+1]=='-')
			{
				break;
			}
			else
			{
				cout << "Error: : followed by " << s[i+1] << endl;
				return;
			}
			cond = i + 2;
		}
		switch(s[i])
		{
			case ',':
				++commas;
				break;

			case '(':
				++lb;
				break;

			case ')':
				++rb;
				break;

			case '.':
				++dot;
				break;
		}
	}
	if(lb > 0)
	{
		name = cropString(s,'(');
	}
	else if(dot > 0)
	{
		name = cropString(s,'.');
	}
	else if(cond > 0)
	{
		name = cropString(s,':');
	}

	airty = commas + lb;

	// Add the airty to the name
	name = name + "\\0";
	name[name.size()-1] = '0'+airty;

	vector<string> raw_args;
	vector<string> raw_conditions;
	// Do the processing
	for(int i = 0; i < airty; ++i)
	{
		char delimiter;
		if(i != commas)
		{
			delimiter = ',';
		}
		else
		{
			delimiter = ')';
		}
		raw_args.push_back(cropString(s,delimiter));
	}
	cropString(s,'-');

	// cout << "name : " << name << endl;
	// cout << "Arguments : ";
 //  	for (unsigned int i = 0; i < raw_args.size(); ++i)
	// {
	// 	cout << raw_args[i] << ' ';
	// }
	if(s.size()>0)
	{
		for(int i = 0; i < s.size(); ++i)
		{
			if(s[i]==')' and s[i+1]==',')
			{
				raw_conditions.push_back(cropString(s,i+1));
				connectives.push_back(AND);
			}
			else if(s[i]==')' and s[i+1]==';')
			{
				raw_conditions.push_back(cropString(s,';'));
				connectives.push_back(OR);
			}
			else if(s[i]=='-' and s[i+1]=='>')
			{
				raw_conditions.push_back(cropString(s,'-'));
				cropString(s,'>');
				connectives.push_back(IMPLIES);
			}
			else if(s[i] == ')' and s[i+1] == '.')
			{
				raw_conditions.push_back(cropString(s,'.'));
				connectives.push_back(END);
				break;
			}
			else if(s[i] == '.')
			{
				raw_conditions.push_back(cropString(s,'.'));
				connectives.push_back(END);
				break;
			}
		}
	// 	cout << endl << "Conditions : ";
	//   	for (unsigned int i = 0; i < raw_conditions.size(); ++i)
	// 	{
	// 		cout << raw_conditions[i];
	// 		if(connectives[i] == AND)
	// 		{
	// 			cout << " and ";
	// 		}
	// 	}
	}
	// cout << endl;

	// Parsing finished.

	for(int i = 0; i < raw_args.size(); ++i)
	{
		Atom * a = new Atom(raw_args[i]);
		args.push_back(a);
	}

	for(int i = 0; i < raw_conditions.size(); ++i)
	{
		conditions.push_back(new PredicateRef(raw_conditions[i],predicates));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, -0x88(%rbp)
movq %rsi, %r12
movq %rdi, %r15
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
leaq 0x28(%rdi), %rax
movq %rax, -0x80(%rbp)
leaq 0x40(%rdi), %rax
movq %rax, -0x78(%rbp)
leaq 0x58(%rdi), %rax
movq %rax, -0x58(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x38(%rdi)
movups %xmm0, 0x48(%rdi)
movups %xmm0, 0x58(%rdi)
andq $0x0, 0x68(%rdi)
leaq -0xc0(%rbp), %rdi
callq 0x21d0
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2f19
leaq -0x50(%rbp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x20a0
leaq -0xc0(%rbp), %rdi
callq 0x20a0
xorl %r13d, %r13d
movq 0x8(%r12), %rax
xorl %edx, %edx
subq %rax, %rdx
pushq $0x1
popq %rcx
leaq 0x1d5d(%rip), %rsi      # 0x50f4
xorl %r14d, %r14d
xorl %eax, %eax
leaq (%rdx,%rcx), %rdi
cmpq $0x1, %rdi
je 0x33e7
movq (%r12), %rdi
movb -0x1(%rdi,%rcx), %r8b
addb $-0x28, %r8b
rorb %r8b
cmpb $0x9, %r8b
ja 0x33d6
movzbl %r8b, %r8d
movslq (%rsi,%r8,4), %r8
addq %rsi, %r8
jmpq *%r8
incl %r14d
jmp 0x33d6
incl %eax
jmp 0x33d6
incl %r13d
incq %rcx
jmp 0x339c
movl %ecx, %ebx
cmpb $0x2d, (%rdi,%rbx)
jne 0x3659
testl %r14d, %r14d
jle 0x33fd
leaq -0x50(%rbp), %rdi
pushq $0x28
popq %rdx
movq %r12, %rsi
callq 0x2e44
jmp 0x3410
testl %eax, %eax
jle 0x3427
leaq -0x50(%rbp), %rdi
pushq $0x2e
popq %rdx
movq %r12, %rsi
callq 0x2e44
leaq -0x50(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x20a0
addl %r13d, %r14d
movl %r14d, 0x20(%r15)
leaq 0x1ce7(%rip), %rdx      # 0x511c
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x390a
leaq -0x50(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x2190
movq %r14, %rdi
callq 0x20a0
movb 0x20(%r15), %al
addb $0x30, %al
movq (%r15), %rcx
movq %r15, -0x30(%rbp)
movq 0x8(%r15), %rdx
movb %al, -0x1(%rcx,%rdx)
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movaps %xmm0, -0x70(%rbp)
andq $0x0, -0x60(%rbp)
xorl %ebx, %ebx
movq -0x30(%rbp), %rax
cmpl 0x20(%rax), %ebx
jge 0x34c4
xorl %eax, %eax
cmpl %ebx, %r13d
setne %al
leal (%rax,%rax,2), %edx
addl $0x29, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e44
movq %r15, %rdi
movq %r14, %rsi
callq 0x3b3e
movq %r14, %rdi
callq 0x20a0
incl %ebx
jmp 0x348b
leaq -0x120(%rbp), %rdi
pushq $0x2d
popq %rdx
movq %r12, %rsi
callq 0x2e44
leaq -0x120(%rbp), %rdi
callq 0x20a0
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x36c4
pushq $0x1
popq %r14
leaq -0x50(%rbp), %r15
leaq -0x70(%rbp), %rbx
leaq -0x1(%r14), %rcx
cmpq %rcx, %rax
jbe 0x36c4
movq (%r12), %rax
movzbl -0x1(%rax,%r14), %ecx
cmpl $0x29, %ecx
je 0x358c
cmpl $0x2d, %ecx
je 0x352b
cmpl $0x2e, %ecx
jne 0x360f
jmp 0x361c
cmpb $0x3e, (%rax,%r14)
jne 0x360f
movq %r15, %rdi
movq %r12, %rsi
pushq $0x2d
popq %rdx
callq 0x2e44
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b3e
movq %r15, %rdi
callq 0x20a0
leaq -0x140(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
pushq $0x3e
popq %rdx
callq 0x2e44
movq %r13, %rdi
callq 0x20a0
movl $0x3, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x3d2e
jmp 0x360f
movzbl (%rax,%r14), %eax
cmpl $0x2c, %eax
je 0x35db
cmpl $0x3b, %eax
je 0x35a5
cmpl $0x2e, %eax
jne 0x360f
jmp 0x3689
movq %r15, %rdi
movq %r12, %rsi
pushq $0x3b
popq %rdx
callq 0x2e44
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b3e
movq %r15, %rdi
callq 0x20a0
movl $0x2, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x3d2e
jmp 0x360f
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x2dcc
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b3e
movq %r15, %rdi
callq 0x20a0
movl $0x1, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x3d2e
movq 0x8(%r12), %rax
incq %r14
jmp 0x34fc
leaq -0x50(%rbp), %rdi
pushq $0x2e
popq %rdx
movq %r12, %rsi
callq 0x2e44
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3b3e
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x20a0
movl $0x4, (%rbx)
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x3d2e
jmp 0x36c4
movq 0x4970(%rip), %rdi      # 0x7fd0
leaq 0x1acb(%rip), %rsi      # 0x5132
callq 0x2140
movq (%r12), %rcx
movsbl (%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
jmp 0x37b8
leaq -0x50(%rbp), %rdi
pushq $0x2e
popq %rdx
movq %r12, %rsi
callq 0x2e44
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3b3e
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x20a0
movl $0x4, (%rbx)
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x3d2e
xorl %r14d, %r14d
leaq -0x100(%rbp), %r15
xorl %r12d, %r12d
movq -0xa0(%rbp), %rbx
movq -0x98(%rbp), %rax
subq %rbx, %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x3731
pushq $0x40
popq %rdi
callq 0x2150
movq %rax, %r13
addq %r14, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %r13, %rdi
movq %r15, %rsi
callq 0x2ab8
movq %r15, %rdi
callq 0x20a0
movq %r13, -0x50(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3942
incq %r12
addq $0x20, %r14
jmp 0x36d1
xorl %r14d, %r14d
leaq -0xe0(%rbp), %r15
xorl %r12d, %r12d
movq -0x70(%rbp), %rbx
movq -0x68(%rbp), %rax
subq %rbx, %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x37a3
pushq $0x40
popq %rdi
callq 0x2150
movq %rax, %r13
addq %r14, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21d0
movb $0x1, %bl
movq %r13, %rdi
movq %r15, %rsi
movq -0x88(%rbp), %rdx
callq 0x2f80
movq %r13, -0x50(%rbp)
xorl %ebx, %ebx
movq -0x78(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3ec6
movq %r15, %rdi
callq 0x20a0
incq %r12
addq $0x20, %r14
jmp 0x373e
leaq -0x70(%rbp), %rdi
callq 0x3966
leaq -0xa0(%rbp), %rdi
callq 0x3966
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x385d
jmp 0x382d
jmp 0x385d
jmp 0x385d
jmp 0x382d
jmp 0x385d
jmp 0x37fa
jmp 0x37fa
jmp 0x37fa
jmp 0x385d
jmp 0x37fa
movq %rax, %r12
leaq -0xc0(%rbp), %rdi
callq 0x20a0
jmp 0x3879
movq %rax, %r12
jmp 0x3879
jmp 0x385d
jmp 0x382d
jmp 0x385d
jmp 0x385d
jmp 0x382d
jmp 0x385d
jmp 0x385d
jmp 0x385d
jmp 0x382d
jmp 0x385d
jmp 0x385d
jmp 0x3817
movq %rax, %r12
jmp 0x3850
movq %rax, %r12
leaq -0x100(%rbp), %rdi
callq 0x20a0
jmp 0x3850
movq %rax, %r12
leaq -0x50(%rbp), %rdi
callq 0x20a0
jmp 0x3860
jmp 0x385d
movq %rax, %r12
leaq -0xe0(%rbp), %rdi
callq 0x20a0
testb %bl, %bl
je 0x3860
pushq $0x40
popq %rsi
movq %r13, %rdi
callq 0x2160
jmp 0x3860
movq %rax, %r12
movq -0x30(%rbp), %r15
leaq -0x70(%rbp), %rdi
callq 0x3966
leaq -0xa0(%rbp), %rdi
callq 0x3966
movq -0x58(%rbp), %rdi
callq 0x3a9c
movq -0x78(%rbp), %rdi
callq 0x3a5e
movq -0x80(%rbp), %rdi
callq 0x2800
movq %r15, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x2200