// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::comparison_terms_formula(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
formula_result_t comparison_terms_formula(std::string const& input, size_t& pos) {
    auto lhs_result = term(input, pos);
    if (lhs_result.is_error())
        return lhs_result.convert<ptr<logic::formula_t>>();
    auto token = next_token(input, pos);
    if (token.kind != token_t::kind_t::Eq &&
            token.kind != token_t::kind_t::Less &&
            token.kind != token_t::kind_t::Leq &&
            token.kind != token_t::kind_t::Geq &&
            token.kind != token_t::kind_t::Greater) {
        return formula_result_t::error(error_t {
                error_t::kind_t::UnexpectedToken, pos,
                "expected was comparison operation, but comming is " + token.lexime
                });

    }
    pos = token.pos + token.lexime.size();
    auto rhs_result = term(input, pos);
    if (rhs_result.is_error())
        return rhs_result.convert<ptr<logic::formula_t>>();

    switch (token.kind) {
    case token_t::kind_t::Eq:
        return formula_result_t::ok(make<logic::eq_formula_t>(lhs_result.ok(), rhs_result.ok()));
    case token_t::kind_t::Less:
        return formula_result_t::ok(make<logic::less_formula_t>(lhs_result.ok(), rhs_result.ok()));
    case token_t::kind_t::Leq:
        return formula_result_t::ok(make<logic::leq_formula_t>(lhs_result.ok(), rhs_result.ok()));
    case token_t::kind_t::Geq:
        return formula_result_t::ok(make<logic::geq_formula_t>(lhs_result.ok(), rhs_result.ok()));
    case token_t::kind_t::Greater:
        return formula_result_t::ok(make<logic::greater_formula_t>(lhs_result.ok(), rhs_result.ok()));
    default:
        throw std::logic_error{"must be unreachable"};
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x1b8(%rbp)
movq %rdi, %rax
movq %rax, -0x1b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x37470
movq -0x1a8(%rbp), %rdi
callq 0x407f0
movb %al, -0x199(%rbp)
jmp 0x37da4
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x37db0
jmp 0x37ddf
movq -0x1b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40c00
jmp 0x37dc2
movl $0x1, -0x60(%rbp)
jmp 0x383d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x383eb
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x90(%rbp), %rdi
callq 0x355b0
jmp 0x37df8
cmpl $0xd, -0x90(%rbp)
je 0x37ec5
cmpl $0x15, -0x90(%rbp)
je 0x37ec5
cmpl $0x16, -0x90(%rbp)
je 0x37ec5
cmpl $0x17, -0x90(%rbp)
je 0x37ec5
cmpl $0x18, -0x90(%rbp)
je 0x37ec5
movl $0x1, -0xc0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
leaq 0x64c15(%rip), %rsi     # 0x9ca78
callq 0x1dee0
jmp 0x37e6a
movq -0x1b8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x40c40
jmp 0x37e7f
leaq -0xc0(%rbp), %rdi
callq 0x30020
movl $0x1, -0x60(%rbp)
jmp 0x383b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x383c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x30020
jmp 0x383c4
movq -0x88(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xa280
movq -0x1c0(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x37470
jmp 0x37f03
leaq -0xf8(%rbp), %rdi
callq 0x407f0
movb %al, -0x1c1(%rbp)
jmp 0x37f17
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x37f23
jmp 0x37f55
movq -0x1b8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x40c00
jmp 0x37f38
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x383a8
movl -0x90(%rbp), %eax
addl $-0xd, %eax
movl %eax, %ecx
movq %rcx, -0x1d0(%rbp)
subl $0xb, %eax
ja 0x3833f
movq -0x1d0(%rbp), %rax
leaq 0x649c2(%rip), %rcx     # 0x9c940
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0x1d8(%rbp)
jmp 0x37f99
leaq -0xf8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x1e0(%rbp)
jmp 0x37fae
movq -0x1e0(%rbp), %rdx
movq -0x1d8(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x38400
jmp 0x37fca
leaq -0x108(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq -0x118(%rbp), %rsi
callq 0x252f0
movq -0x1b8(%rbp), %rdi
movq -0x1e8(%rbp), %rsi
callq 0x40cc0
jmp 0x37ff9
leaq -0x108(%rbp), %rdi
callq 0x16150
leaq -0x118(%rbp), %rdi
callq 0x25320
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x16150
leaq -0x118(%rbp), %rdi
callq 0x25320
jmp 0x383a8
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0x1f0(%rbp)
jmp 0x38058
leaq -0xf8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x1f8(%rbp)
jmp 0x3806d
movq -0x1f8(%rbp), %rdx
movq -0x1f0(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x38440
jmp 0x38089
leaq -0x128(%rbp), %rdi
movq %rdi, -0x200(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x25340
movq -0x1b8(%rbp), %rdi
movq -0x200(%rbp), %rsi
callq 0x40cc0
jmp 0x380b8
leaq -0x128(%rbp), %rdi
callq 0x16150
leaq -0x138(%rbp), %rdi
callq 0x25370
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x16150
leaq -0x138(%rbp), %rdi
callq 0x25370
jmp 0x383a8
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0x208(%rbp)
jmp 0x38117
leaq -0xf8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x210(%rbp)
jmp 0x3812c
movq -0x210(%rbp), %rdx
movq -0x208(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x38480
jmp 0x38148
leaq -0x148(%rbp), %rdi
movq %rdi, -0x218(%rbp)
leaq -0x158(%rbp), %rsi
callq 0x25390
movq -0x1b8(%rbp), %rdi
movq -0x218(%rbp), %rsi
callq 0x40cc0
jmp 0x38177
leaq -0x148(%rbp), %rdi
callq 0x16150
leaq -0x158(%rbp), %rdi
callq 0x253c0
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x16150
leaq -0x158(%rbp), %rdi
callq 0x253c0
jmp 0x383a8
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0x220(%rbp)
jmp 0x381d6
leaq -0xf8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x228(%rbp)
jmp 0x381eb
movq -0x228(%rbp), %rdx
movq -0x220(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x384c0
jmp 0x38207
leaq -0x168(%rbp), %rdi
movq %rdi, -0x230(%rbp)
leaq -0x178(%rbp), %rsi
callq 0x253e0
movq -0x1b8(%rbp), %rdi
movq -0x230(%rbp), %rsi
callq 0x40cc0
jmp 0x38236
leaq -0x168(%rbp), %rdi
callq 0x16150
leaq -0x178(%rbp), %rdi
callq 0x25410
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x16150
leaq -0x178(%rbp), %rdi
callq 0x25410
jmp 0x383a8
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0x238(%rbp)
jmp 0x38295
leaq -0xf8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x240(%rbp)
jmp 0x382aa
movq -0x240(%rbp), %rdx
movq -0x238(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x38500
jmp 0x382c6
leaq -0x188(%rbp), %rdi
movq %rdi, -0x248(%rbp)
leaq -0x198(%rbp), %rsi
callq 0x25430
movq -0x1b8(%rbp), %rdi
movq -0x248(%rbp), %rsi
callq 0x40cc0
jmp 0x382f5
leaq -0x188(%rbp), %rdi
callq 0x16150
leaq -0x198(%rbp), %rdi
callq 0x25460
movl $0x1, -0x60(%rbp)
jmp 0x3839a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x16150
leaq -0x198(%rbp), %rdi
callq 0x25460
jmp 0x383a8
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x250(%rbp)
leaq 0x6474e(%rip), %rsi     # 0x9caab
callq 0xa540
jmp 0x38364
movq -0x250(%rbp), %rdi
movq 0xaec5e(%rip), %rsi     # 0xe6fd0
movq 0xaec17(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x383fd
movq -0x250(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xa2c0
jmp 0x383a8
leaq -0xf8(%rbp), %rdi
callq 0x40860
jmp 0x383b6
leaq -0xf8(%rbp), %rdi
callq 0x40860
jmp 0x383c4
leaq -0x90(%rbp), %rdi
callq 0x404f0
jmp 0x383d2
leaq -0x90(%rbp), %rdi
callq 0x404f0
jmp 0x383eb
leaq -0x50(%rbp), %rdi
callq 0x40860
movq -0x1b0(%rbp), %rax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x40860
movq -0x58(%rbp), %rdi
callq 0xa650
nopl (%rax)