// File: /workspace/github_c_makefile_star2_O0/mtnygard[P]complisp/lisp.c
// Function: compile_cdr
TEST compile_cdr(Buffer *buf, uword *heap) {
  ASTNode *node = Reader_read("(cdr (cons 1 2))");
  int compile_result = Compile_entry(buf, node);
  ASSERT_EQ(compile_result, 0);
  // clang-format off
  byte expected[] = {
      // mov rax, 0x2
      0x48, 0xc7, 0xc0, 0x04, 0x00, 0x00, 0x00,
      // mov [rbp-8], rax
      0x48, 0x89, 0x45, 0xf8,
      // mov rax, 0x4
      0x48, 0xc7, 0xc0, 0x08, 0x00, 0x00, 0x00,
      // mov [rsi+Cdr], rax
      0x48, 0x89, 0x46, 0x08,
      // mov rax, [rbp-8]
      0x48, 0x8b, 0x45, 0xf8,
      // mov [rsi+Car], rax
      0x48, 0x89, 0x46, 0x00,
      // mov rax, rsi
      0x48, 0x89, 0xf0,
      // or rax, kPairTag
      0x48, 0x83, 0xc8, 0x01,
      // add rsi, 2*kWordSize
      0x48, 0x81, 0xc6, 0x10, 0x00, 0x00, 0x00,
      // mov rax, [rax+7]
      0x48, 0x8b, 0x40, 0x07,
  };
  // clang-format on
  EXPECT_ENTRY_CONTAINS_CODE(buf, expected);
  Buffer_make_executable(buf);
  uword result = Testing_execute_entry(buf, heap);
  ASSERT_EQ_FMT(Object_encode_integer(2), result, "0x%lx");
  AST_heap_free(node);
  PASS();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x6b3a(%rip), %rdi      # 0x16774
callq 0x4e40
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x4690
movl %eax, -0x24(%rbp)
movl 0xb4eb(%rip), %eax      # 0x1b144
addl $0x1, %eax
movl %eax, 0xb4e2(%rip)      # 0x1b144
cmpl $0x0, -0x24(%rbp)
je 0xfcb0
jmp 0xfc6a
leaq 0x4a32(%rip), %rax      # 0x146a3
movq %rax, 0xb4d8(%rip)      # 0x1b150
movl $0x913, 0xb4c6(%rip)    # imm = 0x913
leaq 0x63fc(%rip), %rax      # 0x16085
movq %rax, 0xb4c8(%rip)      # 0x1b158
movzbl 0xb469(%rip), %eax      # 0x1b100
andl $0x4, %eax
cmpl $0x0, %eax
je 0xfca4
callq 0x1040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfe1d
jmp 0xfcb2
leaq -0x60(%rbp), %rdi
leaq 0x48b3(%rip), %rsi      # 0x14570
movl $0x30, %edx
callq 0x1110
movq -0x10(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x30, %edx
callq 0x12d40
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0xfced
movl -0x64(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xfe1d
jmp 0xfcef
movq -0x10(%rbp), %rdi
callq 0x1c50
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4e70
movq %rax, -0x70(%rbp)
movl 0xb435(%rip), %eax      # 0x1b144
addl $0x1, %eax
movl %eax, 0xb42c(%rip)      # 0x1b144
movl $0x2, %edi
callq 0x1290
cmpq -0x70(%rbp), %rax
je 0xfe00
movq 0xb29d(%rip), %rax      # 0x1afd0
movq (%rax), %rdi
leaq 0x59f1(%rip), %rsi      # 0x1572e
movb $0x0, %al
callq 0x1100
movq 0xb285(%rip), %rax      # 0x1afd0
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x2, %edi
callq 0x1290
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x655e(%rip), %rsi      # 0x162c8
movb $0x0, %al
callq 0x1100
movq 0xb258(%rip), %rax      # 0x1afd0
movq (%rax), %rdi
leaq 0x59b8(%rip), %rsi      # 0x1573a
movb $0x0, %al
callq 0x1100
movq 0xb240(%rip), %rax      # 0x1afd0
movq (%rax), %rdi
movq -0x70(%rbp), %rdx
leaq 0x652a(%rip), %rsi      # 0x162c8
movb $0x0, %al
callq 0x1100
movq 0xb224(%rip), %rax      # 0x1afd0
movq (%rax), %rdi
leaq 0x6c06(%rip), %rsi      # 0x169bc
movb $0x0, %al
callq 0x1100
leaq 0x48df(%rip), %rax      # 0x146a3
movq %rax, 0xb385(%rip)      # 0x1b150
movl $0x92f, 0xb373(%rip)    # imm = 0x92F
leaq 0x6676(%rip), %rax      # 0x16452
movq %rax, 0xb375(%rip)      # 0x1b158
movzbl 0xb316(%rip), %eax      # 0x1b100
andl $0x4, %eax
cmpl $0x0, %eax
je 0xfdf7
callq 0x1040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfe1d
jmp 0xfe02
movq -0x20(%rbp), %rdi
callq 0x1800
movq $0x0, 0xb342(%rip) # 0x1b158
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)