// File: /workspace/github_c_makefile_star2_O0/mtnygard[P]complisp/lisp.c
// Function: Compile_let
int Compile_let(Buffer *buf, ASTNode *bindings, ASTNode *body, word stack_index,
                Env *binding_env, Env *body_env, Env *labels) {
  if (AST_is_nil(bindings)) {
    // Base case: no bindings (or none left)
    _(Compile_expr(buf, body, stack_index, body_env, labels));
    return 0;
  }
  assert(AST_is_pair(bindings));
  // Unpack the binding
  ASTNode *binding = AST_pair_car(bindings);
  ASTNode *name = AST_pair_car(binding);
  assert(AST_is_symbol(name));
  ASTNode *binding_expr = AST_pair_car(AST_pair_cdr(binding));
  // Evaluate the RHS, store result on stack
  _(Compile_expr(buf, binding_expr, stack_index, binding_env, labels));
  Emit_store_reg_indirect(buf, Ind(kRsp, stack_index), kRax);
  // Bind the name to a stack offset
  Env entry = Env_bind(AST_symbol_cstr(name), stack_index, body_env);
  _(Compile_let(buf, AST_pair_cdr(bindings), body, stack_index - kWordSize,
                binding_env, &entry, labels));
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1700
testb $0x1, %al
jne 0x4056
jmp 0x4093
jmp 0x4058
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x29f0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x4085
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4202
jmp 0x4087
movl $0x0, -0x4(%rbp)
jmp 0x4202
movq -0x18(%rbp), %rdi
callq 0x1870
testb $0x1, %al
jne 0x40a2
jmp 0x40a4
jmp 0x40c3
leaq 0x10973(%rip), %rdi     # 0x14a1e
leaq 0x105f1(%rip), %rsi     # 0x146a3
movl $0x386, %edx            # imm = 0x386
leaq 0x10976(%rip), %rcx     # 0x14a34
callq 0x1090
movq -0x18(%rbp), %rdi
callq 0x1890
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1890
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1a90
testb $0x1, %al
jne 0x40ec
jmp 0x40ee
jmp 0x410d
leaq 0x1098a(%rip), %rdi     # 0x14a7f
leaq 0x105a7(%rip), %rsi     # 0x146a3
movl $0x38a, %edx            # imm = 0x38A
leaq 0x1092c(%rip), %rcx     # 0x14a34
callq 0x1090
movq -0x48(%rbp), %rdi
callq 0x18b0
movq %rax, %rdi
callq 0x1890
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x29f0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x414f
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4202
jmp 0x4151
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movl $0x4, %edi
movsbl %al, %esi
callq 0x1f60
movq -0x90(%rbp), %rdi
movq %rax, -0x64(%rbp)
movq -0x64(%rbp), %rsi
xorl %edx, %edx
callq 0x2510
movq -0x50(%rbp), %rdi
callq 0x1ab0
movq %rax, %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x80(%rbp), %rdi
callq 0x1520
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x18b0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
subq $0x8, %rcx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %rax
leaq -0x80(%rbp), %r9
movq %rax, (%rsp)
callq 0x4020
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x41f9
movl -0x84(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4202
jmp 0x41fb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nop