// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::additive_term(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
term_result_t additive_term(std::string const& input, size_t& pos) {
    auto head_result = multive_term(input, pos);
    if (head_result.is_error())
        return head_result;
    auto acc = head_result.ok();

    while (true) {
        auto op_token = next_token(input, pos);
        if (op_token.kind != token_t::kind_t::Plus && op_token.kind != token_t::kind_t::Minus)
            break;
        pos = op_token.pos + op_token.lexime.size();

        auto term_result = multive_term(input, pos);
        if (term_result.is_error())
            return term_result;

        switch (op_token.kind) {
        case token_t::kind_t::Plus:
            acc = make<logic::add_term_t>(acc, term_result.ok());
            break;
        case token_t::kind_t::Minus:
            acc = make<logic::sub_term_t>(acc, term_result.ok());
            break;
        default:
            throw std::logic_error{"invalid additive op"};
        }
    }
    return acc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0xe0(%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, -0xd8(%rbp)
callq 0x37550
movq -0xd8(%rbp), %rdi
callq 0x407f0
movb %al, -0xc9(%rbp)
jmp 0x379a4
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x379b0
jmp 0x379df
movq -0xe8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40810
jmp 0x379c2
movl $0x1, -0x60(%rbp)
jmp 0x37c98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x37cb1
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0xf0(%rbp)
jmp 0x379f1
movq -0xf0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x25160
jmp 0x37a03
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x355b0
jmp 0x37a1c
cmpl $0xe, -0xa0(%rbp)
je 0x37a4b
cmpl $0xf, -0xa0(%rbp)
je 0x37a4b
movl $0x3, -0x60(%rbp)
jmp 0x37c22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x37c8d
movq -0x98(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xa280
movq -0xf8(%rbp), %rcx
movq -0xe8(%rbp), %rdi
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movb $0x0, -0xa1(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x37550
jmp 0x37a93
movq -0xe8(%rbp), %rdi
callq 0x407f0
movb %al, -0xf9(%rbp)
jmp 0x37aa7
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x37ab3
jmp 0x37ae8
movb $0x1, -0xa1(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x37c0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x37c5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x37c4f
movl -0xa0(%rbp), %eax
movl %eax, -0x100(%rbp)
subl $0xe, %eax
je 0x37b0b
jmp 0x37afb
movl -0x100(%rbp), %eax
subl $0xf, %eax
je 0x37b5a
jmp 0x37ba6
movq -0xe8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x108(%rbp)
jmp 0x37b20
movq -0x108(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x37cd0
jmp 0x37b39
leaq -0x70(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x40ba0
leaq -0xb8(%rbp), %rdi
callq 0x24fe0
jmp 0x37c04
movq -0xe8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x110(%rbp)
jmp 0x37b6f
movq -0x110(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x37d10
jmp 0x37b88
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x40bd0
leaq -0xc8(%rbp), %rdi
callq 0x25050
jmp 0x37c04
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x118(%rbp)
leaq 0x64ea0(%rip), %rsi     # 0x9ca64
callq 0xa540
jmp 0x37bcb
movq -0x118(%rbp), %rdi
movq 0xaf3f7(%rip), %rsi     # 0xe6fd0
movq 0xaf3b0(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x37cc3
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xa2c0
jmp 0x37c4f
movl $0x0, -0x60(%rbp)
testb $0x1, -0xa1(%rbp)
jne 0x37c20
movq -0xe8(%rbp), %rdi
callq 0x40860
jmp 0x37c22
leaq -0xa0(%rbp), %rdi
callq 0x404f0
movl -0x60(%rbp), %eax
movl %eax, -0x11c(%rbp)
testl %eax, %eax
je 0x37c4a
jmp 0x37c3d
movl -0x11c(%rbp), %eax
subl $0x3, %eax
je 0x37c69
jmp 0x37c82
jmp 0x37a01
movq -0xe8(%rbp), %rdi
callq 0x40860
leaq -0xa0(%rbp), %rdi
callq 0x404f0
jmp 0x37c8d
movq -0xe8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x40b70
jmp 0x37c7b
movl $0x1, -0x60(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x25000
jmp 0x37c98
leaq -0x70(%rbp), %rdi
callq 0x25000
jmp 0x37cb1
leaq -0x50(%rbp), %rdi
callq 0x40860
movq -0xe0(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x40860
movq -0x58(%rbp), %rdi
callq 0xa650
nopw %cs:(%rax,%rax)