// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x90(%rsp), %r12
movq %r12, %rdi
callq 0x16611
cmpb $0x0, 0x30(%r12)
je 0x168d5
movq (%r14), %rdx
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x1537c
movl 0x60(%rsp), %eax
cmpl $0x18, %eax
ja 0x168fc
movl $0x1e02000, %ecx        # imm = 0x1E02000
btl %eax, %ecx
jae 0x168fc
movq 0x78(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, (%r14)
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x16611
cmpb $0x0, 0x58(%rsp)
je 0x168ea
movl 0x60(%rsp), %eax
addl $-0xd, %eax
cmpl $0xb, %eax
ja 0x16a4b
leaq 0x22c5d(%rip), %rcx     # 0x394fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x90(%rsp), %rdi
callq 0x1ad98
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1ad98
movq %rsp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1bd63
jmp 0x169e4
leaq 0x90(%rsp), %rsi
movq %rbx, %rdi
callq 0x1adf0
jmp 0x16a2c
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x1adf0
jmp 0x16a18
leaq 0x38(%rsp), %r15
movl $0x1, -0x10(%r15)
movq (%r14), %rax
movq %rax, -0x8(%r15)
leaq 0x70(%rsp), %rdx
leaq 0x22d28(%rip), %rsi     # 0x39644
movq %r15, %rdi
callq 0xebef
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x1ae0c
movq %r15, %rdi
callq 0x9130
jmp 0x16a22
leaq 0x90(%rsp), %rdi
callq 0x1ad98
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1ad98
movq %rsp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1c113
jmp 0x169e4
leaq 0x90(%rsp), %rdi
callq 0x1ad98
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1ad98
movq %rsp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1bf3b
jmp 0x169e4
leaq 0x90(%rsp), %rdi
callq 0x1ad98
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1ad98
movq %rsp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1c027
jmp 0x169e4
leaq 0x90(%rsp), %rdi
callq 0x1ad98
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1ad98
movq %rsp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1be4f
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %r14
andq $0x0, (%rdi)
movb $0x1, 0x30(%rbx)
movaps -0x8(%r14), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, -0x8(%r14)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0xa248
movq %r14, %rdi
callq 0xa248
leaq 0x28(%rsp), %rdi
callq 0x1fb90
leaq 0x70(%rsp), %rdi
callq 0x9130
leaq 0x90(%rsp), %rdi
callq 0x1fb90
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
pushq $0x10
popq %rdi
callq 0x9150
movq %rax, %r14
leaq 0x22c1a(%rip), %rsi     # 0x39677
movq %rax, %rdi
callq 0x93c0
movq 0x45564(%rip), %rsi     # 0x5bfd0
movq 0x45525(%rip), %rdx     # 0x5bf98
movq %r14, %rdi
callq 0x94b0
movq %rax, %rbx
movq %r14, %rdi
callq 0x9210
jmp 0x16aa4
movq %rax, %rbx
movq %r15, %rdi
callq 0x9130
jmp 0x16ab3
jmp 0x16ab0
jmp 0x16aa1
jmp 0x16aa1
jmp 0x16aa1
jmp 0x16aa1
jmp 0x16aa1
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x1fb90
jmp 0x16ab3
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x9130
jmp 0x16ac4
jmp 0x16ac1
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x1fb90
movq %rbx, %rdi
callq 0x94d0