// File: pfnet-research[P]pml/src/parser.cpp
// Function: parser::multive_term(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long&)
term_result_t multive_term(std::string const& input, size_t& pos) {
    auto head_result = primary_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::Star && op_token.kind != token_t::kind_t::Slash)
            break;
        pos = op_token.pos + op_token.lexime.size();

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

        switch (op_token.kind) {
        case token_t::kind_t::Star:
            acc = make<logic::mul_term_t>(acc, term_result.ok());
            break;
        case token_t::kind_t::Slash:
            acc = make<logic::div_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 0x36900
movq -0xd8(%rbp), %rdi
callq 0x407f0
movb %al, -0xc9(%rbp)
jmp 0x375a4
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x375b0
jmp 0x375df
movq -0xe8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40810
jmp 0x375c2
movl $0x1, -0x60(%rbp)
jmp 0x37898
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x378b1
leaq -0x50(%rbp), %rdi
callq 0x40a90
movq %rax, -0xf0(%rbp)
jmp 0x375f1
movq -0xf0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x25160
jmp 0x37603
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x355b0
jmp 0x3761c
cmpl $0x10, -0xa0(%rbp)
je 0x3764b
cmpl $0x11, -0xa0(%rbp)
je 0x3764b
movl $0x3, -0x60(%rbp)
jmp 0x37822
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3788d
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 0x36900
jmp 0x37693
movq -0xe8(%rbp), %rdi
callq 0x407f0
movb %al, -0xf9(%rbp)
jmp 0x376a7
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x376b3
jmp 0x376e8
movb $0x1, -0xa1(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x3780b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3785b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3784f
movl -0xa0(%rbp), %eax
movl %eax, -0x100(%rbp)
subl $0x10, %eax
je 0x3770b
jmp 0x376fb
movl -0x100(%rbp), %eax
subl $0x11, %eax
je 0x3775a
jmp 0x377a6
movq -0xe8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x108(%rbp)
jmp 0x37720
movq -0x108(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x378d0
jmp 0x37739
leaq -0x70(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x40b10
leaq -0xb8(%rbp), %rdi
callq 0x250a0
jmp 0x37804
movq -0xe8(%rbp), %rdi
callq 0x40a90
movq %rax, -0x110(%rbp)
jmp 0x3776f
movq -0x110(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x37910
jmp 0x37788
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x40b40
leaq -0xc8(%rbp), %rdi
callq 0x250f0
jmp 0x37804
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x118(%rbp)
leaq 0x652a0(%rip), %rsi     # 0x9ca64
callq 0xa540
jmp 0x377cb
movq -0x118(%rbp), %rdi
movq 0xaf7f7(%rip), %rsi     # 0xe6fd0
movq 0xaf7b0(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x378c3
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xa2c0
jmp 0x3784f
movl $0x0, -0x60(%rbp)
testb $0x1, -0xa1(%rbp)
jne 0x37820
movq -0xe8(%rbp), %rdi
callq 0x40860
jmp 0x37822
leaq -0xa0(%rbp), %rdi
callq 0x404f0
movl -0x60(%rbp), %eax
movl %eax, -0x11c(%rbp)
testl %eax, %eax
je 0x3784a
jmp 0x3783d
movl -0x11c(%rbp), %eax
subl $0x3, %eax
je 0x37869
jmp 0x37882
jmp 0x37601
movq -0xe8(%rbp), %rdi
callq 0x40860
leaq -0xa0(%rbp), %rdi
callq 0x404f0
jmp 0x3788d
movq -0xe8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x40b70
jmp 0x3787b
movl $0x1, -0x60(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x25000
jmp 0x37898
leaq -0x70(%rbp), %rdi
callq 0x25000
jmp 0x378b1
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)