// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::primary_term(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
term_result_t primary_term(std::string const& input, size_t& pos) {
    auto token = next_token(input, pos);
    if (token.kind == token_t::kind_t::Ident) {
        return var_term(input, pos);
    } else if (token.kind == token_t::kind_t::LParen) {
        EXPECT(lparen_token, LParen);
        auto inner_result = term(input, pos);
        if (inner_result.is_error())
            return inner_result;
        EXPECT(rparen_token, RParen);
        return inner_result;
    } else if (token.kind == token_t::kind_t::Prob) {
        EXPECT(prob_token, Prob);
        EXPECT(lparen_token, LParen);
        auto inner_result = formula(input, pos);
        if (inner_result.is_error())
            return inner_result.convert<ptr<logic::term_t>>();
        EXPECT(rparen_token, RParen);
        return term_result_t::ok(make<logic::prob_term_t>(inner_result.ok()));
    } else if (token.kind == token_t::kind_t::Int) {
        EXPECT(int_token, Int);
        pos = int_token.pos + int_token.lexime.size();
        return term_result_t::ok(make<logic::int_term_t>(std::stoi(int_token.lexime)));
    } else {
        return term_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 $0x520, %rsp            # imm = 0x520
movq %rdi, -0x420(%rbp)
movq %rdi, %rax
movq %rax, -0x418(%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 $0xa, -0x48(%rbp)
jne 0x36975
movq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x366c0
jmp 0x36958
movl $0x1, -0x58(%rbp)
jmp 0x37440
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x37459
cmpl $0x1f, -0x48(%rbp)
jne 0x36c62
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x90(%rbp), %rdi
movl $0x1f, %ecx
callq 0x364d0
jmp 0x3699d
leaq -0x90(%rbp), %rdi
callq 0x40510
movb %al, -0x421(%rbp)
jmp 0x369b1
movb -0x421(%rbp), %al
testb $0x1, %al
jne 0x369bd
jmp 0x36a04
leaq -0x90(%rbp), %rdi
callq 0x405b0
movq %rax, -0x430(%rbp)
jmp 0x369d2
movq -0x430(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x369e7
movl $0x1, -0x58(%rbp)
jmp 0x36c40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x36c51
leaq -0x90(%rbp), %rdi
callq 0x40630
movq %rax, -0x438(%rbp)
jmp 0x36a19
movq -0x438(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x406b0
jmp 0x36a2e
movq -0xb8(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa280
movq -0x440(%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 0x36a6f
leaq -0xf8(%rbp), %rdi
callq 0x407f0
movb %al, -0x441(%rbp)
jmp 0x36a83
movb -0x441(%rbp), %al
testb $0x1, %al
jne 0x36a8f
jmp 0x36ad2
movq -0x420(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x40810
jmp 0x36aa4
movl $0x1, -0x58(%rbp)
jmp 0x36c0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x36c32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x36c26
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x130(%rbp), %rdi
movl $0x20, %ecx
callq 0x364d0
jmp 0x36af0
leaq -0x130(%rbp), %rdi
callq 0x40510
movb %al, -0x442(%rbp)
jmp 0x36b04
movb -0x442(%rbp), %al
testb $0x1, %al
jne 0x36b10
jmp 0x36b57
leaq -0x130(%rbp), %rdi
callq 0x405b0
movq %rax, -0x450(%rbp)
jmp 0x36b25
movq -0x450(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x36b3a
movl $0x1, -0x58(%rbp)
jmp 0x36bf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x36bfe
leaq -0x130(%rbp), %rdi
callq 0x40630
movq %rax, -0x458(%rbp)
jmp 0x36b6c
movq -0x458(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x406b0
jmp 0x36b81
movq -0x158(%rbp), %rax
movq %rax, -0x460(%rbp)
leaq -0x150(%rbp), %rdi
callq 0xa280
movq -0x460(%rbp), %rcx
movq -0x420(%rbp), %rdi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0xf8(%rbp), %rsi
callq 0x40810
jmp 0x36bc1
movl $0x1, -0x58(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x404f0
jmp 0x36bf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x404f0
jmp 0x36bfe
leaq -0x130(%rbp), %rdi
callq 0x407c0
jmp 0x36c0c
leaq -0x130(%rbp), %rdi
callq 0x407c0
jmp 0x36c26
leaq -0xf8(%rbp), %rdi
callq 0x40860
leaq -0xc0(%rbp), %rdi
callq 0x404f0
jmp 0x36c40
leaq -0xf8(%rbp), %rdi
callq 0x40860
leaq -0xc0(%rbp), %rdi
callq 0x404f0
jmp 0x36c51
leaq -0x90(%rbp), %rdi
callq 0x407c0
jmp 0x37440
leaq -0x90(%rbp), %rdi
callq 0x407c0
jmp 0x37459
cmpl $0x23, -0x48(%rbp)
jne 0x370f0
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x198(%rbp), %rdi
movl $0x23, %ecx
callq 0x364d0
jmp 0x36c8a
leaq -0x198(%rbp), %rdi
callq 0x40510
movb %al, -0x461(%rbp)
jmp 0x36c9e
movb -0x461(%rbp), %al
testb $0x1, %al
jne 0x36caa
jmp 0x36cf1
leaq -0x198(%rbp), %rdi
callq 0x405b0
movq %rax, -0x470(%rbp)
jmp 0x36cbf
movq -0x470(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x36cd4
movl $0x1, -0x58(%rbp)
jmp 0x370ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x370df
leaq -0x198(%rbp), %rdi
callq 0x40630
movq %rax, -0x478(%rbp)
jmp 0x36d06
movq -0x478(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x406b0
jmp 0x36d1b
movq -0x1c0(%rbp), %rax
movq %rax, -0x480(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0xa280
movq -0x480(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x200(%rbp), %rdi
movl $0x1f, %ecx
callq 0x364d0
jmp 0x36d64
leaq -0x200(%rbp), %rdi
callq 0x40510
movb %al, -0x481(%rbp)
jmp 0x36d78
movb -0x481(%rbp), %al
testb $0x1, %al
jne 0x36d84
jmp 0x36ddc
leaq -0x200(%rbp), %rdi
callq 0x405b0
movq %rax, -0x490(%rbp)
jmp 0x36d99
movq -0x490(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x36dae
movl $0x1, -0x58(%rbp)
jmp 0x3709a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x370c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x370b4
leaq -0x200(%rbp), %rdi
callq 0x40630
movq %rax, -0x498(%rbp)
jmp 0x36df1
movq -0x498(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x406b0
jmp 0x36e06
movq -0x228(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x220(%rbp), %rdi
callq 0xa280
movq -0x4a0(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x268(%rbp), %rdi
callq 0x374b0
jmp 0x36e47
leaq -0x268(%rbp), %rdi
callq 0x40890
movb %al, -0x4a1(%rbp)
jmp 0x36e5b
movb -0x4a1(%rbp), %al
testb $0x1, %al
jne 0x36e67
jmp 0x36eaa
movq -0x420(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x408b0
jmp 0x36e7c
movl $0x1, -0x58(%rbp)
jmp 0x37066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3708c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x37080
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x2a0(%rbp), %rdi
movl $0x20, %ecx
callq 0x364d0
jmp 0x36ec8
leaq -0x2a0(%rbp), %rdi
callq 0x40510
movb %al, -0x4a2(%rbp)
jmp 0x36edc
movb -0x4a2(%rbp), %al
testb $0x1, %al
jne 0x36ee8
jmp 0x36f2f
leaq -0x2a0(%rbp), %rdi
callq 0x405b0
movq %rax, -0x4b0(%rbp)
jmp 0x36efd
movq -0x4b0(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x36f12
movl $0x1, -0x58(%rbp)
jmp 0x3704a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x37058
leaq -0x2a0(%rbp), %rdi
callq 0x40630
movq %rax, -0x4b8(%rbp)
jmp 0x36f44
movq -0x4b8(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
callq 0x406b0
jmp 0x36f59
movq -0x2c8(%rbp), %rax
movq %rax, -0x4c8(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0xa280
movq -0x4c8(%rbp), %rcx
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x268(%rbp), %rdi
callq 0x408f0
movq %rax, -0x4c0(%rbp)
jmp 0x36f99
movq -0x4c0(%rbp), %rsi
leaq -0x2f0(%rbp), %rdi
callq 0x374f0
jmp 0x36fae
leaq -0x2e0(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
leaq -0x2f0(%rbp), %rsi
callq 0x25110
movq -0x420(%rbp), %rdi
movq -0x4d0(%rbp), %rsi
callq 0x406f0
jmp 0x36fdd
leaq -0x2e0(%rbp), %rdi
callq 0x25000
leaq -0x2f0(%rbp), %rdi
callq 0x25140
movl $0x1, -0x58(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x404f0
jmp 0x3704a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3703c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x25000
leaq -0x2f0(%rbp), %rdi
callq 0x25140
leaq -0x2d0(%rbp), %rdi
callq 0x404f0
jmp 0x37058
leaq -0x2a0(%rbp), %rdi
callq 0x407c0
jmp 0x37066
leaq -0x2a0(%rbp), %rdi
callq 0x407c0
jmp 0x37080
leaq -0x268(%rbp), %rdi
callq 0x40970
leaq -0x230(%rbp), %rdi
callq 0x404f0
jmp 0x3709a
leaq -0x268(%rbp), %rdi
callq 0x40970
leaq -0x230(%rbp), %rdi
callq 0x404f0
jmp 0x370b4
leaq -0x200(%rbp), %rdi
callq 0x407c0
leaq -0x1c8(%rbp), %rdi
callq 0x404f0
jmp 0x370ce
leaq -0x200(%rbp), %rdi
callq 0x407c0
leaq -0x1c8(%rbp), %rdi
callq 0x404f0
jmp 0x370df
leaq -0x198(%rbp), %rdi
callq 0x407c0
jmp 0x37440
leaq -0x198(%rbp), %rdi
callq 0x407c0
jmp 0x37459
cmpl $0x7, -0x48(%rbp)
jne 0x37302
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x328(%rbp), %rdi
movl $0x7, %ecx
callq 0x364d0
jmp 0x37118
leaq -0x328(%rbp), %rdi
callq 0x40510
movb %al, -0x4d1(%rbp)
jmp 0x3712c
movb -0x4d1(%rbp), %al
testb $0x1, %al
jne 0x37138
jmp 0x3717f
leaq -0x328(%rbp), %rdi
callq 0x405b0
movq %rax, -0x4e0(%rbp)
jmp 0x3714d
movq -0x4e0(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0x40530
jmp 0x37162
movl $0x1, -0x58(%rbp)
jmp 0x372e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x372f1
leaq -0x328(%rbp), %rdi
callq 0x40630
movq %rax, -0x4e8(%rbp)
jmp 0x37194
movq -0x4e8(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0x406b0
jmp 0x371a9
movq -0x350(%rbp), %rax
movq %rax, -0x508(%rbp)
leaq -0x348(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0xa280
movq -0x508(%rbp), %rcx
movq -0x4f8(%rbp), %rdi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x350(%rbp), %rax
movq %rax, -0x500(%rbp)
callq 0xa280
movq -0x500(%rbp), %rcx
movq -0x4f8(%rbp), %rdi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x409a0
movl %eax, -0x4ec(%rbp)
jmp 0x37223
movl -0x4ec(%rbp), %eax
movl %eax, -0x37c(%rbp)
leaq -0x378(%rbp), %rdi
leaq -0x37c(%rbp), %rsi
callq 0x37520
jmp 0x37244
leaq -0x368(%rbp), %rdi
movq %rdi, -0x510(%rbp)
leaq -0x378(%rbp), %rsi
callq 0x409e0
movq -0x420(%rbp), %rdi
movq -0x510(%rbp), %rsi
callq 0x406f0
jmp 0x37273
leaq -0x368(%rbp), %rdi
callq 0x25000
leaq -0x378(%rbp), %rdi
callq 0x40a10
movl $0x1, -0x58(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x404f0
jmp 0x372e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x372d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x25000
leaq -0x378(%rbp), %rdi
callq 0x40a10
leaq -0x358(%rbp), %rdi
callq 0x404f0
jmp 0x372f1
leaq -0x328(%rbp), %rdi
callq 0x407c0
jmp 0x37440
leaq -0x328(%rbp), %rdi
callq 0x407c0
jmp 0x37459
movl $0x1, -0x3b0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x3a8(%rbp)
leaq -0x3a0(%rbp), %rax
movq %rax, -0x518(%rbp)
movl -0x48(%rbp), %esi
leaq -0x410(%rbp), %rdi
callq 0x347b0
jmp 0x37339
leaq 0x65716(%rip), %rsi     # 0x9ca56
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rdx
callq 0x12fb0
jmp 0x37355
leaq 0x6577f(%rip), %rdx     # 0x9cadb
leaq -0x3d0(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x1ddc0
jmp 0x37371
movq -0x518(%rbp), %rdi
leaq -0x38(%rbp), %rdx
leaq -0x3d0(%rbp), %rsi
callq 0x40470
jmp 0x3738a
movq -0x420(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x40a30
jmp 0x3739f
leaq -0x3b0(%rbp), %rdi
callq 0x30020
leaq -0x3d0(%rbp), %rdi
callq 0xa240
leaq -0x3f0(%rbp), %rdi
callq 0xa240
leaq -0x410(%rbp), %rdi
callq 0xa240
movl $0x1, -0x58(%rbp)
jmp 0x37440
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x37432
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x37426
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3741a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0x30020
leaq -0x3d0(%rbp), %rdi
callq 0xa240
leaq -0x3f0(%rbp), %rdi
callq 0xa240
leaq -0x410(%rbp), %rdi
callq 0xa240
jmp 0x37459
leaq -0x48(%rbp), %rdi
callq 0x404f0
movq -0x418(%rbp), %rax
addq $0x520, %rsp            # imm = 0x520
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x404f0
movq -0x50(%rbp), %rdi
callq 0xa650
nopl (%rax,%rax)