// File: /workspace/github_c_makefile_star2_O3/mattn[P]orelang/ore.c
// Function: ore_func_call
ore_value
ore_func_call(ore_context* ore, ore_value fn, int num_in, ore_value* args) {
  if ((fn.v.f.num_in != -1 && num_in < fn.v.f.num_in) || (fn.v.f.max_in != -1 && num_in > fn.v.f.max_in)) {
    fprintf(stderr, "number of arguments mismatch: %d for %d\n",
      num_in, fn.v.f.num_in);
    fprintf(stderr, "number of arguments mismatch: %d for %d\n",
      num_in, fn.v.f.max_in);
    ore->err = ORE_ERROR_EXCEPTION;
    return ore_value_nil();
  }

  ore_context* env = ore_new((ore_context*) fn.v.f.ore);
  mpc_ast_t* stmts = NULL;
  mpc_ast_t* f = fn.v.f.x.o;
  int n = 0, i;
  for (i = 2; i < f->children_num; i++) {
    if (is_a(f->children[i], "vararg")) {
      ore_array_t* a = kl_init(value);
      int j;
      for (j = 0; j < num_in; j++) {
        *kl_pushp(value, a) = args[j];
      }
      ore_define(env, f->children[i-1]->contents, ore_value_array_from_klist(ore, a));
    } else if (is_a(f->children[i], "ident")) {
      if (n < num_in)
        ore_define(env, f->children[i]->contents, args[n++]);
    } else if (is_a(f->children[i], "char")) {
      if (f->children[i]->contents[0] == '{') {
        i++;
        break;
      }
    }
  }
  for (; i < f->children_num; i++) {
    if (stmts == NULL && !is_a(f->children[i], "char")) {
      stmts = f->children[i];
    }
  }
  ore_value v = ore_value_nil();
  if (stmts) {
    v = ore_eval(env, stmts);
    if (env->err == ORE_ERROR_EXCEPTION)
      ore->err = env->err;
    char buf[64];
    sprintf(buf, "0x%p", env->env);
    ore_define(ore, buf, ore_value_env_from_context(env));
  }
  return v;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, %r13
movl %edx, %r14d
movq %rsi, 0x28(%rsp)
movq %rdi, %r12
movl 0x150(%rsp), %ecx
movl 0x154(%rsp), %ebx
cmpl $-0x1, %ecx
setne %al
cmpl %edx, %ecx
setg %dl
testb %dl, %al
jne 0xdb19
cmpl $-0x1, %ebx
sete %al
cmpl %r14d, %ebx
setge %dl
orb %al, %dl
je 0xdb19
leaq 0x140(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0xd661
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rbp
movl 0x28(%rbp), %edx
movl $0x2, %r15d
cmpl $0x3, %edx
jl 0xda1e
movq %r12, 0x50(%rsp)
leal -0x1(%r14), %ecx
leaq 0x1(%rcx), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x58(%rsp)
movl %r14d, %eax
addq $0x2, %rcx
movq %rcx, 0x68(%rsp)
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
xorl %ebx, %ebx
movl $0x2, %r15d
movq %rbp, 0x38(%rsp)
movq %rdx, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
movq 0x30(%rbp), %rbp
movq (%rbp,%r15,8), %r14
movq (%r14), %rbx
movq %rbx, %rdi
leaq 0x72e3(%rip), %rsi      # 0x14b2f
callq 0x2290
testq %rax, %rax
je 0xd97f
movl $0x1, %edi
movl $0x20, %esi
callq 0x2140
movq %rax, %rbx
movl $0x1, %edi
movl $0x20, %esi
callq 0x2140
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq $0x1, (%rax)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, 0x8(%rbx)
movq %rax, (%rbx)
cmpl $0x0, 0x58(%rsp)
jle 0xd915
movq %r14, 0x48(%rsp)
xorl %ebp, %ebp
movq %rax, %r14
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq $0x0, 0x28(%rax)
movq %rax, 0x28(%r14)
movq 0x20(%r13,%rbp), %rcx
movq %rcx, 0x20(%r14)
movups (%r13,%rbp), %xmm0
movups 0x10(%r13,%rbp), %xmm1
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
addq $0x28, %rbp
cmpq %rbp, %r12
jne 0xd8ad
movq %rax, 0x8(%rbx)
movq 0x68(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rbx)
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rbp
movq -0x8(%rbp,%r15,8), %rax
movq 0x8(%rax), %r14
leaq 0x70(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0xdc1f
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x70(%rsp), %xmm0
movups 0x80(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0xd3c9
movq 0x38(%rsp), %rbp
movq 0x40(%rsp), %rbx
incq %r15
movslq 0x28(%rbp), %rdx
cmpq %rdx, %r15
jl 0xd82c
jmp 0xda19
movq %rbx, %rdi
leaq 0x71ad(%rip), %rsi      # 0x14b36
callq 0x2290
testq %rax, %rax
je 0xd9db
movq 0x40(%rsp), %rbx
cmpl 0x58(%rsp), %ebx
movq 0x38(%rsp), %rbp
jge 0xd96a
movq 0x8(%r14), %rsi
movslq %ebx, %rax
incl %ebx
leaq (%rax,%rax,4), %rax
movq 0x20(%r13,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
movups (%r13,%rax,8), %xmm0
movups 0x10(%r13,%rax,8), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
callq 0xd3c9
jmp 0xd96a
movq %rbx, %rdi
leaq 0x6b23(%rip), %rsi      # 0x14508
callq 0x2290
testq %rax, %rax
movq 0x38(%rsp), %rbp
je 0xd965
movq 0x8(%r14), %rax
cmpb $0x7b, (%rax)
movq 0x40(%rsp), %rbx
jne 0xd96a
incl %r15d
movq 0x50(%rsp), %r12
movq 0x48(%rsp), %rdx
jmp 0xda1e
movq 0x50(%rsp), %r12
cmpl %edx, %r15d
jge 0xdb09
movq %r12, %r13
movl %r15d, %r15d
movl %edx, %r12d
xorl %ebx, %ebx
leaq 0x6acf(%rip), %r14      # 0x14508
testq %rbx, %rbx
jne 0xda58
movq 0x30(%rbp), %rax
movq (%rax,%r15,8), %rbx
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x2290
testq %rax, %rax
je 0xda58
xorl %ebx, %ebx
incq %r15
cmpq %r15, %r12
jne 0xda39
xorps %xmm0, %xmm0
movq %r13, %r15
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movq $0x0, 0x20(%r13)
testq %rbx, %rbx
je 0xdb04
movq %r15, %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdc73
cmpl $0x1, 0x20(%r14)
jne 0xdaa7
movq 0x28(%rsp), %rax
movl $0x1, 0x20(%rax)
movq 0x30(%rsp), %r12
movq (%r12), %rdx
leaq 0x7085(%rip), %rsi      # 0x14b3c
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2240
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0xcc04
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3c9
movq %r15, %rax
jmp 0xdb72
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
jmp 0xdb66
movq 0xe4d8(%rip), %r15      # 0x1bff8
movq (%r15), %rdi
movq %r14, %r13
leaq 0x6fd9(%rip), %r14      # 0x14b06
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2160
movq (%r15), %rdi
movq %r14, %rsi
movl %r13d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2160
movq 0x28(%rsp), %rax
movl $0x1, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movups %xmm0, 0x10(%r12)
movq $0x0, 0x20(%r12)
movq %r12, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq