// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b54
leaq -0x50(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x32e9
leaq -0x50(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3a1f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3a3a
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2130
movq %r15, -0x30(%rbp)
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0x3aa1
movq (%r12), %rcx
negq %rdx
xorl %eax, %eax
movl $0x1, %esi
leaq 0x1697(%rip), %rdi      # 0x50f4
xorl %r15d, %r15d
xorl %r13d, %r13d
movb -0x1(%rcx,%rsi), %r8b
addb $-0x28, %r8b
rorb %r8b
cmpb $0x9, %r8b
ja 0x3a8f
movzbl %r8b, %r8d
movslq (%rdi,%r8,4), %r8
addq %rdi, %r8
jmpq *%r8
incl %r15d
jmp 0x3a8f
incl %eax
jmp 0x3a8f
incl %r13d
leaq (%rdx,%rsi), %r8
incq %r8
incq %rsi
cmpq $0x1, %r8
jne 0x3a63
jmp 0x3aa9
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %eax, %eax
testl %r15d, %r15d
jle 0x3ac1
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x28, %edx
callq 0x31e3
jmp 0x3ad6
testl %eax, %eax
jle 0x3afe
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e3
leaq -0x50(%rbp), %r14
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3afe
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 0x2b54
leaq 0x15f2(%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 0x3b5b
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 0x3bdf
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 0x31e3
movq %r15, %rdi
movq %r14, %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3bd4
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
incl %ebx
movq -0x58(%rbp), %rax
cmpl 0x20(%rax), %ebx
jl 0x3b97
leaq -0x158(%rbp), %rdi
movq %r12, %rsi
movl $0x2d, %edx
callq 0x31e3
leaq -0x148(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c12
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x2130
cmpq $0x0, 0x8(%r12)
je 0x3f2d
cmpq $0x0, 0x8(%r12)
je 0x3f2d
leaq -0x128(%rbp), %r13
movl $0x1, %r14d
leaq -0x50(%rbp), %r15
leaq -0x80(%rbp), %rbx
movq (%r12), %rcx
movb -0x1(%rcx,%r14), %al
cmpb $0x29, %al
jne 0x3d10
cmpb $0x2c, (%rcx,%r14)
jne 0x3cad
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x3140
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3c89
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 0x3dd9
movl $0x1, (%rsi)
jmp 0x3da1
cmpb $0x29, %al
jne 0x3d10
cmpb $0x3b, (%rcx,%r14)
jne 0x3d10
movq %r15, %rdi
movq %r12, %rsi
movl $0x3b, %edx
callq 0x31e3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3cec
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 0x3df5
movl $0x2, (%rsi)
jmp 0x3da1
cmpb $0x2d, %al
jne 0x3dab
cmpb $0x3e, (%rcx,%r14)
jne 0x3dab
movq %r15, %rdi
movq %r12, %rsi
movl $0x2d, %edx
callq 0x31e3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3d57
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0x138(%rbp), %rdi
movq %r12, %rsi
movl $0x3e, %edx
callq 0x31e3
movq -0x138(%rbp), %rdi
cmpq %r13, %rdi
je 0x3d86
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 0x3de7
movl $0x3, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rax)
jmp 0x3dc2
cmpb $0x29, %al
jne 0x3dba
cmpb $0x2e, (%rcx,%r14)
je 0x3ecf
cmpb $0x2e, %al
je 0x3e74
leaq 0x1(%r14), %rax
cmpq %r14, 0x8(%r12)
movq %rax, %r14
ja 0x3c3f
jmp 0x3f2d
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x4710
jmp 0x3dc2
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x4710
jmp 0x3dc2
movq -0x60(%rbp), %rdi
movq %r15, %rdx
callq 0x4710
jmp 0x3dc2
movl %esi, %ebx
cmpb $0x2d, (%rcx,%rbx)
je 0x3aa9
movq 0x31ba(%rip), %rdi      # 0x6fd0
leaq 0x1315(%rip), %rsi      # 0x5132
movl $0x15, %edx
callq 0x2150
movq (%r12), %rax
movb (%rax,%rbx), %al
leaq -0x50(%rbp), %rsi
movb %al, (%rsi)
movq 0x3195(%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 0x40cd
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e3
leaq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3eab
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 0x3f1f
leaq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rdi
callq 0x4710
jmp 0x3f2d
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl $0x2e, %edx
callq 0x31e3
leaq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4492
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3f06
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 0x40df
movl $0x4, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x60(%rax)
movq -0xa0(%rbp), %r13
cmpq %r13, -0x98(%rbp)
je 0x3ffe
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 0x2b54
movq %r12, %rdi
movq %r14, %rsi
callq 0x2e04
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x3fad
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 0x3fc9
movq %r12, (%rsi)
addq $0x8, 0x30(%rax)
jmp 0x3fd9
movq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x43b6
incq %rbx
movq -0xa0(%rbp), %r13
movq -0x98(%rbp), %rax
subq %r13, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rbx, %rax
ja 0x3f50
movq -0x80(%rbp), %r13
cmpq %r13, -0x78(%rbp)
je 0x40b8
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 0x2b54
movb $0x1, %r13b
movq %r12, %rdi
movq %r14, %rsi
movq -0xf8(%rbp), %rdx
callq 0x3360
movq %r12, -0x50(%rbp)
xorl %r13d, %r13d
movq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4850
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x4099
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 0x401b
leaq -0x80(%rbp), %rdi
callq 0x434c
leaq -0xa0(%rbp), %rdi
callq 0x434c
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 0x4710
jmp 0x3f2d
jmp 0x41e3
jmp 0x41e3
jmp 0x41ca
jmp 0x41e3
jmp 0x41ca
jmp 0x41e3
jmp 0x41e3
jmp 0x4151
jmp 0x4151
jmp 0x41ca
jmp 0x41e3
jmp 0x41e3
jmp 0x4151
jmp 0x41e3
jmp 0x41e3
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4154
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4154
movq %rax, %r14
movq -0x30(%rbp), %rbx
jmp 0x4238
movq %rax, %r14
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4180
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4180
movq %rax, %r14
movq %r15, %rbx
jmp 0x4238
jmp 0x41e3
jmp 0x41ca
jmp 0x41e3
jmp 0x41ca
jmp 0x41e3
jmp 0x41e3
movq %rax, %r14
movb $0x1, %r13b
jmp 0x420d
movq %rax, %r14
jmp 0x4212
movq %rax, %r14
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x4212
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2130
jmp 0x4212
jmp 0x41e3
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x421f
movq -0x40(%rbp), %rsi
incq %rsi
jmp 0x421a
movq %rax, %r14
jmp 0x421f
movq %rax, %r14
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x420d
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2130
testb %r13b, %r13b
je 0x421f
movl $0x40, %esi
movq %r12, %rdi
callq 0x2130
movq -0x30(%rbp), %rbx
leaq -0x80(%rbp), %rdi
callq 0x434c
leaq -0xa0(%rbp), %rdi
callq 0x434c
movq -0x60(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4254
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0xb0(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4273
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0xa8(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4292
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rsi
subq %rdi, %rsi
callq 0x2130
movq -0x58(%rbp), %rax
movq (%rax), %rdi
cmpq %rbx, %rdi
je 0x42a9
movq (%rbx), %rsi
incq %rsi
callq 0x2130
movq %r14, %rdi
callq 0x21d0
nop