// File: /workspace/github_c_makefile_star2_O2/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 $0xf8, %rsp
movq %rcx, %r12
movl %edx, %r14d
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
movl 0x140(%rsp), %ecx
movl 0x144(%rsp), %ebx
cmpl $-0x1, %ecx
setne %al
cmpl %edx, %ecx
setg %dl
testb %dl, %al
jne 0xaf97
cmpl $-0x1, %ebx
sete %al
cmpl %r14d, %ebx
setge %dl
orb %al, %dl
je 0xaf97
movq %r13, 0x58(%rsp)
leaq 0x130(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0xaca5
movq %rax, 0x38(%rsp)
movq 0x18(%rbx), %rbp
movq $0x0, 0x50(%rsp)
testl %r14d, %r14d
movl $0x0, %eax
movl %r14d, 0x4c(%rsp)
cmovgl %r14d, %eax
imulq $0x28, %rax, %r15
pushq $0x2
popq %r13
movq %rbp, 0x40(%rsp)
movslq 0x28(%rbp), %r14
cmpq %r14, %r13
jge 0xafee
movq 0x30(%rbp), %rax
movq (%rax,%r13,8), %rbx
movq (%rbx), %rbp
movq %rbp, %rdi
leaq 0x5c3b(%rip), %rsi      # 0x10aa3
callq 0x2290
testq %rax, %rax
je 0xaf0a
callq 0xb0dd
movq %rax, %rbp
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0xaeae
movq %rbp, %rdi
callq 0xb123
movups (%r12,%rbx), %xmm0
movups 0x10(%r12,%rbx), %xmm1
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
movq 0x20(%r12,%rbx), %rcx
movq %rcx, 0x20(%rax)
addq $0x28, %rbx
jmp 0xae80
movq 0x40(%rsp), %rcx
movq 0x30(%rcx), %rax
movq -0x8(%rax,%r13,8), %rax
movq 0x8(%rax), %rbx
leaq 0x60(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %rcx, %rbp
callq 0xb14a
movq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0xaad0
incq %r13
jmp 0xae46
movq %rbp, %rdi
leaq 0x5b96(%rip), %rsi      # 0x10aaa
callq 0x2290
testq %rax, %rax
je 0xaf65
movq 0x50(%rsp), %rcx
cmpl 0x4c(%rsp), %ecx
movq 0x40(%rsp), %rbp
jge 0xaf02
movq 0x8(%rbx), %rsi
movslq %ecx, %rax
incl %ecx
movq %rcx, 0x50(%rsp)
imulq $0x28, %rax, %rax
movq 0x20(%r12,%rax), %rcx
movq %rcx, 0x20(%rsp)
movups (%r12,%rax), %xmm0
movups 0x10(%r12,%rax), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x38(%rsp), %rdi
jmp 0xaefd
movq %rbp, %rdi
leaq 0x5589(%rip), %rsi      # 0x104f8
callq 0x2290
testq %rax, %rax
je 0xaf8d
movq 0x8(%rbx), %rax
cmpb $0x7b, (%rax)
movq 0x40(%rsp), %rbp
jne 0xaf02
jmp 0xafeb
movq 0x40(%rsp), %rbp
jmp 0xaf02
movl %r14d, %ebp
movq 0xd057(%rip), %r14      # 0x17ff8
movq (%r14), %rdi
leaq 0x5acf(%rip), %r15      # 0x10a7a
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2160
movq (%r14), %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2160
movq 0x30(%rsp), %rax
movl $0x1, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movups %xmm0, 0x10(%r13)
andq $0x0, 0x20(%r13)
jmp 0xb0c8
incq %r13
movslq %r13d, %r15
xorl %ebx, %ebx
leaq 0x54fe(%rip), %r12      # 0x104f8
movq 0x58(%rsp), %r13
cmpq %r14, %r15
jge 0xb028
testq %rbx, %rbx
jne 0xb023
movq 0x30(%rbp), %rax
movq (%rax,%r15,8), %rbx
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x2290
testq %rax, %rax
je 0xb023
xorl %ebx, %ebx
incq %r15
jmp 0xafff
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
andq $0x0, 0x20(%r13)
testq %rbx, %rbx
je 0xb0c8
movq %r13, %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0xb1b8
cmpl $0x1, 0x20(%r14)
jne 0xb069
movq 0x30(%rsp), %rax
movl $0x1, 0x20(%rax)
movq 0x38(%rsp), %r14
movq (%r14), %rdx
leaq 0x5a38(%rip), %rsi      # 0x10ab0
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2240
leaq 0x88(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0xa564
movq 0x20(%r12), %rax
movq %rax, 0x20(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xaad0
movq %r13, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq