// File: /workspace/github_cpp_makefile_star2_O2/BlinfoldKing[P]lisval/src/lib/evaluator.cpp
// Function: Evaluator::eq()
pair<Token*, function<Token*(Token*)>> Evaluator::eq() {
    Token* op = new BinaryOperator(BinaryOperatorType::EQ);
    Token* var1 = new Variable("L");
    Token* var2 = new Variable("R");
    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 != b_token->type) {
                if (a_token->type == TokenType::VARIABLE
                        || b_token->type == TokenType::VARIABLE) {
                    Token* t = new Error("cannot check equality of variable", input);
                    return t;
                }
            }

            if (a_token->type == TokenType::NUMBER) {
                Number* a = static_cast<Number*>(a_token);
                Number* b = static_cast<Number*>(b_token);

                Token* t = new Boolean(a->value == b->value);
                return t;
            }

            if (a_token->type == TokenType::ATOM) {
                Atom* a = static_cast<Atom*>(a_token);
                Atom* b = static_cast<Atom*>(b_token);

                Token* t = new Boolean(a->str == b->str);
                return t;
            }

            if (a_token->type == TokenType::BOOLEAN) {
                Boolean* a = static_cast<Boolean*>(a_token);
                Boolean* b = static_cast<Boolean*>(b_token);

                Token* t = new Boolean(a->value == b->value);
                return t;
            }

            Token* t = new Error("unsupported equality", input);
            return t;
    });

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x8
popq %rdi
callq 0x3200
movabsq $0x700000005, %rcx      # imm = 0x700000005
movq %rcx, (%rax)
movq %rax, -0x48(%rbp)
pushq $0x28
popq %rdi
callq 0x3200
movq %rax, %r15
leaq 0x8491(%rip), %rsi      # 0xc277
leaq -0x88(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x3100
leaq -0x88(%rbp), %rsi
movq %r15, %rdi
callq 0x749c
leaq -0x88(%rbp), %rdi
callq 0x3140
movq %r15, -0x40(%rbp)
pushq $0x28
popq %rdi
callq 0x3200
movq %rax, %r15
leaq 0x86c4(%rip), %rsi      # 0xc4eb
leaq -0x68(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x3100
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x749c
leaq -0x68(%rbp), %rdi
callq 0x3140
leaq -0x38(%rbp), %r12
movq %r15, (%r12)
pushq $0x20
popq %rdi
callq 0x3200
movq %rax, %r15
movl $0x1, (%rax)
leaq 0x8(%rax), %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
andq $0x0, 0x18(%rax)
leaq -0x48(%rbp), %rsi
movq %r13, %rdi
callq 0x74b0
leaq -0x40(%rbp), %rsi
movq %r13, %rdi
callq 0x74b0
movq %r13, %rdi
movq %r12, %rsi
callq 0x74b0
movq %r15, (%rbx)
andq $0x0, 0x10(%rbx)
movq %r14, 0x8(%rbx)
leaq 0x1fea(%rip), %rax      # 0x5e92
movq %rax, 0x20(%rbx)
leaq 0x215b(%rip), %rax      # 0x600e
movq %rax, 0x18(%rbx)
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x3ede
jmp 0x3ee5
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x3140
jmp 0x3ee8
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r15, %rdi
callq 0x3210
movq %rbx, %rdi
callq 0x3320
nop