// File: /workspace/github_c_makefile_star2_O2/mtnygard[P]complisp/lisp.c
// Function: Compile_call
int Compile_call(Buffer *buf, ASTNode *callable, ASTNode *args,
                 word stack_index, Env *varenv, Env *labels) {
  if (AST_is_symbol(callable)) {
    if (AST_symbol_matches(callable, "labelcall")) {
      ASTNode *label = operand1(args);
      assert(AST_is_symbol(label));
      ASTNode *call_args = AST_pair_cdr(args);
      word nargs = list_length(call_args);

      return Compile_labelcall(buf, label, call_args, stack_index - kWordSize,
                               varenv, labels, nargs, stack_index + kWordSize);
    }
    if (AST_symbol_matches(callable, "let")) {
      return Compile_let(buf, operand1(args), operand2(args), stack_index,
                         varenv, varenv, labels);
    }
    if (AST_symbol_matches(callable, "if")) {
      return Compile_if(buf, operand1(args), operand2(args), operand3(args),
                        stack_index, varenv, labels);
    }
    if (AST_symbol_matches(callable, "cons")) {
      return Compile_cons(buf, operand1(args), operand2(args), stack_index,
                          varenv, labels);
    }
    if (AST_symbol_matches(callable, "car")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_load_reg_indirect(buf, kRax, Ind(kRax, kCarOffset - kPairTag));
      return 0;
    }
    if (AST_symbol_matches(callable, "cdr")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_load_reg_indirect(buf, kRax, Ind(kRax, kCdrOffset - kPairTag));
      return 0;
    }
    if (AST_symbol_matches(callable, "add1")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_add_reg_imm32(buf, kRax, Object_encode_integer(1));
      return 0;
    }
    if (AST_symbol_matches(callable, "sub1")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_sub_reg_imm32(buf, kRax, Object_encode_integer(1));
      return 0;
    }
    if (AST_symbol_matches(callable, "integer->char")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_shl_reg_imm8(buf, kRax, kCharShift - kIntegerShift);
      Emit_or_reg_imm8(buf, kRax, kCharTag);
      return 0;
    }
    if (AST_symbol_matches(callable, "char->integer")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_shr_reg_imm8(buf, kRax, kCharShift - kIntegerShift);
      return 0;
    }
    if (AST_symbol_matches(callable, "nil?")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_cmp_reg_imm32(buf, kRax, Object_nil());
      Emit_mov_reg_imm32(buf, kRax, 0);
      Emit_setcc_imm8(buf, kEqual, kAl);
      Emit_shl_reg_imm8(buf, kRax, kBoolShift);
      Emit_or_reg_imm8(buf, kRax, kBoolTag);
      return 0;
    }
    if (AST_symbol_matches(callable, "zero?")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Compile_compare_imm32(buf, Object_encode_integer(0));
      return 0;
    }
    if (AST_symbol_matches(callable, "not")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Compile_compare_imm32(buf, Object_false());
      return 0;
    }
    if (AST_symbol_matches(callable, "integer?")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_and_reg_imm8(buf, kRax, kIntegerTagMask);
      Compile_compare_imm32(buf, kIntegerTag);
      return 0;
    }
    if (AST_symbol_matches(callable, "boolean?")) {
      _(Compile_expr(buf, operand1(args), stack_index, varenv, labels));
      Emit_and_reg_imm8(buf, kRax, kImmediateTagMask);
      Compile_compare_imm32(buf, kBoolTag);
      return 0;
    }
    if (AST_symbol_matches(callable, "+")) {
      _(Compile_expr(buf, operand2(args), stack_index, varenv, labels));
      Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
      _(Compile_expr(buf, operand1(args), stack_index - kWordSize, varenv,
                     labels));
      Emit_add_reg_indirect(buf, kRax, Ind(kRsp, stack_index));
      return 0;
    }
    if (AST_symbol_matches(callable, "-")) {
      _(Compile_expr(buf, operand2(args), stack_index, varenv, labels));
      Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
      _(Compile_expr(buf, operand1(args), stack_index - kWordSize, varenv,
                     labels));
      Emit_sub_reg_indirect(buf, kRax, Ind(kRsp, stack_index));
      return 0;
    }
    if (AST_symbol_matches(callable, "*")) {
      _(Compile_expr(buf, operand2(args), stack_index, varenv, labels));
      // Remove the tag so that the result is still only tagged with 0b00
      // instead of 0b0000
      Emit_shr_reg_imm8(buf, kRax, kIntegerShift);
      Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
      _(Compile_expr(buf, operand1(args), stack_index - kWordSize, varenv,
                     labels));
      Emit_mul_reg_indirect(buf, Ind(kRsp, stack_index));
      return 0;
    }
    if (AST_symbol_matches(callable, "=")) {
      _(Compile_expr(buf, operand2(args), stack_index, varenv, labels));
      Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
      _(Compile_expr(buf, operand1(args), stack_index - kWordSize, varenv,
                     labels));
      Emit_cmp_reg_indirect(buf, kRax, Ind(kRsp, stack_index));
      Emit_mov_reg_imm32(buf, kRax, 0);
      Emit_setcc_imm8(buf, kEqual, kAl);
      Emit_shl_reg_imm8(buf, kRax, kBoolShift);
      Emit_or_reg_imm8(buf, kRax, kBoolTag);
      return 0;
    }
    if (AST_symbol_matches(callable, "<")) {
      _(Compile_expr(buf, operand2(args), stack_index, varenv, labels));
      Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
      _(Compile_expr(buf, operand1(args), stack_index - kWordSize, varenv,
                     labels));
      Emit_cmp_reg_indirect(buf, kRax, Ind(kRsp, stack_index));
      Emit_mov_reg_imm32(buf, kRax, 0);
      Emit_setcc_imm8(buf, kLess, kAl);
      Emit_shl_reg_imm8(buf, kRax, kBoolShift);
      Emit_or_reg_imm8(buf, kRax, kBoolTag);
      return 0;
    }
  }
  assert(0 && "unexpected call type");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, -0x30(%rbp)
movq %rsi, %rbx
movl %ebx, %eax
andl $0x7, %eax
cmpl $0x5, %eax
jne 0x294b
movq %r9, %r15
movq %r8, %r12
movq %rcx, %r13
movq %rdi, %r14
leaq 0xb643(%rip), %rsi      # 0xd7d8
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2200
movq %r15, -0x38(%rbp)
movq %r14, %r15
movq %r13, %r14
movq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x15ee
movq %rax, %rbx
andl $0x7, %eax
cmpl $0x5, %eax
jne 0x29f2
movq %r13, %rdi
callq 0x15fc
movq %rax, %r13
movq %rax, %rdi
callq 0x2bc7
leaq -0x8(%r14), %rcx
addq $0x8, %r14
movq %r14, 0x8(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %r8
movq -0x38(%rbp), %r9
callq 0x2c15
jmp 0x293c
leaq 0xc11a(%rip), %rsi      # 0xe321
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2252
movq %r13, -0x38(%rbp)
movq %r14, %r13
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x15ee
movq %rax, %rbx
movq %r14, %rdi
callq 0x1fdb
movq %r15, (%rsp)
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq -0x38(%rbp), %rcx
movq %r12, %r8
movq %r12, %r9
callq 0x2d33
jmp 0x293c
leaq 0xc12c(%rip), %rsi      # 0xe385
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x22ae
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x15ee
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
callq 0x1fdb
movq %r12, -0x40(%rbp)
movq %rax, %r12
movq %rbx, %rdi
callq 0x1fed
movq %r15, (%rsp)
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
movq %rax, %rcx
movq %r13, %r8
movq -0x40(%rbp), %r9
callq 0x2a11
jmp 0x293c
leaq 0xc100(%rip), %rsi      # 0xe3b5
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2305
movq %r15, -0x38(%rbp)
movq %r14, %r15
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x15ee
movq %rax, %rbx
movq %r14, %rdi
callq 0x1fdb
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movl %r13d, %ecx
movq %r12, %r8
movq -0x38(%rbp), %r9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ae7
leaq 0xc0b6(%rip), %rsi      # 0xe3c2
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x234c
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
movabsq $0xff00000000, %rdx     # imm = 0xFF00000000
jmp 0x2391
leaq 0xc07b(%rip), %rsi      # 0xe3ce
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x23a0
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
movabsq $0x700000000, %rdx      # imm = 0x700000000
movq %r14, %rdi
xorl %esi, %esi
callq 0x1e63
jmp 0x2939
leaq 0xbaa6(%rip), %rsi      # 0xde4d
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x23ed
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x4
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a50
jmp 0x2939
leaq 0xba86(%rip), %rsi      # 0xde7a
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x243a
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x4
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1aa9
jmp 0x2939
leaq 0xb3fb(%rip), %rsi      # 0xd83c
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2494
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x6
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b02
pushq $0xf
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ba2
jmp 0x2939
leaq 0xb3af(%rip), %rsi      # 0xd84a
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x24e1
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x6
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b52
jmp 0x2939
leaq 0xb370(%rip), %rsi      # 0xd858
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2556
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x2f
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1c40
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x19f2
pushq $0x4
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x1c95
pushq $0x7
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b02
pushq $0x1f
jmp 0x2484
leaq 0xb300(%rip), %rsi      # 0xd85d
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x25a0
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0x2ea0
jmp 0x2939
leaq 0xb2bc(%rip), %rsi      # 0xd863
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x25eb
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
pushq $0x1f
popq %rsi
movq %r14, %rdi
callq 0x2ea0
xorl %r15d, %r15d
jmp 0x2939
leaq 0xb275(%rip), %rsi      # 0xd867
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x263e
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rbx
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1bf1
movq %rbx, %rdi
jmp 0x2594
movq %r15, -0x38(%rbp)
leaq 0xb227(%rip), %rsi      # 0xd870
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2696
movq -0x30(%rbp), %rdi
callq 0x15ee
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
xorl %r15d, %r15d
pushq $0x3f
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1bf1
pushq $0x1f
popq %rsi
movq %r14, %rdi
jmp 0x2596
leaq 0xb1dc(%rip), %rsi      # 0xd879
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x2728
movq -0x30(%rbp), %rdi
callq 0x1fdb
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
movzbl %r13b, %ebx
shlq $0x20, %rbx
orq $0x4, %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1d37
movq -0x30(%rbp), %rdi
callq 0x15ee
addq $-0x8, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
pushq $-0x1
popq %r15
jne 0x2939
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1d75
jmp 0x25e3
leaq 0xb14c(%rip), %rsi      # 0xd87b
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x27ba
movq -0x30(%rbp), %rdi
callq 0x1fdb
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
movzbl %r13b, %ebx
shlq $0x20, %rbx
orq $0x4, %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1d37
movq -0x30(%rbp), %rdi
callq 0x15ee
addq $-0x8, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
pushq $-0x1
popq %r15
jne 0x2939
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1db3
jmp 0x25e3
leaq 0xb0bc(%rip), %rsi      # 0xd87d
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x285b
movq -0x30(%rbp), %rdi
callq 0x1fdb
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
pushq $0x2
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b52
movzbl %r13b, %ebx
shlq $0x20, %rbx
orq $0x4, %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1d37
movq -0x30(%rbp), %rdi
callq 0x15ee
addq $-0x8, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
pushq $-0x1
popq %r15
jne 0x2939
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1df1
jmp 0x25e3
leaq 0xb01d(%rip), %rsi      # 0xd87f
movq %rbx, %rdi
callq 0x1754
testb %al, %al
je 0x28fb
movq -0x30(%rbp), %rdi
callq 0x1fdb
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
jne 0x2935
movzbl %r13b, %ebx
shlq $0x20, %rbx
orq $0x4, %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1d37
movq -0x30(%rbp), %rdi
callq 0x15ee
addq $-0x8, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
pushq $-0x1
popq %r15
jne 0x2939
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1e25
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x19f2
pushq $0x4
jmp 0x29c8
leaq 0xaf7f(%rip), %rsi      # 0xd881
movq %rbx, %rdi
callq 0x1754
testb %al, %al
movq %r12, -0x40(%rbp)
je 0x294b
movq -0x30(%rbp), %rdi
callq 0x1fdb
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
je 0x296a
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaf31(%rip), %rdi      # 0xd883
leaq 0xac22(%rip), %rsi      # 0xd57b
leaq 0xae97(%rip), %rcx      # 0xd7f7
movl $0x37c, %edx            # imm = 0x37C
callq 0x1090
movzbl %r13b, %ebx
shlq $0x20, %rbx
orq $0x4, %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1d37
movq -0x30(%rbp), %rdi
callq 0x15ee
addq $-0x8, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq -0x38(%rbp), %r8
callq 0x2007
testl %eax, %eax
pushq $-0x1
popq %r15
jne 0x2939
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1e25
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x19f2
pushq $0xc
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x1c95
pushq $0x7
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b02
pushq $0x1f
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ba2
jmp 0x25e3
leaq 0xade9(%rip), %rdi      # 0xd7e2
leaq 0xab7b(%rip), %rsi      # 0xd57b
leaq 0xadf0(%rip), %rcx      # 0xd7f7
movl $0x2f7, %edx            # imm = 0x2F7
callq 0x1090