// File: /workspace/github_cpp_makefile_star2_O3/lotka[P]prologplusplus/predicate.cpp
// Function: PredicateRef::PredicateRef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<Predicate*, std::allocator<Predicate*>>&)
PredicateRef::PredicateRef(string input, vector<Predicate *> &predicates)
{
	int commas 	= countChar(input,',');
	// left brackets
	int lb 			= countChar(input,'(');
	// right brackets
	int rb	    = countChar(input,')');
	// dots
	int dot 	= countChar(input,'.');
	name = cropString(input,'(');
	// Add the airty to the name
	name = name + "\\0";
	airty = commas+lb;
	name[name.size()-1] = airty+'0';
	//cout << "debug_info : " << name << endl;

	bool exists = false;
	for(int i = 0; i < predicates.size(); ++i)
	{
		if(predicates[i]->name == name and predicates[i]->airty == airty)
		{
			exists = true;
		}
	}
	if(not exists)
	{
		cout << "ERROR in locating " << name << endl;
	}

	for(int i = 0; i < airty-1; ++i)
	{
		Atom * atom_ptr = new Atom(cropString(input,','));
		// for free variables, check for existing instance and point to that
		if(atom_ptr->free_variable)
		{
			for(int i = 0; i < args.size(); ++i)
			{
				if((*atom_ptr).name==(*args[i]).name)
				{
					atom_ptr=args[i];
					break;
				}
			}
		}
		args.push_back(atom_ptr);
	}

	args.push_back(new Atom(cropString(input,')')));

	//cout << "debug_info : ";
	// for(int i = 0; i < airty; ++i)
	// {
	// 	cout << *args[i] << " ";
	// } cout << endl;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, -0x38(%rbp)
movq %rsi, %r15
leaq 0x10(%rdi), %rax
movq %rax, -0x80(%rbp)
movq %rax, (%rdi)
xorl %eax, %eax
movq %rax, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
leaq 0x20(%rdi), %rcx
movq %rcx, -0x48(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movq %rdi, -0x30(%rbp)
movq %rax, 0x30(%rdi)
leaq -0x110(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsi), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %rdi
callq 0x2b40
leaq -0x120(%rbp), %rdi
movl $0x2c, %esi
callq 0x3286
movl %eax, %r12d
movq -0x120(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3403
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xf0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x2b40
leaq -0x100(%rbp), %rdi
movl $0x28, %esi
callq 0x3286
movl %eax, %r13d
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3453
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xd0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x2b40
leaq -0xe0(%rbp), %rdi
movl $0x29, %esi
callq 0x3286
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x34a0
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xb0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x2b40
leaq -0xc0(%rbp), %rdi
movl $0x2e, %esi
callq 0x3286
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x34ed
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0x78(%rbp), %rdi
movq %r15, %rsi
movl $0x28, %edx
movq -0x30(%rbp), %rbx
callq 0x31e7
leaq -0x78(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x68(%rbp), %rbx
cmpq %rbx, %rdi
je 0x3529
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0x78(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x2b40
leaq 0x1bd2(%rip), %rsi      # 0x511c
leaq -0x78(%rbp), %rdi
callq 0x21f0
movq %r15, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
cmpq %rbx, %rdi
je 0x3577
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2130
addl %r12d, %r13d
movq -0x30(%rbp), %rcx
movl %r13d, 0x38(%rcx)
addb $0x30, %r13b
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movb %r13b, -0x1(%rax,%rcx)
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rsi
subq %r15, %rsi
je 0x3610
sarq $0x3, %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %r12
movl 0x38(%rax), %ebx
cmpq $0x1, %rsi
adcq $0x0, %rsi
xorl %r14d, %r14d
xorl %edi, %edi
movq %rsi, -0x58(%rbp)
movq (%r15,%r14,8), %r13
cmpq %r12, 0x8(%r13)
jne 0x3602
testq %r12, %r12
je 0x35f8
movq %rdi, -0x38(%rbp)
movq (%r13), %rdi
movq -0x40(%rbp), %rsi
movq %r12, %rdx
callq 0x2140
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
testl %eax, %eax
jne 0x3602
cmpl %ebx, 0x20(%r13)
sete %al
orb %al, %dil
incq %r14
cmpq %r14, %rsi
jne 0x35c9
testb $0x1, %dil
jne 0x366c
movq 0x39b9(%rip), %rdi      # 0x6fd0
leaq 0x1b01(%rip), %rsi      # 0x511f
movl $0x12, %edx
movq -0x30(%rbp), %rbx
callq 0x2150
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x3996(%rip), %rdi      # 0x6fd0
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
movl 0x38(%rbx), %ebx
cmpl $0x2, %ebx
movq -0x30(%rbp), %rbx
movq -0x50(%rbp), %r15
jl 0x379f
xorl %r13d, %r13d
leaq -0x90(%rbp), %r12
leaq -0xa0(%rbp), %r14
movl $0x40, %edi
callq 0x2120
movq %rax, -0x38(%rbp)
movq %r14, %rdi
movq %r15, %rsi
movl $0x2c, %edx
callq 0x31e7
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x2e00
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x36d3
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2130
movq -0x38(%rbp), %r14
movq %r14, -0x78(%rbp)
movq 0x28(%rbx), %rsi
cmpb $0x1, 0x20(%r14)
jne 0x3763
movq %r13, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rsi, %r13
subq %rax, %r13
je 0x3758
sarq $0x3, %r13
movq 0x8(%r14), %r15
cmpq $0x1, %r13
adcq $0x0, %r13
xorl %ebx, %ebx
movq %rax, -0x58(%rbp)
movq (%rax,%rbx,8), %r14
cmpq 0x8(%r14), %r15
jne 0x373e
testq %r15, %r15
je 0x374c
movq %rsi, %r12
movq (%r14), %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq %r15, %rdx
callq 0x2140
movq %r12, %rsi
testl %eax, %eax
movq -0x58(%rbp), %rax
je 0x374c
incq %rbx
cmpq %rbx, %r13
jne 0x370f
movq -0x38(%rbp), %r14
jmp 0x3750
movq %r14, -0x78(%rbp)
movq -0x30(%rbp), %rbx
movq -0x50(%rbp), %r15
leaq -0x90(%rbp), %r12
movq -0x40(%rbp), %r13
cmpq 0x30(%rbx), %rsi
je 0x377a
movq %r14, (%rsi)
addq $0x8, 0x28(%rbx)
leaq -0xa0(%rbp), %r14
jmp 0x378e
movq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0x4388
leaq -0xa0(%rbp), %r14
incl %r13d
movl 0x38(%rbx), %eax
decl %eax
cmpl %eax, %r13d
jl 0x368e
movl $0x40, %edi
callq 0x2120
movq %rax, %r14
leaq -0x140(%rbp), %rdi
movq %r15, %rsi
movl $0x29, %edx
callq 0x31e7
movb $0x1, %bl
leaq -0x140(%rbp), %rsi
movq %r14, %rdi
callq 0x2e00
leaq -0x78(%rbp), %rsi
movq %r14, (%rsi)
xorl %ebx, %ebx
movq -0x48(%rbp), %rdi
callq 0x2fc0
leaq -0x130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3802
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2130
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x38ea
jmp 0x3929
movq %rax, %r15
movq -0x78(%rbp), %rdi
cmpq %rbx, %rdi
je 0x392c
movq -0x68(%rbp), %rsi
jmp 0x38bd
jmp 0x3929
jmp 0x3929
movq %rax, %r15
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x392c
movq -0xb0(%rbp), %rsi
jmp 0x38bd
jmp 0x3929
movq %rax, %r15
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x392c
movq -0xd0(%rbp), %rsi
jmp 0x38bd
jmp 0x3929
movq %rax, %r15
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x392c
movq -0xf0(%rbp), %rsi
jmp 0x38bd
jmp 0x3929
movq %rax, %r15
movq -0x120(%rbp), %rdi
cmpq %rbx, %rdi
je 0x392c
movq -0x110(%rbp), %rsi
incq %rsi
jmp 0x3922
jmp 0x3929
movq %rax, %r15
leaq -0x130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38e6
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2130
testb %bl, %bl
je 0x392c
movl $0x40, %esi
movq %r14, %rdi
jmp 0x3922
jmp 0x3929
movq %rax, %r15
jmp 0x3919
movq %rax, %r15
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3919
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x40, %esi
movq -0x38(%rbp), %rdi
callq 0x2130
jmp 0x392c
movq %rax, %r15
movq -0x48(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
movq -0x30(%rbp), %rbx
je 0x3948
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x2130
movq (%rbx), %rdi
cmpq -0x80(%rbp), %rdi
je 0x3960
movq -0x80(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2130
movq %r15, %rdi
callq 0x21d0