// File: /workspace/github_c_makefile_star2_O0/mattn[P]orelang/ore.c
// Function: ore_call
static ore_value
ore_call(ore_context* ore, mpc_ast_t *t) {
  ore_value fn;
  const char* pfn = NULL;
  if (is_a(t->children[0], "ident")) {
    pfn = t->children[0]->contents;
    fn = ore_get(ore, pfn);
  } else if (is_a(t->children[0], "prop")) {
    pfn = t->children[0]->children[2]->contents;
    fn = ore_eval(ore, t->children[0]);
    if (fn.t == ORE_TYPE_NIL) {
      // FIXME
      ore_context* tmp = ore;
      ore_value inst = ore_eval(tmp, t->children[0]->children[0]);
      while (1) {
        inst = ore_prop(inst.v.o->e, "super");
        if (inst.t == ORE_TYPE_NIL)
          break;
        fn = ore_prop(inst.v.o->e, pfn);
        if (fn.t == ORE_TYPE_FUNC || fn.t == ORE_TYPE_CFUNC) {
          break;
        }
      }
    }
  } else {
    pfn = "<anonymous>";
    fn = ore_eval(ore, t->children[0]);
  }
  if (ore->err != ORE_ERROR_NONE)
    return ore_value_nil();
  if (fn.t != ORE_TYPE_FUNC && fn.t != ORE_TYPE_CFUNC) {
    fprintf(stderr, "unknown function '%s'\n", pfn);
    ore->err = ORE_ERROR_EXCEPTION;
    return ore_value_nil();
  }
  ore_value v = ore_value_nil();
  switch (fn.t) {
    case ORE_TYPE_CFUNC:
      {
        int num_in = t->children_num / 2 - 1, n = 0, i;
        if (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);
          ore->err = ORE_ERROR_EXCEPTION;
          return ore_value_nil();
        }
        ore_value* args = (ore_value*) malloc(sizeof(ore_value) * num_in);
        if (!args) {
          fprintf(stderr, "failed to allocate memory\n");
          ore->err = ORE_ERROR_EXCEPTION;
          return ore_value_nil();
        }
        for (i = 2; i < t->children_num - 1; i += 2) {
          args[n++] = ore_eval(ore, t->children[i]);
        }
        v = ((ore_cfunc_t)fn.v.f.x.c) ((ore_context*) ore, num_in, args, fn.v.f.u);
        free(args);
      }
      break;
    case ORE_TYPE_FUNC:
      {
        ore_context* env = ore_new((ore_context*) fn.v.f.ore);
        mpc_ast_t* stmts = ore_find_statements(fn.v.f.x.o);
        if (stmts) {
          ore_value* args = ore_bind_args(ore, fn.v.f.x.o, env, t);
          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));
          free(args);
        }
      }
      break;
    default:
      fprintf(stderr, "invalid function call\n");
      ore->err = ORE_ERROR_EXCEPTION;
      return ore_value_nil();
  }
  return v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x288(%rbp)
movq %rdi, -0x280(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq (%rax), %rdi
leaq 0x38b4(%rip), %rsi      # 0x1ac22
callq 0x2260
cmpq $0x0, %rax
je 0x173b4
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x10a30
leaq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
jmp 0x17522
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq (%rax), %rdi
leaq 0x3899(%rip), %rsi      # 0x1ac62
callq 0x2260
cmpq $0x0, %rax
je 0x174e5
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdx
leaq -0x90(%rbp), %rdi
callq 0x119b0
leaq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
cmpl $0x0, -0x38(%rbp)
jne 0x174e3
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x119b0
movq -0xb8(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0xe8(%rbp), %rdi
leaq 0x4d97(%rip), %rdx      # 0x1c20d
callq 0x10850
leaq -0xc0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
cmpl $0x0, -0xc0(%rbp)
jne 0x1749e
jmp 0x174e1
movq -0xb8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x40(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x10850
leaq -0x38(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
cmpl $0x8, -0x38(%rbp)
je 0x174da
cmpl $0x9, -0x38(%rbp)
jne 0x174dc
jmp 0x174e1
jmp 0x1745d
jmp 0x174e3
jmp 0x17520
leaq 0x4d2c(%rip), %rax      # 0x1c218
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdx
leaq -0x138(%rbp), %rdi
callq 0x119b0
leaq -0x38(%rbp), %rdi
leaq -0x138(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
jmp 0x17522
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x1753d
movq -0x288(%rbp), %rdi
callq 0x10670
jmp 0x178d8
cmpl $0x8, -0x38(%rbp)
je 0x17581
cmpl $0x9, -0x38(%rbp)
je 0x17581
movq 0x9aa8(%rip), %rax      # 0x20ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0x4cc6(%rip), %rsi      # 0x1c224
movb $0x0, %al
callq 0x2140
movq -0x288(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
callq 0x10670
jmp 0x178d8
leaq -0x160(%rbp), %rdi
callq 0x10670
movl -0x38(%rbp), %eax
movl %eax, -0x28c(%rbp)
subl $0x8, %eax
je 0x17763
jmp 0x175a1
movl -0x28c(%rbp), %eax
subl $0x9, %eax
jne 0x1788f
jmp 0x175b2
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
subl $0x1, %eax
movl %eax, -0x164(%rbp)
movl $0x0, -0x168(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x175f0
cmpl $-0x1, -0x24(%rbp)
je 0x1762d
movl -0x164(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x1762d
movq 0x9a01(%rip), %rax      # 0x20ff8
movq (%rax), %rdi
movl -0x164(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x35e8(%rip), %rsi      # 0x1abf2
movb $0x0, %al
callq 0x2140
movq -0x288(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
callq 0x10670
jmp 0x178d8
movslq -0x164(%rbp), %rax
imulq $0x28, %rax, %rdi
callq 0x2190
movq %rax, -0x178(%rbp)
cmpq $0x0, -0x178(%rbp)
jne 0x17682
movq 0x99a3(%rip), %rax      # 0x20ff8
movq (%rax), %rdi
leaq 0x355f(%rip), %rsi      # 0x1abbe
movb $0x0, %al
callq 0x2140
movq -0x288(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
callq 0x10670
jmp 0x178d8
movl $0x2, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x28(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x17718
movq -0x178(%rbp), %rax
movl -0x168(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x168(%rbp)
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x298(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x16c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq -0x1a0(%rbp), %rdi
callq 0x119b0
movq -0x298(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
movl -0x16c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x16c(%rbp)
jmp 0x1768c
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rsi
movl -0x164(%rbp), %edx
movq -0x178(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq -0x1c8(%rbp), %rdi
callq *%rax
leaq -0x160(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
movq -0x178(%rbp), %rdi
callq 0x2280
jmp 0x178c0
movq -0x30(%rbp), %rdi
callq 0x11230
movq %rax, -0x1d0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x17ab0
movq %rax, -0x1d8(%rbp)
cmpq $0x0, -0x1d8(%rbp)
je 0x1788d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
movq -0x10(%rbp), %rcx
callq 0x188f0
movq %rax, -0x1e0(%rbp)
movq -0x1d0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x208(%rbp), %rdi
callq 0x119b0
leaq -0x160(%rbp), %rdi
leaq -0x208(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
movq -0x1d0(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x17800
movq -0x1d0(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
leaq -0x250(%rbp), %rdi
movq -0x1d0(%rbp), %rax
movq (%rax), %rdx
leaq 0x3410(%rip), %rsi      # 0x1ac28
movb $0x0, %al
callq 0x2220
movq -0x8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x250(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x1d0(%rbp), %rsi
leaq -0x278(%rbp), %rdi
callq 0x10720
movq -0x2a8(%rbp), %rdi
movq -0x2a0(%rbp), %rsi
movq -0x258(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x278(%rbp), %xmm0
movups -0x268(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x11030
movq -0x1e0(%rbp), %rdi
callq 0x2280
jmp 0x178c0
movq 0x9762(%rip), %rax      # 0x20ff8
movq (%rax), %rdi
leaq 0x499b(%rip), %rsi      # 0x1c23b
movb $0x0, %al
callq 0x2140
movq -0x288(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
callq 0x10670
jmp 0x178d8
movq -0x288(%rbp), %rdi
leaq -0x160(%rbp), %rsi
movl $0x28, %edx
callq 0x2170
movq -0x280(%rbp), %rax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
nopl (%rax,%rax)