// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rsi, %rdx
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, -0x50(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movq %rdi, -0x40(%rbp)
movq %rax, 0x30(%rdi)
leaq -0x110(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsi), %rsi
movq %rdx, -0x38(%rbp)
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %rdi
callq 0x2b54
leaq -0x120(%rbp), %rdi
movl $0x2c, %esi
callq 0x3282
movl %eax, %r12d
movq -0x120(%rbp), %rdi
cmpq %rbx, %rdi
je 0x33fa
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xf0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x2b54
leaq -0x100(%rbp), %rdi
movl $0x28, %esi
callq 0x3282
movl %eax, %r13d
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x344e
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xd0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x2b54
leaq -0xe0(%rbp), %rdi
movl $0x29, %esi
callq 0x3282
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x349f
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0xb0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x2b54
leaq -0xc0(%rbp), %rdi
movl $0x2e, %esi
callq 0x3282
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x34f0
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2130
movq %r15, -0x30(%rbp)
leaq -0x78(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x28, %edx
movq -0x40(%rbp), %rbx
callq 0x31e3
leaq -0x78(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
leaq -0x68(%rbp), %r15
cmpq %r15, %rdi
je 0x3531
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2130
leaq -0x78(%rbp), %rdi
movq %r15, (%rdi)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
callq 0x2b54
leaq 0x1bce(%rip), %rsi      # 0x511c
leaq -0x78(%rbp), %rdi
callq 0x21f0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x3576
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2130
addl %r12d, %r13d
movl %r13d, 0x38(%rbx)
addb $0x30, %r13b
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movb %r13b, -0x1(%rax,%rcx)
movq -0x30(%rbp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rsi
subq %r13, %rsi
je 0x3613
sarq $0x3, %rsi
movq (%rbx), %rax
movq %rax, -0x48(%rbp)
movq 0x8(%rbx), %r12
cmpq $0x1, %rsi
adcq $0x0, %rsi
movl 0x38(%rbx), %edx
movl %edx, -0x54(%rbp)
xorl %r14d, %r14d
xorl %edi, %edi
movq (%r13,%r14,8), %r15
movq 0x8(%r15), %rdx
cmpq %r12, %rdx
jne 0x3601
testq %rdx, %rdx
je 0x35ee
movl %edi, -0x30(%rbp)
movq (%r15), %rdi
movq %rsi, %rbx
movq -0x48(%rbp), %rsi
callq 0x2140
movl -0x30(%rbp), %edi
movq %rbx, %rsi
testl %eax, %eax
jne 0x3601
movl -0x54(%rbp), %edx
cmpl %edx, 0x20(%r15)
movzbl %dil, %edi
movl $0x1, %edx
cmovel %edx, %edi
incq %r14
cmpq %r14, %rsi
jne 0x35bf
testb $0x1, %dil
movq -0x40(%rbp), %rbx
jne 0x3668
movq 0x39b6(%rip), %rdi      # 0x6fd0
leaq 0x1afe(%rip), %rsi      # 0x511f
movl $0x12, %edx
callq 0x2150
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x3997(%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
cmpl $0x2, 0x38(%rbx)
jl 0x3786
xorl %r14d, %r14d
leaq -0xa0(%rbp), %r15
movl $0x40, %edi
callq 0x2120
movq %rax, -0x30(%rbp)
movq %r15, %rdi
movq -0x38(%rbp), %rsi
movl $0x2c, %edx
callq 0x31e3
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x2e04
movq %r14, -0x48(%rbp)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x36cd
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2130
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpb $0x1, 0x20(%rax)
jne 0x3736
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rbx
movq 0x28(%rax), %r12
subq %rbx, %r12
je 0x3736
sarq $0x3, %r12
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r13
cmpq $0x1, %r12
adcq $0x0, %r12
xorl %r15d, %r15d
movq (%rbx,%r15,8), %r14
cmpq 0x8(%r14), %r13
jne 0x3728
testq %r13, %r13
je 0x3732
movq (%r14), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rdx
callq 0x2140
testl %eax, %eax
je 0x3732
incq %r15
cmpq %r15, %r12
jne 0x3703
jmp 0x3736
movq %r14, -0x78(%rbp)
movq -0x40(%rbp), %rbx
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x375d
movq -0x78(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rbx)
movq -0x48(%rbp), %r14
leaq -0xa0(%rbp), %r15
jmp 0x3775
movq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0x43b6
movq -0x48(%rbp), %r14
leaq -0xa0(%rbp), %r15
incl %r14d
movl 0x38(%rbx), %eax
decl %eax
cmpl %eax, %r14d
jl 0x367c
movl $0x40, %edi
callq 0x2120
movq %rax, %r14
leaq -0x140(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x29, %edx
callq 0x31e3
movb $0x1, %r15b
leaq -0x140(%rbp), %rsi
movq %r14, %rdi
callq 0x2e04
leaq -0x78(%rbp), %rsi
movq %r14, (%rsi)
xorl %r15d, %r15d
movq -0x50(%rbp), %rdi
callq 0x2fc4
leaq -0x130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37ec
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, %r12
movb $0x1, %r15b
jmp 0x38d3
jmp 0x391e
movq %rax, %r12
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x3921
movq -0x68(%rbp), %rsi
jmp 0x38aa
jmp 0x391e
jmp 0x391e
movq %rax, %r12
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3921
movq -0xb0(%rbp), %rsi
jmp 0x38aa
jmp 0x391e
movq %rax, %r12
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3921
movq -0xd0(%rbp), %rsi
jmp 0x38aa
jmp 0x391e
movq %rax, %r12
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3921
movq -0xf0(%rbp), %rsi
jmp 0x38aa
jmp 0x391e
movq %rax, %r12
movq -0x120(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3921
movq -0x110(%rbp), %rsi
incq %rsi
jmp 0x3917
jmp 0x391e
movq %rax, %r12
leaq -0x130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38d3
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2130
testb %r15b, %r15b
je 0x3921
movl $0x40, %esi
movq %r14, %rdi
jmp 0x3917
jmp 0x391e
movq %rax, %r12
jmp 0x390e
movq %rax, %r12
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x390e
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2130
movl $0x40, %esi
movq -0x30(%rbp), %rdi
callq 0x2130
jmp 0x3921
movq %rax, %r12
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
movq -0x40(%rbp), %rbx
je 0x393d
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x2130
movq (%rbx), %rdi
cmpq -0x80(%rbp), %rdi
je 0x3955
movq -0x80(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2130
movq %r12, %rdi
callq 0x21d0
nop