// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::additive_expr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
expr_result_t additive_expr(std::string const& input, size_t& pos) {
    auto head_result = multive_expr(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 e_result = multive_expr(input, pos);
        if (e_result.is_error())
            return e_result;
        auto e = e_result.ok();

        switch (op_token.kind) {
        case token_t::kind_t::Plus:
            acc = make<ast::add_expr_t>(acc, e);
            break;
        case token_t::kind_t::Minus:
            acc = make<ast::sub_expr_t>(acc, e);
            break;
        default:
            throw std::logic_error{"invalid additive op"};
        }
    }
    return acc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0xf8(%rbp)
movq %rdi, %rax
movq %rax, -0xf0(%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, -0xe8(%rbp)
callq 0x3e8b0
movq -0xe8(%rbp), %rdi
callq 0x41970
movb %al, -0xd9(%rbp)
jmp 0x3ed24
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x3ed30
jmp 0x3ed5f
movq -0xf8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x41990
jmp 0x3ed42
movl $0x1, -0x60(%rbp)
jmp 0x3f03f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3f058
leaq -0x50(%rbp), %rdi
callq 0x419e0
movq %rax, -0x100(%rbp)
jmp 0x3ed71
movq -0x100(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x13050
jmp 0x3ed83
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x355b0
jmp 0x3ed9c
cmpl $0xe, -0xa0(%rbp)
je 0x3edcb
cmpl $0xf, -0xa0(%rbp)
je 0x3edcb
movl $0x3, -0x60(%rbp)
jmp 0x3efbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3f034
movq -0x98(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xa280
movq -0x108(%rbp), %rcx
movq -0xf8(%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 0x3e8b0
jmp 0x3ee13
movq -0xf8(%rbp), %rdi
callq 0x41970
movb %al, -0x109(%rbp)
jmp 0x3ee27
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x3ee33
jmp 0x3ee68
movb $0x1, -0xa1(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x3efa6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3f002
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3eff6
movq -0xf8(%rbp), %rdi
callq 0x419e0
movq %rax, -0x118(%rbp)
jmp 0x3ee7d
movq -0x118(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x13050
movl -0xa0(%rbp), %eax
movl %eax, -0x11c(%rbp)
subl $0xe, %eax
je 0x3eeb3
jmp 0x3eea3
movl -0x11c(%rbp), %eax
subl $0xf, %eax
je 0x3eefe
jmp 0x3ef35
leaq -0xc8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x3f070
jmp 0x3eecc
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x42110
leaq -0xc8(%rbp), %rdi
callq 0x42140
jmp 0x3ef93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3efea
leaq -0xd8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x3f0b0
jmp 0x3ef17
leaq -0x70(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x42160
leaq -0xd8(%rbp), %rdi
callq 0x42190
jmp 0x3ef93
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x128(%rbp)
leaq 0x5db11(%rip), %rsi     # 0x9ca64
callq 0xa540
jmp 0x3ef5a
movq -0x128(%rbp), %rdi
movq 0xa8068(%rip), %rsi     # 0xe6fd0
movq 0xa8021(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x3f06a
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xa2c0
jmp 0x3efea
leaq -0xb8(%rbp), %rdi
callq 0x13080
movl $0x0, -0x60(%rbp)
testb $0x1, -0xa1(%rbp)
jne 0x3efbb
movq -0xf8(%rbp), %rdi
callq 0x2ffa0
jmp 0x3efbd
leaq -0xa0(%rbp), %rdi
callq 0x404f0
movl -0x60(%rbp), %eax
movl %eax, -0x12c(%rbp)
testl %eax, %eax
je 0x3efe5
jmp 0x3efd8
movl -0x12c(%rbp), %eax
subl $0x3, %eax
je 0x3f010
jmp 0x3f029
jmp 0x3ed81
leaq -0xb8(%rbp), %rdi
callq 0x13080
movq -0xf8(%rbp), %rdi
callq 0x2ffa0
leaq -0xa0(%rbp), %rdi
callq 0x404f0
jmp 0x3f034
movq -0xf8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x41f90
jmp 0x3f022
movl $0x1, -0x60(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x13080
jmp 0x3f03f
leaq -0x70(%rbp), %rdi
callq 0x13080
jmp 0x3f058
leaq -0x50(%rbp), %rdi
callq 0x2ffa0
movq -0xf0(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x2ffa0
movq -0x58(%rbp), %rdi
callq 0xa650
nopw (%rax,%rax)