// File: /workspace/github_cpp_makefile_star2_O3/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 0x66415
movq %r15, %rdi
callq 0x66892
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x10c10(%rip), %rsi     # 0x77038
leaq 0x10c0a(%rip), %rdx     # 0x77039
leaq 0x78(%rsp), %rdi
callq 0xdfa8
movq 0x10(%r15), %rdx
leaq 0x18(%rsp), %rbp
leaq 0x8(%rsp), %rdi
testq %rdx, %rdx
je 0x6645d
movq %rbp, (%rdi)
movq 0x8(%r15), %rsi
addq %rsi, %rdx
callq 0xde0c
jmp 0x66473
movq %rbp, (%rdi)
leaq 0x16609(%rip), %rsi     # 0x7ca70
leaq 0x16606(%rip), %rdx     # 0x7ca74
callq 0xdfa8
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0xa110
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x66496
callq 0xa2b0
movq 0x88(%r15), %rsi
leaq 0x98(%rsp), %rdi
movl $0x4, %edx
callq 0x75750
leaq 0x15d30(%rip), %rcx     # 0x7c1e6
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 0x664f0
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x664f7
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 0x66532
callq 0xa2b0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66548
callq 0xa2b0
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x1cb42
testb %al, %al
jne 0x6670c
movq 0x38(%r15), %rax
movq %rax, 0x68(%rsp)
movq 0x40(%r15), %rax
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x66589
movq 0x33a2d(%rip), %rcx     # 0x99fa8
cmpb $0x0, (%rcx)
je 0x66585
incl 0x8(%rax)
jmp 0x66589
lock
incl 0x8(%rax)
movq 0x48(%r15), %rax
movq %rax, 0x58(%rsp)
movq 0x50(%r15), %rax
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x665b5
movq 0x33a01(%rip), %rcx     # 0x99fa8
cmpb $0x0, (%rcx)
je 0x665b1
incl 0x8(%rax)
jmp 0x665b5
lock
incl 0x8(%rax)
movq 0x28(%r15), %rax
movq %rax, 0x48(%rsp)
movq 0x30(%r15), %rax
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x665e1
movq 0x339d5(%rip), %rcx     # 0x99fa8
cmpb $0x0, (%rcx)
je 0x665dd
incl 0x8(%rax)
jmp 0x665e1
lock
incl 0x8(%rax)
leaq 0x78(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x48(%rsp), %r8
movq %rbx, %rdi
callq 0x1e5bc
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x6660c
callq 0xdce4
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x6661b
callq 0xdce4
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x6662a
callq 0xdce4
movq 0x28(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq 0x88(%r15), %rdi
testb %al, %al
je 0x66670
movq 0x28(%r15), %rax
cmpq %rax, 0x28(%rdi)
je 0x66670
movq %rdi, 0x38(%rsp)
movq 0x90(%r15), %rcx
movq %rcx, 0x40(%rsp)
testq %rcx, %rcx
je 0x66682
movq 0x33942(%rip), %rdx     # 0x99fa8
cmpb $0x0, (%rdx)
je 0x6667a
incl 0x8(%rcx)
jmp 0x66682
movq %rbx, %rsi
callq 0x4ff7c
jmp 0x666f8
lock
incl 0x8(%rcx)
movq 0x28(%r15), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x666aa
movq 0x3390c(%rip), %rcx     # 0x99fa8
cmpb $0x0, (%rcx)
je 0x666a6
incl 0x8(%rax)
jmp 0x666aa
lock
incl 0x8(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x6a814
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4ff7c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x666da
callq 0xdce4
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x666e9
callq 0xdce4
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x666f8
callq 0xdce4
movq 0xa0(%rbx), %rdi
callq 0x18918
movq %rbx, %rdi
callq 0x1d9a4
movq 0xa0(%rbx), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1889c
movq 0xa0(%rbx), %rdi
callq 0x18e22
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x66743
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x4ff7c
movq 0x48(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x667a5
movq 0x38(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x6679a
leaq 0x8(%rsp), %rdi
movq %rbp, (%rdi)
leaq 0x13f47(%rip), %rsi     # 0x7a6b5
leaq 0x13f42(%rip), %rdx     # 0x7a6b7
callq 0xdfa8
movq 0xa0(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1861a
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6679a
callq 0xa2b0
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x4ff7c
movq 0xa0(%rbx), %rdi
callq 0x18e94
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x667c0
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 0x667e9
callq 0xdce4
jmp 0x667e9
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x667f8
callq 0xdce4
movq 0x40(%rsp), %rdi
jmp 0x66829
jmp 0x66861
jmp 0x66877
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x66815
callq 0xdce4
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x66824
callq 0xdce4
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x6687a
callq 0xdce4
jmp 0x6687a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6684c
callq 0xa2b0
jmp 0x6684c
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x6686e
jmp 0x6687a
jmp 0x66877
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6687a
callq 0xa2b0
jmp 0x6687a
jmp 0x66877
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x66889
callq 0xa2b0
movq %rbx, %rdi
callq 0xa510
nop