// File: 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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, 0x78(%rsp)
movq %rdx, 0x80(%rsp)
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq %rdx, 0x1c0(%rsp)
movq %rcx, 0x1b8(%rsp)
movq 0x1d0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
addq $0x88, %rdi
callq 0x1be40
testb $0x1, %al
jne 0xb8ce1
movq 0x88(%rsp), %rdi
callq 0xb9400
leaq 0x197(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xb690
movq 0x70(%rsp), %rdx
leaq 0x18321(%rip), %rsi     # 0xd1020
leaq 0x198(%rsp), %rdi
callq 0xb4c0
jmp 0xb8d0e
leaq 0x197(%rsp), %rdi
callq 0xb3f0
movq 0x88(%rsp), %rdi
addq $0x8, %rdi
callq 0xb610
movb $0x0, 0x15e(%rsp)
testb $0x1, %al
jne 0xb8d3a
jmp 0xb8d71
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xb690
movq 0x68(%rsp), %rdx
movb $0x1, 0x15e(%rsp)
leaq 0x1e540(%rip), %rsi     # 0xd72a0
leaq 0x160(%rsp), %rdi
callq 0xb4c0
jmp 0xb8d6f
jmp 0xb8d8e
movq 0x88(%rsp), %rsi
addq $0x8, %rsi
leaq 0x160(%rsp), %rdi
callq 0xb1a0
jmp 0xb8d8c
jmp 0xb8d8e
leaq 0x198(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0xb470
jmp 0xb8da5
leaq 0x160(%rsp), %rdi
callq 0xb6e8
testb $0x1, 0x15e(%rsp)
jne 0xb8dbe
jmp 0xb8dcb
leaq 0x15f(%rsp), %rdi
callq 0xb3f0
movq 0x88(%rsp), %rdi
addq $0x88, %rdi
callq 0xb9b40
movq %rax, %rsi
leaq 0x118(%rsp), %rdi
movl $0x4, %edx
callq 0xcfd20
jmp 0xb8df6
leaq 0x1dc19(%rip), %rsi     # 0xd6a16
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rdx
callq 0x1bcf0
jmp 0xb8e14
leaq 0x198(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0xb470
jmp 0xb8e2b
leaq 0x138(%rsp), %rdi
callq 0xb6e8
leaq 0x118(%rsp), %rdi
callq 0xb6e8
movq 0x1b8(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x2a8a0
movb %al, 0x67(%rsp)
jmp 0xb8e60
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0xb9205
jmp 0xb8e6e
movq 0x88(%rsp), %rdi
movq 0x1b8(%rsp), %rax
movq %rax, 0x40(%rsp)
callq 0x3f060
movq %rax, %rsi
leaq 0x108(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x1a920
movq 0x88(%rsp), %rdi
callq 0x3f070
movq %rax, %rsi
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x1a920
movq 0x88(%rsp), %rdi
callq 0x1bed0
movq %rax, %rsi
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x1a920
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
leaq 0x198(%rsp), %rsi
callq 0x2de20
jmp 0xb8f04
leaq 0xe8(%rsp), %rdi
callq 0x1a950
leaq 0xf8(%rsp), %rdi
callq 0x1a950
leaq 0x108(%rsp), %rdi
callq 0x1a950
movq 0x88(%rsp), %rdi
callq 0x1bed0
movq %rax, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movb %al, 0x3f(%rsp)
jmp 0xb8f52
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0xb8f5f
jmp 0xb91bd
movq 0x88(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb50
movq %rax, %rdi
callq 0x1bed0
movq 0x88(%rsp), %rdi
movq %rax, 0x30(%rsp)
callq 0x1bed0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x1be90
testb $0x1, %al
jne 0xb8fa3
jmp 0xb91bd
movq 0x88(%rsp), %rsi
addq $0x88, %rsi
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1ac60
movq 0x88(%rsp), %rdi
callq 0x1bed0
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x1a920
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
callq 0xc02c0
jmp 0xb8fff
leaq 0xd8(%rsp), %rdi
callq 0x1bb50
movq %rax, %rdi
movq 0x1b8(%rsp), %rsi
callq 0x97950
jmp 0xb901e
leaq 0xd8(%rsp), %rdi
callq 0x1acc0
leaq 0xb8(%rsp), %rdi
callq 0x1a950
leaq 0xc8(%rsp), %rdi
callq 0x1acc0
jmp 0xb91e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x197(%rsp), %rdi
callq 0xb3f0
jmp 0xb93e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0xb90a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x160(%rsp), %rdi
callq 0xb6e8
testb $0x1, 0x15e(%rsp)
jne 0xb90b3
jmp 0xb90c0
leaq 0x15f(%rsp), %rdi
callq 0xb3f0
jmp 0xb93d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0xb93d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0xb9115
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xb6e8
leaq 0x118(%rsp), %rdi
callq 0xb6e8
jmp 0xb93d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x1a950
leaq 0xf8(%rsp), %rdi
callq 0x1a950
leaq 0x108(%rsp), %rdi
callq 0x1a950
jmp 0xb93d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0xb919e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x1acc0
leaq 0xb8(%rsp), %rdi
callq 0x1a950
leaq 0xc8(%rsp), %rdi
callq 0x1acc0
jmp 0xb93d7
movq 0x88(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb50
movq %rax, %rdi
movq 0x1b8(%rsp), %rsi
callq 0x97950
jmp 0xb91e3
jmp 0xb91e5
movq 0x1b8(%rsp), %rdi
callq 0x99d60
jmp 0xb91f4
movq 0x1b8(%rsp), %rdi
callq 0x2c250
jmp 0xb9203
jmp 0xb9205
movq 0x1b8(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x96790
jmp 0xb921c
movq 0x1b8(%rsp), %rdi
callq 0x97930
jmp 0xb922b
movq 0x88(%rsp), %rdi
callq 0x3f060
movq %rax, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movb %al, 0x1f(%rsp)
jmp 0xb9252
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0xb925c
jmp 0xb927a
movq 0x78(%rsp), %rdi
callq 0x1bb50
movq %rax, %rdi
movq 0x1b8(%rsp), %rsi
callq 0x97950
jmp 0xb9278
jmp 0xb927a
movq 0x88(%rsp), %rdi
callq 0x3f070
movq %rax, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movb %al, 0x1e(%rsp)
jmp 0xb92a1
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0xb92ae
jmp 0xb93b3
movq 0x88(%rsp), %rdi
callq 0x3f060
movq %rax, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movb %al, 0x1d(%rsp)
jmp 0xb92d5
movb 0x1d(%rsp), %al
testb $0x1, %al
jne 0xb92e2
jmp 0xb9392
movq 0x1b8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x97(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xb690
movq 0x10(%rsp), %rdx
leaq 0x1c3dd(%rip), %rsi     # 0xd56ea
leaq 0x98(%rsp), %rdi
callq 0xb4c0
jmp 0xb931c
movq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x96750
jmp 0xb9330
leaq 0x98(%rsp), %rdi
callq 0xb6e8
leaq 0x97(%rsp), %rdi
callq 0xb3f0
jmp 0xb9392
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0xb9383
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xb6e8
leaq 0x97(%rsp), %rdi
callq 0xb3f0
jmp 0xb93d7
movq 0x80(%rsp), %rdi
callq 0x1bb50
movq %rax, %rdi
movq 0x1b8(%rsp), %rsi
callq 0x97950
jmp 0xb93b1
jmp 0xb93b3
movq 0x1b8(%rsp), %rdi
callq 0x97a00
jmp 0xb93c2
leaq 0x198(%rsp), %rdi
callq 0xb6e8
addq $0x1d8, %rsp            # imm = 0x1D8
retq
leaq 0x198(%rsp), %rdi
callq 0xb6e8
movq 0x188(%rsp), %rdi
callq 0xb680
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)