// File: /workspace/github_c_makefile_star2_O0/voithos[P]awl/src/builtins.c
// Function: builtin_macro
awlval* builtin_macro(awlenv* e, awlval* a) {
    AWLASSERT_ARGCOUNT(a, 3, "macro");
    AWLASSERT_TYPE(a, 0, AWLVAL_SYM, "macro");
    AWLASSERT_ISEXPR(a, 1, "macro");

    int index = awlenv_index(e, a->cell[0]);
    AWLASSERT(a, index == -1,
            "cannot redefine '%s'", a->cell[0]->sym);

    for (int i = 0; i < a->cell[1]->count; i++) {
        AWLASSERT(a, (a->cell[1]->cell[i]->type == AWLVAL_SYM),
                "macro cannot take non-symbol argument at position %i", i);
    }

    awlval* name = awlval_pop(a, 0);
    awlval* formals = awlval_pop(a, 0);
    awlval* body = awlval_take(a, 0);

    awlval* macro = awlval_macro(e, formals, body);

    awlenv_put(e, name, macro);

    awlval_del(name);
    awlval_del(macro);
    return awlval_qexpr();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x61f8
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
leaq 0x13f17(%rip), %rdi     # 0x1a0e2
leaq 0x14307(%rip), %rsi     # 0x1a4d9
movl $0x3, %edx
movb $0x0, %al
callq 0x16600
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x63fb
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpl $0x3, (%rax)
je 0x6260
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x78(%rbp)
movl $0x3, %edi
callq 0x161a0
movq -0x78(%rbp), %rcx
movq %rax, %r8
leaq 0x13ef3(%rip), %rdi     # 0x1a129
leaq 0x1429c(%rip), %rsi     # 0x1a4d9
xorl %edx, %edx
movb $0x0, %al
callq 0x16600
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x63fb
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
cmpl $0xc, (%rax)
je 0x62cc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
cmpl $0xb, (%rax)
je 0x62cc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, %rcx
leaq 0x141ac(%rip), %rdi     # 0x1a44b
leaq 0x14233(%rip), %rsi     # 0x1a4d9
movl $0x1, %edx
movb $0x0, %al
callq 0x16600
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x63fb
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
callq 0x188d0
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
je 0x6320
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
leaq 0x14023(%rip), %rdi     # 0x1a322
movb $0x0, %al
callq 0x16600
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x63fb
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x4(%rcx), %eax
jge 0x638d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x3, (%rax)
je 0x6380
movl -0x44(%rbp), %esi
leaq 0x1417d(%rip), %rdi     # 0x1a4df
movb $0x0, %al
callq 0x16600
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x63fb
jmp 0x6382
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6327
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x174b0
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x174b0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x17560
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x16ad0
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x189b0
movq -0x58(%rbp), %rdi
callq 0x16cf0
movq -0x70(%rbp), %rdi
callq 0x16cf0
callq 0x16c00
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)