// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r15
cmpq $0x0, 0x88(%rdi)
jne 0x4902d
movq %r15, %rdi
callq 0x49374
leaq 0xb004(%rip), %rsi      # 0x54038
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xa150
movq 0x10(%r15), %r14
testq %r14, %r14
je 0x4905c
leaq 0x8(%r15), %rsi
leaq 0x8(%rsp), %rdi
callq 0xa3b0
jmp 0x49072
leaq 0x109f5(%rip), %rsi     # 0x59a58
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xa150
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa540
leaq 0x88(%r15), %r13
leaq 0x8(%rsp), %rdi
callq 0xa558
testq %r14, %r14
movq (%r13), %rsi
leaq 0xa8(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x534b2
movq %rbp, 0x30(%rsp)
leaq 0x10119(%rip), %rsi     # 0x591ce
leaq 0x8(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x11ff8
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa540
leaq 0x8(%rsp), %rdi
callq 0xa558
leaq 0xa8(%rsp), %rdi
callq 0xa558
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x17166
testb %al, %al
jne 0x4921a
movq %r12, 0x28(%rsp)
leaq 0x38(%r15), %rsi
leaq 0x38(%rsp), %rdi
callq 0x12c0a
leaq 0x48(%r15), %rsi
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x12c0a
leaq 0x28(%r15), %rbp
leaq 0x88(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x12c0a
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x183d4
leaq 0x90(%rsp), %rdi
callq 0xc984
leaq 0xa0(%rsp), %rdi
callq 0xc984
leaq 0x40(%rsp), %rdi
callq 0xc984
movq (%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq 0x28(%rsp), %r12
movq (%r13), %rdi
testb %al, %al
je 0x49202
movq 0x28(%rdi), %rax
cmpq (%rbp), %rax
je 0x49202
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x12c1e
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x12c0a
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4c21a
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3a606
movq 0x28(%rsp), %r12
leaq 0x10(%rsp), %rdi
callq 0xc984
leaq 0x70(%rsp), %rdi
callq 0xc984
leaq 0x80(%rsp), %rdi
callq 0xc984
jmp 0x4920a
movq %rbx, %rsi
callq 0x3a606
movq %rbx, %rdi
callq 0x3b712
movq %rbx, %rdi
callq 0x17b0a
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x39d78
movq %rbx, %rdi
callq 0x3a5fa
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x4924d
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x3a606
movq 0x48(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x492a5
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x49299
leaq 0xec25(%rip), %rsi      # 0x57e95
leaq 0x8(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0xa150
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x39d6c
leaq 0x8(%rsp), %rdi
callq 0xa558
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x3a606
movq %rbx, %rdi
callq 0x3a692
leaq 0x48(%rsp), %rdi
callq 0xa558
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xc984
jmp 0x492db
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xc984
leaq 0x80(%rsp), %rdi
jmp 0x4931d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x4933e
jmp 0x4935e
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xc984
leaq 0xa0(%rsp), %rdi
callq 0xc984
leaq 0x40(%rsp), %rdi
callq 0xc984
jmp 0x49361
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xa558
jmp 0x49336
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xa558
jmp 0x49361
jmp 0x4935e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xa558
jmp 0x49359
movq %rax, %rbx
testq %r14, %r14
jmp 0x49361
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xa558
movq %rbx, %rdi
callq 0xa500
nop