// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/src/parser/function.cpp
// Function: FunctionNode::Provision()
bool FunctionNode::Provision()
{
        list<FuncArgDef*>::iterator i;
        for(i = this->ArgList->begin(); i!=this->ArgList->end(); i++)
        {
                string argname = (*i)->GetName();
                DataType argtype = (*i)->GetType();
                VariableDef * localvar = new VariableDef(argname);
                localvar->SetVarType(argtype);
                this->AddVariable(localvar);
                
                unsigned long varindex = localvar->GetVarIndex();
                (*i)->SetArgIndex(varindex);
        }

        Node * parent = this->GetParentNode();
        if(parent==NULL)
        {
                cerr<<"pupp provision error: A function cannot be defined without a context."<<endl;
                return false;
        }

        list<ClosureVarDesc*>::iterator j;

        if(this->CopyList!=NULL)
        {
                int pos = 0;
                
                for(j = this->CopyList->begin(); j!= this->CopyList->end(); j++)
                {
                        //Because its parent is NOT a Node but a lambda exp, the layer has to be set to 0 to skip the exp.
                        //This is extremely unusual.
                        unsigned long layer = 0; 
                        
                        string varname = (*j)->GetVarName();
                        VariableDef * vardef = parent->FindVariable(varname, &layer);
                        if(vardef==NULL)
                        {
                                cerr<<"pupp provision error: Variable "<<varname<<" has not been defined"<<endl;
                                return false;
                        }
                        
                        VariableDef * newvardef = new VariableDef(varname);
                        newvardef->SetVarType(vardef->GetVarType());
                        newvardef->SetNeedInstance(false);

                        this->AddVariable(newvardef);
                        
                        (*j)->SetSrcLayer(layer);
                        (*j)->SetSrcDef(vardef);
                        (*j)->SetDstDef(newvardef);
                        
                        if(pos++==0)
                        {
                                this->ClosureVarStartIndex = newvardef->GetVarIndex();
                        }
                        
                }
        }
        
        return ContainerNode::Provision();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq 0x98(%rdi), %rax
movq (%rax), %r14
cmpq %rax, %r14
je 0xbebb
leaq 0x18(%rsp), %r12
leaq 0x70(%rsp), %r15
movq 0x10(%r14), %rax
movq %r12, %r13
movq %r12, 0x8(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x99a6
movq 0x10(%r14), %rax
movl 0x20(%rax), %ebp
movl $0x40, %edi
callq 0x6260
movq %rax, %r12
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x99a6
movq %r12, %rdi
movq %r15, %rsi
callq 0x1884e
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xbe6c
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6270
movq %r12, %rdi
movl %ebp, %esi
callq 0x18964
movq %rbx, %rdi
movq %r12, %rsi
callq 0xc34c
movq %r12, %rdi
callq 0x189a0
movq 0x10(%r14), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%rsp), %rdi
movq %r13, %r12
cmpq %r13, %rdi
je 0xbeab
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%r14), %r14
cmpq 0x98(%rbx), %r14
jne 0xbde9
movq %rbx, %rdi
callq 0xc33c
movq %rax, 0x90(%rsp)
testq %rax, %rax
je 0xc0ef
movq 0xa0(%rbx), %rbp
testq %rbp, %rbp
je 0xc0e5
xorl %eax, %eax
leaq 0x50(%rsp), %r12
movq (%rbp), %rbp
cmpq 0xa0(%rbx), %rbp
je 0xc0e5
movl %eax, 0x4(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x10(%rbp), %rax
leaq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x99a6
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x99a6
movq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xc4ca
movq %rax, %r15
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xbf82
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r15, %r15
je 0xc034
movl $0x40, %edi
callq 0x6260
movq %rax, %r13
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %r14
movq %r12, %rdi
callq 0x99a6
movq %r13, %rdi
movq %r14, %rsi
callq 0x1884e
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xbfe1
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6270
movq %r15, %rdi
callq 0x18968
movq %r13, %rdi
movl %eax, %esi
callq 0x18964
movq %r13, %rdi
xorl %esi, %esi
callq 0x189aa
movq %rbx, %rdi
movq %r13, %rsi
callq 0xc34c
movq 0x10(%rbp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x38(%rax)
movq %r15, 0x28(%rax)
movq 0x10(%rbp), %rax
movq %r13, 0x30(%rax)
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0xc0a3
incl %eax
movl %eax, 0x4(%rsp)
jmp 0xc0ba
movl $0x1f, %edx
movq 0x3afb0(%rip), %rdi     # 0x46ff0
leaq 0x291ac(%rip), %rsi     # 0x351f3
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x3af93(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %r13
movl $0x15, %edx
movq %rax, %rdi
leaq 0x2919f(%rip), %rsi     # 0x35213
callq 0x62f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r13, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
jmp 0xc0ba
movq %r13, %rdi
callq 0x189a0
movq %rax, 0xa8(%rbx)
movl $0x1, 0x4(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xc0d6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r15, %r15
movl 0x4(%rsp), %eax
jne 0xbeeb
jmp 0xc131
movq %rbx, %rdi
callq 0x9f1a
jmp 0xc133
movq 0x3aefa(%rip), %rbx     # 0x46ff0
leaq 0x294e3(%rip), %rsi     # 0x355e0
movl $0x45, %edx
movq %rbx, %rdi
callq 0x62f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xc169
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xc169
movq %rax, %r14
movl $0x40, %esi
movq %r13, %rdi
jmp 0xc18d
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xc1d4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xc1d4
jmp 0xc1d1
movq %rax, %r14
jmp 0xc1c0
movq %rax, %r14
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xc1c0
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0x40, %esi
movq %r12, %rdi
callq 0x6270
jmp 0xc1e8
jmp 0xc1e5
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
jne 0xc1f2
jmp 0xc1ff
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0xc1ff
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movq %r14, %rdi
callq 0x6460
nop