// File: /workspace/github_cpp_makefile_star2_O1/pranavmodx[P]modlang/src/evaluator.cpp
// Function: Evaluator::evalCallExpression(Object*, std::vector<Object*, std::allocator<Object*>>&)
Object *Evaluator::evalCallExpression(Object *fn, std::vector<Object *> &args)
{
	if (fn->type() != FUNCTION_OBJ && fn->type() != BUILTIN_OBJ)
		return new Error("error: not a function -> " + fn->type());

	if (fn->type() == BUILTIN_OBJ)
		return ((Builtin *)fn)->function(args);

	if (((Function *)fn)->parameters.size() != args.size())
		return new Error(
			"error: argument length (" + std::to_string(args.size()) +
			") not equal to parameter length (" + std::to_string(((Function *)fn)->parameters.size()) + ")");

	Environment *extendedEnv = extendFunctionEnv((Function *)fn, args, ((Function *)fn)->env);

	Object *evaluated = Eval(((Function *)fn)->body, extendedEnv);

	if (evaluated->type() == RETURN_VALUE_OBJ)
		return ((ReturnValue *)evaluated)->value;

	return evaluated;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq *(%rax)
movq 0x8(%r12), %rdx
movb $0x1, %bpl
cmpq 0x16f58(%rip), %rdx     # 0x381b8
jne 0x21282
testq %rdx, %rdx
je 0x21280
movq 0x16f42(%rip), %rsi     # 0x381b0
movq 0x8(%rsp), %rdi
callq 0x51d0
testl %eax, %eax
setne %bpl
jmp 0x21282
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x212cc
movq (%r14), %rax
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq *(%rax)
movq 0xf0(%rsp), %rdx
movb $0x1, %r12b
cmpq 0x1704f(%rip), %rdx     # 0x382f8
jne 0x212cf
testq %rdx, %rdx
je 0x212cc
movq 0x17039(%rip), %rsi     # 0x382f0
movq 0xe8(%rsp), %rdi
callq 0x51d0
testl %eax, %eax
setne %r12b
jmp 0x212cf
xorl %r12d, %r12d
testb %bpl, %bpl
je 0x212f5
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x212f5
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x51c0
leaq 0x18(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x21310
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
testb %r12b, %r12b
je 0x2137a
movl $0x28, %edi
callq 0x51b0
movq %rax, %rbx
movq (%r14), %rax
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq *(%rax)
leaq 0x8830(%rip), %rcx      # 0x29b66
leaq 0x8(%rsp), %rdi
movl $0x19, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x51f0
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x213c4
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x213cb
movq (%r14), %rax
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq *(%rax)
movq 0x8(%r12), %rdx
cmpq 0x16f62(%rip), %rdx     # 0x382f8
jne 0x213bd
testq %rdx, %rdx
je 0x2144d
movq 0x16f48(%rip), %rsi     # 0x382f0
movq 0x8(%rsp), %rdi
callq 0x51d0
testl %eax, %eax
sete %bpl
jmp 0x21450
xorl %ebp, %ebp
jmp 0x21450
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x90(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x136ab(%rip), %rax     # 0x34a98
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
movq %rbx, %rax
addq $0x18, %rax
movq %rax, 0x8(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
callq 0xbde8
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x21434
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21476
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21476
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21467
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
testb %bpl, %bpl
je 0x2148b
movq %r15, %rdi
callq *0x8(%r14)
movq %rax, %rbx
movq %rbx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r14), %rax
subq 0x8(%r14), %rax
movq 0x8(%r15), %r12
subq (%r15), %r12
cmpq %r12, %rax
jne 0x21503
movq 0x28(%r14), %rcx
movq %r14, %rsi
movq %r15, %rdx
callq 0x23a1c
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x1ef50
movq %rax, %rbx
movq (%rax), %rax
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq *(%rax)
movq 0x8(%r14), %rdx
cmpq 0x16dfd(%rip), %rdx     # 0x382d8
jne 0x21567
testq %rdx, %rdx
je 0x2156b
movq 0x16ddf(%rip), %rsi     # 0x382d0
movq 0x8(%rsp), %rdi
callq 0x51d0
testl %eax, %eax
sete %bpl
jmp 0x2156e
sarq $0x3, %r12
movl $0x28, %edi
callq 0x51b0
movq %rax, %rbx
movl $0x1, %esi
cmpq $0xa, %r12
jb 0x2159e
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r12, %rcx
cmpq $0x63, %rcx
jbe 0x21597
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x2159c
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x2159e
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x21531
addl $-0x3, %esi
jmp 0x2159e
xorl %ebp, %ebp
jmp 0x2156e
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21585
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
testb %bpl, %bpl
je 0x21476
movq 0x8(%rbx), %rbx
jmp 0x21476
addl $-0x2, %esi
jmp 0x2159e
decl %esi
movl %esi, %esi
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xa8(%rsp), %rdi
xorl %edx, %edx
callq 0x5210
leaq 0xa8(%rsp), %r15
movq (%r15), %rdi
movl 0x8(%r15), %esi
movq %r12, %rdx
callq 0x249c3
leaq 0x8191(%rip), %rcx      # 0x2976a
movl $0x18, %r8d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x51f0
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2161c
movq %rdx, 0xc8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd8(%rsp)
jmp 0x21624
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0xc8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x8536(%rip), %rsi      # 0x29b80
callq 0x5360
leaq 0x58(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x21676
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x2167d
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x10(%r14), %r15
subq 0x8(%r14), %r15
sarq $0x3, %r15
movl $0x1, %esi
cmpq $0xa, %r15
jb 0x216fb
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x216f4
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x216f9
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x216fb
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x216be
addl $-0x3, %esi
jmp 0x216fb
addl $-0x2, %esi
jmp 0x216fb
decl %esi
movl %esi, %esi
leaq 0x38(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28(%rsp), %rdi
xorl %edx, %edx
callq 0x5210
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
movq %r15, %rdx
callq 0x249c3
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x30(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %rbp, %rcx
je 0x21745
movq 0x58(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x21760
movl $0xf, %esi
cmpq %r14, 0x28(%rsp)
je 0x2175b
movq 0x38(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x21771
movq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x50b0
jmp 0x2177f
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x51f0
movq %r13, 0x8(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x2179f
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x217a7
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x830c(%rip), %rsi      # 0x29ad7
leaq 0x8(%rsp), %rdi
callq 0x5360
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x217fc
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x21803
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x70(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x13276(%rip), %rax     # 0x34a98
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
movq %rbx, %rax
addq $0x18, %rax
movq %rax, 0x8(%rbx)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
callq 0xbde8
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2185d
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21874
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x2188b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x218a2
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
leaq 0xb8(%rsp), %r12
je 0x218c7
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x21476
movq 0xb8(%rsp), %rsi
jmp 0x21443
movq %rax, (%rsp)
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x21906
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21906
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21923
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21923
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x21940
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21940
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2195d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x2195d
movq %rax, (%rsp)
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x21980
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21980
movq %rax, (%rsp)
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x219e5
movq 0xb8(%rsp), %rsi
jmp 0x219d7
jmp 0x219e1
movq %rax, (%rsp)
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x219c8
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x219c8
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x219e5
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x219e5
movq %rax, (%rsp)
movl $0x28, %esi
movq %rbx, %rdi
callq 0x51c0
movq (%rsp), %rdi
callq 0x5330
movq %rax, (%rsp)
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x219f2
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x219ed
nop