// File: BlinfoldKing[P]lisval/src/lib/evaluator.cpp
// Function: Evaluator::range()
pair<Token*, function<Token*(Token*)>> Evaluator::range() {
    Token* op = new Atom("range");
    Token* var1 = new Variable("MIN");
    Token* var2 = new Variable("MAX");
    List* signature = new List();
    signature->list.push_back(op);
    signature->list.push_back(var1);
    signature->list.push_back(var2);
    Token* token = signature;
    auto res = make_pair(token, [this](Token* input) {
            List* list = static_cast<List*>(input);

            Token* a_token = this->eval(list->list[1]);
            Token* b_token = this->eval(list->list[2]);

            if (a_token->type != TokenType::NUMBER) {
                Token* t = new Error("expect a number, got: " + a_token->debug(), input);
                return t;
            }

            if (b_token->type != TokenType::NUMBER) {
                Token* t = new Error("expect a number, got: " + b_token->debug(), input);
                return t;
            }

            Number* min = static_cast<Number*>(a_token);
            Number* max = static_cast<Number*>(b_token);

            List* result = new List();
            for (int i = min->value; i < max->value; i++) {
                result->list.push_back(new Number(i));
            }

            Token* t = result;
            return t;
    });

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x100(%rbp)
movq %rdi, %rax
movq %rax, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x28, %edi
callq 0x32b0
movq %rax, -0xe8(%rbp)
movb $0x1, -0x4d(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x34a0
movq -0xe0(%rbp), %rdx
leaq 0x1e0c7(%rip), %rsi     # 0x23389
leaq -0x38(%rbp), %rdi
callq 0x33b0
jmp 0x52cd
movq -0xe8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x11960
jmp 0x52df
movb $0x0, -0x4d(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31c0
leaq -0x39(%rbp), %rdi
callq 0x3300
movq -0xe8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x28, %edi
callq 0x32b0
movq %rax, -0x110(%rbp)
movb $0x1, -0x7a(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x34a0
movq -0x108(%rbp), %rdx
leaq 0x1e05c(%rip), %rsi     # 0x2338f
leaq -0x78(%rbp), %rdi
callq 0x33b0
jmp 0x533e
movq -0x110(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x11830
jmp 0x5350
movb $0x0, -0x7a(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31c0
leaq -0x79(%rbp), %rdi
callq 0x3300
movq -0x110(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x28, %edi
callq 0x32b0
movq %rax, -0x120(%rbp)
movb $0x1, -0xaa(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x34a0
movq -0x118(%rbp), %rdx
leaq 0x1dfe9(%rip), %rsi     # 0x23393
leaq -0xa8(%rbp), %rdi
callq 0x33b0
jmp 0x53b8
movq -0x120(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x11830
jmp 0x53cd
movb $0x0, -0xaa(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x31c0
leaq -0xa9(%rbp), %rdi
callq 0x3300
movq -0x120(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x20, %edi
callq 0x32b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x128(%rbp)
callq 0x11870
jmp 0x5418
movq -0x128(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x18(%rbp), %rsi
callq 0x118b0
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x58(%rbp), %rsi
callq 0x118b0
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x88(%rbp), %rsi
callq 0x118b0
movq -0xf0(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xd8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x55d0
movq -0x100(%rbp), %rdi
movq %rax, -0xd0(%rbp)
movq %rdx, -0xc8(%rbp)
leaq -0xd0(%rbp), %rsi
callq 0x5600
movq -0xf8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x54e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31c0
leaq -0x39(%rbp), %rdi
callq 0x3300
testb $0x1, -0x4d(%rbp)
jne 0x54f9
jmp 0x550a
movq -0xe8(%rbp), %rdi
movl $0x28, %esi
callq 0x32c0
jmp 0x55c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5532
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31c0
leaq -0x79(%rbp), %rdi
callq 0x3300
testb $0x1, -0x7a(%rbp)
jne 0x5543
jmp 0x5554
movq -0x110(%rbp), %rdi
movl $0x28, %esi
callq 0x32c0
jmp 0x55c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x557c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x31c0
leaq -0xa9(%rbp), %rdi
callq 0x3300
testb $0x1, -0xaa(%rbp)
jne 0x5593
jmp 0x55a4
movq -0x120(%rbp), %rdi
movl $0x28, %esi
callq 0x32c0
jmp 0x55c3
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x20, %esi
callq 0x32c0
movq -0x48(%rbp), %rdi
callq 0x3490
nopl (%rax)