// File: /workspace/github_cpp_makefile_star2_O1/menhits[P]phplus/src/Actions/FunctionAction.cpp
// Function: FunctionAction::addToProg(std::shared_ptr<ActionData>, std::shared_ptr<ActionData>, CppProgram*)
void addToProg(Action inLeft, Action inRight, CppProgram* prog)
	{
		if (!action)
		{
			resolveAction();
		}
		
		// construct a unique name that will NEVER collide with another funtion (even in the case of overloaded functions with the same Phplus name)
		// note that this name will be used to determine if this function has already been used in C++, so it should generate the same name every time
		string name="%";
		
		name+=(nameHint.empty() ? "func" : nameHint);
		
		name+="_"+str::ptrToUniqueStr(&*action);
		
		//name+="_"+getInLeftType()->getCompactString()+"_"+getInRightType()->getCompactString();
		
		/*
		if (str::hasSuffix(nameHint, "_CPP"))
			name=nameHint.substr(0, nameHint.size()-4);
		*/
		
		if (!prog->hasFunc(name))
		{
			prog->pushFunc(name, getInLeftType(), getInRightType(), getReturnType());
				if (getReturnType()->isCreatable() && action->getReturnType()!=getReturnType())
				{
					cppTupleCastAction(action, getReturnType())->addToProg(prog);
				}
				else
				{
					action->addToProg(prog);
				}
				prog->endln();
			prog->popFunc();
		}
		
		prog->name(name);
		
		prog->pushExpr();
			/*
			bool hasStarted=false;
			if (getInLeftType()->getType()==TypeBase::TUPLE)
			{
				for (auto i: *getInLeftType()->getAllSubTypes())
				{
					if (hasStarted)
						prog->code(", ");
					hasStarted=true;
					getElemFromTupleAction(getInLeftType(), i.name)->addToProg(inLeft, voidAction, prog);
				}
			}
			else if (!getInLeftType()->isCreatable())
			{
				// do nothing
			}
			else
			{
				if (hasStarted)
					prog->code(", ");
				hasStarted=true;
				inLeft->addToProg(prog);
			}
			
			if (getInRightType()->getType()==TypeBase::TUPLE)
			{
				for (auto i: *getInRightType()->getAllSubTypes())
				{
					if (hasStarted)
						prog->code(", ");
					hasStarted=true;
					getElemFromTupleAction(getInRightType(), i.name)->addToProg(inRight, voidAction, prog);
				}
			}
			else if (!getInRightType()->isCreatable())
			{
				// do nothing
			}
			else
			{
				if (hasStarted)
					prog->code(", ");
				hasStarted=true;
				inRight->addToProg(prog);
			}
			//prog->code(", ");
			//inRight->addToProg(prog);
			*/
			
			if (getInLeftType()->isCreatable())
			{
				inLeft->addToProg(prog);
			}
			
			if (getInRightType()->isCreatable())
			{
				if (getInLeftType()->isCreatable())
					prog->code(", ");
				
				inRight->addToProg(prog);
			}
			
		prog->popExpr();
		
		//prog->comment("function transpiling not yet implemented");
		
		
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
cmpq $0x0, 0x88(%rdi)
jne 0x655b3
movq %r15, %rdi
callq 0x65a36
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x10a72(%rip), %rsi     # 0x76038
leaq 0x10a6c(%rip), %rdx     # 0x76039
leaq 0x78(%rsp), %rdi
callq 0xdf6a
movq 0x10(%r15), %rdx
leaq 0x18(%rsp), %rbp
leaq 0x8(%rsp), %rdi
testq %rdx, %rdx
je 0x655fb
movq %rbp, (%rdi)
movq 0x8(%r15), %rsi
addq %rsi, %rdx
callq 0xdde2
jmp 0x65611
movq %rbp, (%rdi)
leaq 0x164ab(%rip), %rsi     # 0x7bab0
leaq 0x164a8(%rip), %rdx     # 0x7bab4
callq 0xdf6a
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0xa110
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x65634
callq 0xa2b0
movq 0x88(%r15), %rsi
leaq 0x98(%rsp), %rdi
movl $0x4, %edx
callq 0x747b0
leaq 0x15bd2(%rip), %rcx     # 0x7b226
leaq 0x98(%rsp), %rdi
movl $0x1, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0xa310
movq %rbp, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6568e
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x65695
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0xa110
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x656d0
callq 0xa2b0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x656e6
callq 0xa2b0
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x1c806
testb %al, %al
jne 0x658b1
movq 0x38(%r15), %rax
movq %rax, 0x68(%rsp)
movq 0x40(%r15), %rax
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x65727
movq 0x3388f(%rip), %rcx     # 0x98fa8
cmpb $0x0, (%rcx)
je 0x65723
incl 0x8(%rax)
jmp 0x65727
lock
incl 0x8(%rax)
movq 0x48(%r15), %rax
movq %rax, 0x58(%rsp)
movq 0x50(%r15), %rax
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x65753
movq 0x33863(%rip), %rcx     # 0x98fa8
cmpb $0x0, (%rcx)
je 0x6574f
incl 0x8(%rax)
jmp 0x65753
lock
incl 0x8(%rax)
movq 0x28(%r15), %rax
movq %rax, 0x48(%rsp)
movq 0x30(%r15), %rax
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x6577f
movq 0x33837(%rip), %rcx     # 0x98fa8
cmpb $0x0, (%rcx)
je 0x6577b
incl 0x8(%rax)
jmp 0x6577f
lock
incl 0x8(%rax)
leaq 0x78(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x48(%rsp), %r8
movq %rbx, %rdi
callq 0x1e24a
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x657aa
callq 0xdcba
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x657b9
callq 0xdcba
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x657c8
callq 0xdcba
movq 0x28(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x6580e
movq 0x88(%r15), %rax
movq 0x28(%rax), %rcx
cmpq 0x28(%r15), %rcx
je 0x6580e
movq %rax, 0x38(%rsp)
movq 0x90(%r15), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x65823
movq 0x337a4(%rip), %rcx     # 0x98fa8
cmpb $0x0, (%rcx)
je 0x6581f
incl 0x8(%rax)
jmp 0x65823
movq 0x88(%r15), %rdi
movq %rbx, %rsi
callq 0x4f248
jmp 0x6589d
lock
incl 0x8(%rax)
movq 0x28(%r15), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x6584f
movq 0x33767(%rip), %rcx     # 0x98fa8
cmpb $0x0, (%rcx)
je 0x6584b
incl 0x8(%rax)
jmp 0x6584f
lock
incl 0x8(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x69908
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4f248
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6587f
callq 0xdcba
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6588e
callq 0xdcba
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6589d
callq 0xdcba
movq 0xa0(%rbx), %rdi
callq 0x18652
movq %rbx, %rdi
callq 0x1d636
movq 0xa0(%rbx), %rdi
leaq 0x78(%rsp), %rsi
callq 0x185d6
movq 0xa0(%rbx), %rdi
callq 0x18b54
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x658e8
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x4f248
movq 0x48(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x6594a
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x6593f
leaq 0x8(%rsp), %rdi
movq %rbp, (%rdi)
leaq 0x13de2(%rip), %rsi     # 0x796f5
leaq 0x13ddd(%rip), %rdx     # 0x796f7
callq 0xdf6a
movq 0xa0(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1834e
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6593f
callq 0xa2b0
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x4f248
movq 0xa0(%rbx), %rdi
callq 0x18bc6
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x65965
callq 0xa2b0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6598e
callq 0xdcba
jmp 0x6598e
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6599d
callq 0xdcba
movq 0x40(%rsp), %rdi
jmp 0x659ce
jmp 0x65a06
jmp 0x65a1c
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x659ba
callq 0xdcba
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x659c9
callq 0xdcba
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x65a1f
callq 0xdcba
jmp 0x65a1f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x659f1
callq 0xa2b0
jmp 0x659f1
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x65a13
jmp 0x65a1f
jmp 0x65a1c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x65a1f
callq 0xa2b0
jmp 0x65a1f
jmp 0x65a1c
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x65a2e
callq 0xa2b0
movq %rbx, %rdi
callq 0xa510