// File: /workspace/github_cpp_makefile_star2_O3/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 $0xe8, %rsp
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
cmpq 0x17195(%rip), %rdx     # 0x381b8
jne 0x21042
movq 0x8(%rsp), %r12
testq %rdx, %rdx
je 0x21088
movq 0x1717a(%rip), %rsi     # 0x381b0
movq %r12, %rdi
callq 0x51d0
testl %eax, %eax
je 0x21088
movq (%r14), %rax
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq *(%rax)
movq 0x30(%rsp), %rdx
cmpq 0x1729d(%rip), %rdx     # 0x382f8
jne 0x2107e
movq 0x28(%rsp), %r12
testq %rdx, %rdx
je 0x2108c
movq 0x17282(%rip), %rsi     # 0x382f0
movq %r12, %rdi
callq 0x51d0
testl %eax, %eax
setne %bpl
jmp 0x2108e
movb $0x1, %bpl
movq 0x28(%rsp), %r12
jmp 0x2108e
xorl %ebp, %ebp
jmp 0x210ad
xorl %ebp, %ebp
leaq 0x38(%rsp), %rax
cmpq %rax, %r12
je 0x210a8
movq 0x38(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x51c0
movq 0x8(%rsp), %r12
leaq 0x18(%rsp), %r13
cmpq %r13, %r12
je 0x210c7
movq 0x18(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x51c0
testb %bpl, %bpl
je 0x21131
movl $0x28, %edi
callq 0x51b0
movq %rax, %rbx
movq (%r14), %rax
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq *(%rax)
leaq 0x8a89(%rip), %rcx      # 0x29b76
leaq 0x8(%rsp), %rdi
movl $0x19, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x51f0
leaq 0xd8(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x21180
movq %rsi, 0xc8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd8(%rsp)
jmp 0x2118a
movq (%r14), %rax
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq *(%rax)
movq 0x8(%r12), %rdx
cmpq 0x171ab(%rip), %rdx     # 0x382f8
jne 0x21177
movq 0x8(%rsp), %r12
testq %rdx, %rdx
je 0x211fc
movq 0x1718c(%rip), %rsi     # 0x382f0
movq %r12, %rdi
callq 0x51d0
testl %eax, %eax
sete %bpl
jmp 0x211ff
movq 0x8(%rsp), %r12
xorl %ebp, %ebp
jmp 0x211ff
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0xd0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x138ec(%rip), %rax     # 0x34a98
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
movq %rbx, %rax
addq $0x18, %rax
movq %rax, 0x8(%rbx)
addq %rsi, %rdx
callq 0xbdc6
movq 0xc8(%rsp), %rdi
cmpq %r14, %rdi
je 0x211e3
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21223
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21223
movb $0x1, %bpl
cmpq %r13, %r12
je 0x21214
movq 0x18(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x51c0
testb %bpl, %bpl
je 0x21238
movq %r15, %rdi
callq *0x8(%r14)
movq %rax, %rbx
movq %rbx, %rax
addq $0xe8, %rsp
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 0x212b3
movq 0x28(%r14), %rcx
movq %r14, %rsi
movq %r15, %rdx
callq 0x23724
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x1ed4a
movq %rax, %rbx
movq (%rax), %rax
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq *(%rax)
movq 0x8(%r14), %rdx
cmpq 0x17050(%rip), %rdx     # 0x382d8
jne 0x2131b
movq 0x8(%rsp), %r14
testq %rdx, %rdx
je 0x21324
movq 0x1702d(%rip), %rsi     # 0x382d0
movq %r14, %rdi
callq 0x51d0
testl %eax, %eax
sete %bpl
jmp 0x21327
sarq $0x3, %r12
movl $0x28, %edi
callq 0x51b0
movq %rax, %rbx
movl $0x1, %esi
cmpq $0xa, %r12
jb 0x21355
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r12, %rcx
cmpq $0x63, %rcx
jbe 0x2134e
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x21353
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x21355
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x212e5
addl $-0x3, %esi
jmp 0x21355
movq 0x8(%rsp), %r14
xorl %ebp, %ebp
jmp 0x21327
movb $0x1, %bpl
cmpq %r13, %r14
je 0x2133c
movq 0x18(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x51c0
testb %bpl, %bpl
je 0x21223
movq 0x8(%rbx), %rbx
jmp 0x21223
addl $-0x2, %esi
jmp 0x21355
decl %esi
movl %esi, %esi
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x88(%rsp), %rdi
xorl %edx, %edx
callq 0x5210
leaq 0x88(%rsp), %r15
movq (%r15), %rdi
movl 0x8(%r15), %esi
movq %r12, %rdx
callq 0x246bf
leaq 0x83ea(%rip), %rcx      # 0x2977a
movl $0x18, %r8d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x51f0
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x213d3
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x213db
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0xa8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x878f(%rip), %rsi      # 0x29b90
callq 0x5360
leaq 0x38(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2142d
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x21434
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%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 0x214b2
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x214ab
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x214b0
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x214b2
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x21475
addl $-0x3, %esi
jmp 0x214b2
addl $-0x2, %esi
jmp 0x214b2
decl %esi
movl %esi, %esi
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x48(%rsp), %rdi
xorl %edx, %edx
callq 0x5210
movq 0x48(%rsp), %rdi
movl 0x50(%rsp), %esi
movq %r15, %rdx
callq 0x246bf
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x50(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %rbp, %rcx
je 0x214fc
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x2151a
movl $0xf, %edi
cmpq %r14, %rsi
je 0x21515
movq 0x58(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x21526
leaq 0x28(%rsp), %rdi
callq 0x50b0
jmp 0x21534
leaq 0x48(%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 0x21554
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x2155c
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 0x8567(%rip), %rsi      # 0x29ae7
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 0x215b1
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x215b8
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 0x134c1(%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 0xbdc6
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x21612
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21629
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x21640
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x21657
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
leaq 0x98(%rsp), %r12
je 0x2167c
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x51c0
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x21223
movq 0x98(%rsp), %rsi
jmp 0x211f2
movq %rax, (%rsp)
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x216bb
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x216bb
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x216d8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x216d8
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x216f5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x216f5
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x21712
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21712
movq %rax, (%rsp)
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x21735
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x21735
movq %rax, (%rsp)
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x2179a
movq 0x98(%rsp), %rsi
jmp 0x2178c
jmp 0x21796
movq %rax, (%rsp)
movq 0xc8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2177d
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x2177d
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2179a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x51c0
jmp 0x2179a
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 0x217a7
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x217a2