// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::primary_formula(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
formula_result_t primary_formula(std::string const& input, size_t& pos) {
    auto token = next_token(input, pos);
    if (token.kind == token_t::kind_t::True) {
        pos = token.pos + token.lexime.size();
        return formula_result_t::ok(make<logic::top_formula_t>());
    } else if (token.kind == token_t::kind_t::False) {
        pos = token.pos + token.lexime.size();
        return formula_result_t::ok(make<logic::bot_formula_t>());
    } else if (token.kind == token_t::kind_t::LParen) {
        EXPECT(lparen_token, LParen);
        auto inner_result = formula(input, pos);
        if (inner_result.is_error())
            return inner_result;
        EXPECT(rparen_token, RParen);
        return inner_result;
    } else {
        auto cmp_result = comparison_terms_formula(input, pos);
        if (cmp_result.is_ok())
            return cmp_result;
        if (token.kind == token_t::kind_t::Ident) {
            pos = token.pos + token.lexime.size();
            return formula_result_t::ok(make<logic::var_formula_t>(token.lexime));
        } else {
            return formula_result_t::error(parser::error_t {
                parser::error_t::kind_t::UnexpectedToken, pos,
                "expected was " + token_kind_to_string(token.kind) + ", but coming is " + token.lexime
            });
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x298(%rbp)
movq %rdi, %rax
movq %rax, -0x290(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x48(%rbp), %rdi
callq 0x355b0
cmpl $0x8, -0x48(%rbp)
jne 0x38631
movq -0x40(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xa280
movq -0x2a0(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x68(%rbp), %rdi
callq 0x38c90
jmp 0x385b6
leaq -0x58(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x40d40
movq -0x298(%rbp), %rdi
movq -0x2a8(%rbp), %rsi
callq 0x40cc0
jmp 0x385df
leaq -0x58(%rbp), %rdi
callq 0x16150
leaq -0x68(%rbp), %rdi
callq 0x40d70
movl $0x1, -0x78(%rbp)
jmp 0x38c60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x16150
leaq -0x68(%rbp), %rdi
callq 0x40d70
jmp 0x38c79
cmpl $0x9, -0x48(%rbp)
jne 0x386ea
movq -0x40(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xa280
movq -0x2b0(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x38cc0
jmp 0x3866e
leaq -0x88(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
leaq -0x98(%rbp), %rsi
callq 0x40d90
movq -0x298(%rbp), %rdi
movq -0x2b8(%rbp), %rsi
callq 0x40cc0
jmp 0x3869d
leaq -0x88(%rbp), %rdi
callq 0x16150
leaq -0x98(%rbp), %rdi
callq 0x40dc0
movl $0x1, -0x78(%rbp)
jmp 0x38c60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x16150
leaq -0x98(%rbp), %rdi
callq 0x40dc0
jmp 0x38c79
cmpl $0x1f, -0x48(%rbp)
jne 0x389d7
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0xd0(%rbp), %rdi
movl $0x1f, %ecx
callq 0x364d0
jmp 0x38712
leaq -0xd0(%rbp), %rdi
callq 0x40510
movb %al, -0x2b9(%rbp)
jmp 0x38726
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x38732
jmp 0x38779
leaq -0xd0(%rbp), %rdi
callq 0x405b0
movq %rax, -0x2c8(%rbp)
jmp 0x38747
movq -0x2c8(%rbp), %rsi
movq -0x298(%rbp), %rdi
callq 0x40de0
jmp 0x3875c
movl $0x1, -0x78(%rbp)
jmp 0x389b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x389c6
leaq -0xd0(%rbp), %rdi
callq 0x40630
movq %rax, -0x2d0(%rbp)
jmp 0x3878e
movq -0x2d0(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x406b0
jmp 0x387a3
movq -0xf8(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xa280
movq -0x2d8(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x138(%rbp), %rdi
callq 0x374b0
jmp 0x387e4
leaq -0x138(%rbp), %rdi
callq 0x40890
movb %al, -0x2d9(%rbp)
jmp 0x387f8
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x38804
jmp 0x38847
movq -0x298(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x40e60
jmp 0x38819
movl $0x1, -0x78(%rbp)
jmp 0x38981
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x389a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3899b
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x170(%rbp), %rdi
movl $0x20, %ecx
callq 0x364d0
jmp 0x38865
leaq -0x170(%rbp), %rdi
callq 0x40510
movb %al, -0x2da(%rbp)
jmp 0x38879
movb -0x2da(%rbp), %al
testb $0x1, %al
jne 0x38885
jmp 0x388cc
leaq -0x170(%rbp), %rdi
callq 0x405b0
movq %rax, -0x2e8(%rbp)
jmp 0x3889a
movq -0x2e8(%rbp), %rsi
movq -0x298(%rbp), %rdi
callq 0x40de0
jmp 0x388af
movl $0x1, -0x78(%rbp)
jmp 0x38965
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38973
leaq -0x170(%rbp), %rdi
callq 0x40630
movq %rax, -0x2f0(%rbp)
jmp 0x388e1
movq -0x2f0(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x406b0
jmp 0x388f6
movq -0x198(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xa280
movq -0x2f8(%rbp), %rcx
movq -0x298(%rbp), %rdi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x138(%rbp), %rsi
callq 0x40e60
jmp 0x38936
movl $0x1, -0x78(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x404f0
jmp 0x38965
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x404f0
jmp 0x38973
leaq -0x170(%rbp), %rdi
callq 0x407c0
jmp 0x38981
leaq -0x170(%rbp), %rdi
callq 0x407c0
jmp 0x3899b
leaq -0x138(%rbp), %rdi
callq 0x40970
leaq -0x100(%rbp), %rdi
callq 0x404f0
jmp 0x389b5
leaq -0x138(%rbp), %rdi
callq 0x40970
leaq -0x100(%rbp), %rdi
callq 0x404f0
jmp 0x389c6
leaq -0xd0(%rbp), %rdi
callq 0x407c0
jmp 0x38c60
leaq -0xd0(%rbp), %rdi
callq 0x407c0
jmp 0x38c79
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1d8(%rbp), %rdi
callq 0x37d50
jmp 0x389ed
leaq -0x1d8(%rbp), %rdi
callq 0x40eb0
movb %al, -0x2f9(%rbp)
jmp 0x38a01
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x38a0d
jmp 0x38a3f
movq -0x298(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x40e60
jmp 0x38a22
movl $0x1, -0x78(%rbp)
jmp 0x38c44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38c52
cmpl $0xa, -0x48(%rbp)
jne 0x38b06
movq -0x40(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0xa280
movq -0x310(%rbp), %rcx
movq -0x308(%rbp), %rsi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x1f8(%rbp), %rdi
callq 0x38cf0
jmp 0x38a8a
leaq -0x1e8(%rbp), %rdi
movq %rdi, -0x318(%rbp)
leaq -0x1f8(%rbp), %rsi
callq 0x40ed0
movq -0x298(%rbp), %rdi
movq -0x318(%rbp), %rsi
callq 0x40cc0
jmp 0x38ab9
leaq -0x1e8(%rbp), %rdi
callq 0x16150
leaq -0x1f8(%rbp), %rdi
callq 0x40f00
movl $0x1, -0x78(%rbp)
jmp 0x38c44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x16150
leaq -0x1f8(%rbp), %rdi
callq 0x40f00
jmp 0x38c52
movl $0x1, -0x228(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rax
movq %rax, -0x320(%rbp)
movl -0x48(%rbp), %esi
leaq -0x288(%rbp), %rdi
callq 0x347b0
jmp 0x38b3d
leaq 0x63f12(%rip), %rsi     # 0x9ca56
leaq -0x268(%rbp), %rdi
leaq -0x288(%rbp), %rdx
callq 0x12fb0
jmp 0x38b59
leaq 0x63f7b(%rip), %rdx     # 0x9cadb
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x1ddc0
jmp 0x38b75
movq -0x320(%rbp), %rdi
leaq -0x38(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x40470
jmp 0x38b8e
movq -0x298(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x40c40
jmp 0x38ba3
leaq -0x228(%rbp), %rdi
callq 0x30020
leaq -0x248(%rbp), %rdi
callq 0xa240
leaq -0x268(%rbp), %rdi
callq 0xa240
leaq -0x288(%rbp), %rdi
callq 0xa240
movl $0x1, -0x78(%rbp)
jmp 0x38c44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38c36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38c2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x38c1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x30020
leaq -0x248(%rbp), %rdi
callq 0xa240
leaq -0x268(%rbp), %rdi
callq 0xa240
leaq -0x288(%rbp), %rdi
callq 0xa240
jmp 0x38c52
leaq -0x1d8(%rbp), %rdi
callq 0x40970
jmp 0x38c60
leaq -0x1d8(%rbp), %rdi
callq 0x40970
jmp 0x38c79
leaq -0x48(%rbp), %rdi
callq 0x404f0
movq -0x290(%rbp), %rax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x404f0
movq -0x70(%rbp), %rdi
callq 0xa650
nopl (%rax,%rax)