// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdx, -0xf8(%rbp)
movq %rsi, %r12
leaq 0x10(%rdi), %r15
movq %r15, (%rdi)
xorl %eax, %eax
movq %rax, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
leaq 0x28(%rdi), %rcx
movq %rcx, -0xa8(%rbp)
leaq 0x40(%rdi), %rcx
movq %rcx, -0xb0(%rbp)
leaq 0x58(%rdi), %rcx
movq %rcx, -0x60(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x38(%rdi)
movups %xmm0, 0x48(%rdi)
movups %xmm0, 0x58(%rdi)
movq %rdi, -0x58(%rbp)
movq %rax, 0x68(%rdi)
leaq -0x108(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsi), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %rdi
callq 0x2b40
leaq -0x50(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x32ed
leaq -0x50(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3a29
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3a44
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2130
movq %r15, -0x30(%rbp)
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0x3ac1
movq (%r12), %rcx
negq %rdx
xorl %eax, %eax
movl $0x1, %esi
leaq 0x168d(%rip), %rdi      # 0x50f4
xorl %r15d, %r15d
xorl %r13d, %r13d
movb -0x1(%rcx,%rsi), %r8b
addb $-0x28, %r8b
rorb %r8b
cmpb $0x9, %r8b
ja 0x3a99
movzbl %r8b, %r8d
movslq (%rdi,%r8,4), %r8
addq %rdi, %r8
jmpq *%r8
incl %r15d
jmp 0x3a99
incl %eax
jmp 0x3a99
incl %r13d
leaq (%rdx,%rsi), %r8
incq %r8
incq %rsi
cmpq $0x1, %r8
jne 0x3a6d
testl %r15d, %r15d
jle 0x3ac9
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x28, %edx
callq 0x31e7
jmp 0x3ade
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x3b06
testl %eax, %eax
jle 0x3b06
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e7
leaq -0x50(%rbp), %r14
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3b06
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
addl %r13d, %r15d
movq -0x58(%rbp), %rax
movl %r15d, 0x20(%rax)
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rcx
movq %rcx, (%rdi)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x2b40
leaq 0x15ea(%rip), %rsi      # 0x511c
leaq -0x50(%rbp), %rdi
callq 0x21f0
leaq -0x50(%rbp), %r14
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3b63
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movq -0x58(%rbp), %rsi
movb 0x20(%rsi), %al
addb $0x30, %al
movq (%rsi), %rcx
movq 0x8(%rsi), %rdx
movb %al, -0x1(%rcx,%rdx)
xorl %ebx, %ebx
movq %rbx, -0x90(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xa0(%rbp)
movq %rbx, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
cmpl $0x0, 0x20(%rsi)
jle 0x3be7
leaq -0xa0(%rbp), %r15
xorl %eax, %eax
cmpl %ebx, %r13d
setne %al
leal (%rax,%rax,2), %edx
addl $0x29, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x31e7
movq %r15, %rdi
movq %r14, %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3bdc
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
incl %ebx
movq -0x58(%rbp), %rax
cmpl 0x20(%rax), %ebx
jl 0x3b9f
leaq -0x158(%rbp), %rdi
movq %r12, %rsi
movl $0x2d, %edx
callq 0x31e7
leaq -0x148(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c1a
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x2130
cmpq $0x0, 0x8(%r12)
je 0x3f28
leaq -0x128(%rbp), %r13
movl $0x1, %r14d
leaq -0x50(%rbp), %r15
leaq -0x80(%rbp), %rbx
movq (%r12), %rax
movzbl -0x1(%rax,%r14), %ecx
cmpl $0x29, %ecx
je 0x3cf3
cmpl $0x2d, %ecx
je 0x3c61
cmpl $0x2e, %ecx
jne 0x3de0
jmp 0x3df7
cmpb $0x3e, (%rax,%r14)
jne 0x3de0
movq %r15, %rdi
movq %r12, %rsi
movl $0x2d, %edx
callq 0x31e7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3ca0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0x138(%rbp), %rdi
movq %r12, %rsi
movl $0x3e, %edx
callq 0x31e7
movq -0x138(%rbp), %rdi
cmpq %r13, %rdi
je 0x3ccf
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x3, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x60(%rax), %rsi
cmpq 0x68(%rax), %rsi
je 0x3db8
movl $0x3, (%rsi)
jmp 0x3dae
movzbl (%rax,%r14), %eax
cmpl $0x2c, %eax
je 0x3d61
cmpl $0x3b, %eax
je 0x3d10
cmpl $0x2e, %eax
jne 0x3de0
jmp 0x3eca
movq %r15, %rdi
movq %r12, %rsi
movl $0x3b, %edx
callq 0x31e7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3d44
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x2, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x60(%rax), %rsi
cmpq 0x68(%rax), %rsi
je 0x3dc6
movl $0x2, (%rsi)
jmp 0x3dae
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x3144
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3d93
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x1, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x60(%rax), %rsi
cmpq 0x68(%rax), %rsi
je 0x3dd4
movl $0x1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rax)
jmp 0x3de0
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x46ea
jmp 0x3de0
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x46ea
jmp 0x3de0
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x46ea
leaq 0x1(%r14), %rax
cmpq %r14, 0x8(%r12)
movq %rax, %r14
ja 0x3c3b
jmp 0x3f28
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e7
leaq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3e2e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x4, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x60(%rax), %rsi
cmpq 0x68(%rax), %rsi
jne 0x3f1a
leaq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rdi
callq 0x46ea
jmp 0x3f28
movl %esi, %ebx
cmpb $0x2d, (%rcx,%rbx)
je 0x3aa9
movq 0x3164(%rip), %rdi      # 0x6fd0
leaq 0x12bf(%rip), %rsi      # 0x5132
movl $0x15, %edx
callq 0x2150
movq (%r12), %rax
movb (%rax,%rbx), %al
leaq -0x50(%rbp), %rsi
movb %al, (%rsi)
movq 0x313f(%rip), %rdi      # 0x6fd0
movl $0x1, %edx
callq 0x2150
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
jmp 0x40c8
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e7
leaq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4464
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3f01
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x4, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x60(%rax), %rsi
cmpq 0x68(%rax), %rsi
je 0x40da
movl $0x4, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rax)
movq -0xa0(%rbp), %r13
cmpq %r13, -0x98(%rbp)
je 0x3ff9
movl $0x8, %r15d
xorl %ebx, %ebx
leaq -0xf0(%rbp), %r14
movl $0x40, %edi
callq 0x2120
movq %rax, %r12
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%r13,%r15), %rsi
movq (%r13,%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x2b40
movq %r12, %rdi
movq %r14, %rsi
callq 0x2e00
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x3fa8
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2130
movq %r12, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rsi
cmpq 0x38(%rax), %rsi
je 0x3fc4
movq %r12, (%rsi)
addq $0x8, 0x30(%rax)
jmp 0x3fd4
movq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x4388
incq %rbx
movq -0xa0(%rbp), %r13
movq -0x98(%rbp), %rax
subq %r13, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rbx, %rax
ja 0x3f4b
movq -0x80(%rbp), %r13
cmpq %r13, -0x78(%rbp)
je 0x40b3
movl $0x8, %ebx
xorl %r15d, %r15d
leaq -0xd0(%rbp), %r14
movl $0x40, %edi
callq 0x2120
movq %rax, %r12
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%r13,%rbx), %rsi
movq (%r13,%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x2b40
movb $0x1, %r13b
movq %r12, %rdi
movq %r14, %rsi
movq -0xf8(%rbp), %rdx
callq 0x336c
movq %r12, -0x50(%rbp)
xorl %r13d, %r13d
movq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x482a
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x4094
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2130
incq %r15
movq -0x80(%rbp), %r13
movq -0x78(%rbp), %rax
subq %r13, %rax
sarq $0x5, %rax
addq $0x20, %rbx
cmpq %r15, %rax
ja 0x4016
leaq -0x80(%rbp), %rdi
callq 0x431a
leaq -0xa0(%rbp), %rdi
callq 0x431a
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rdi
callq 0x46ea
jmp 0x3f28
jmp 0x41d2
jmp 0x41b9
jmp 0x41d2
jmp 0x41d2
jmp 0x4142
jmp 0x41b9
jmp 0x41d2
jmp 0x4142
jmp 0x4142
jmp 0x41d2
jmp 0x41d2
jmp 0x41d2
jmp 0x41d2
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4145
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4145
movq %rax, %r14
movq -0x30(%rbp), %rbx
jmp 0x4227
movq %rax, %r14
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4171
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4171
movq %rax, %r14
movq %r15, %rbx
jmp 0x4227
jmp 0x41b9
jmp 0x41d2
jmp 0x41b9
jmp 0x41d2
jmp 0x41d2
jmp 0x41b9
jmp 0x41d2
jmp 0x41d2
jmp 0x418b
movq %rax, %r14
jmp 0x4201
movq %rax, %r14
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x4201
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4201
jmp 0x41d2
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x420e
movq -0x40(%rbp), %rsi
incq %rsi
jmp 0x4209
movq %rax, %r14
jmp 0x420e
movq %rax, %r14
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x41fc
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2130
testb %r13b, %r13b
je 0x420e
movl $0x40, %esi
movq %r12, %rdi
callq 0x2130
movq -0x30(%rbp), %rbx
leaq -0x80(%rbp), %rdi
callq 0x431a
leaq -0xa0(%rbp), %rdi
callq 0x431a
movq -0x60(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4243
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0xb0(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4262
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0xa8(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4281
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0x58(%rbp), %rax
movq (%rax), %rdi
cmpq %rbx, %rdi
je 0x4298
movq (%rbx), %rsi
incq %rsi
callq 0x2130
movq %r14, %rdi
callq 0x21d0