// File: asd00012334[P]Abstract-Algebra-2018/main.cpp
// Function: DivisionSpecialized<prime::Zp, prime::ZpElement, true>::operator/(Polynomial<prime::Zp, prime::ZpElement>) const
Polynomial<ring,ringElement> operator/(Polynomial<ring,ringElement> p2)const{
        /// ?
        Polynomial<ring, ringElement> out, res;
        auto This = static_cast<Polynomial<ring,ringElement>const*>(this);
        res.canonicalType.scalar = This->canonicalType.scalar;
        out.canonicalType.scalar = This->canonicalType.scalar;

        res.coef = This->coef;
        out.coef.resize(res.coef.size(),This->r->scalar->__zero__());
        /// Reduce to monic polynomial

        auto cinv = p2.coef.back().inv();
        for(int i=0;i<p2.coef.size();++i)
            p2.coef[i] = p2.coef[i]*cinv;

        for(int i=res.coef.size()-1;i>=(int)p2.coef.size()-1;--i){
            auto tmp = res.coef[i];
            out.coef[i-p2.coef.size()+1] = tmp;
            for(int j=0;j<p2.coef.size();++j)
                res.coef[i-j] = res.coef[i-j] - p2.coef.rbegin()[j] * tmp;
        }
        for(int i=0;i<out.coef.size();++i)
            out.coef[i] = out.coef[i] * cinv;

        out.reduce();
        return out;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdx, -0x150(%rbp)
movq %rdi, -0x148(%rbp)
movq %rdi, %rax
movq %rax, -0x140(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x138(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x4870
leaq -0x48(%rbp), %rdi
callq 0x4870
jmp 0x597e
movq -0x148(%rbp), %rax
movq -0x138(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rsi
addq $0x10, %rsi
leaq -0x38(%rbp), %rdi
callq 0xd190
jmp 0x59b8
movq -0x148(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x160(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x95a0
movq %rax, -0x158(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
leaq -0x78(%rbp), %rdi
callq 0x2750
jmp 0x59f0
movq -0x158(%rbp), %rsi
movq -0x160(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xdd80
jmp 0x5a09
movq -0x150(%rbp), %rdi
addq $0x10, %rdi
callq 0x9950
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x4800
jmp 0x5a2a
movl $0x0, -0x94(%rbp)
movq -0x150(%rbp), %rdi
movslq -0x94(%rbp), %rax
movq %rax, -0x168(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jae 0x5b0a
movq -0x150(%rbp), %rdi
addq $0x10, %rdi
movslq -0x94(%rbp), %rsi
callq 0xd3e0
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xd580
jmp 0x5a94
movq -0x150(%rbp), %rdi
addq $0x10, %rdi
movslq -0x94(%rbp), %rsi
callq 0xd3e0
movq -0xb0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xa0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5a34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5e14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x49b0
jmp 0x5e14
leaq -0x48(%rbp), %rdi
addq $0x10, %rdi
callq 0x95a0
subq $0x1, %rax
movl %eax, -0xb4(%rbp)
movq -0x150(%rbp), %rdi
movl -0xb4(%rbp), %eax
movl %eax, -0x16c(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movl -0x16c(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x5d26
leaq -0x48(%rbp), %rdi
addq $0x10, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xd3e0
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movq -0x148(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, -0xd0(%rbp)
movq 0x8(%rcx), %rdx
movq %rdx, -0xc8(%rbp)
movq 0x10(%rcx), %rcx
movq %rcx, -0xc0(%rbp)
addq $0x10, %rax
movq %rax, -0x178(%rbp)
movslq -0xb4(%rbp), %rax
movq %rax, -0x180(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdi
subq %rax, %rsi
addq $0x1, %rsi
callq 0xd3e0
movq -0xd0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xc8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x0, -0xd4(%rbp)
movq -0x150(%rbp), %rdi
movslq -0xd4(%rbp), %rax
movq %rax, -0x188(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movq -0x188(%rbp), %rax
cmpq %rcx, %rax
jae 0x5d10
leaq -0x38(%rbp), %rdi
movl -0xb4(%rbp), %eax
movl -0xd4(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rsi
callq 0xd3e0
movq -0x150(%rbp), %rsi
movq %rax, -0x1a0(%rbp)
addq $0x10, %rsi
leaq -0x110(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0xd500
movq -0x198(%rbp), %rdi
movslq -0xd4(%rbp), %rsi
callq 0xd550
movq %rax, -0x190(%rbp)
jmp 0x5c88
movq -0x190(%rbp), %rsi
leaq -0x108(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0xd580
jmp 0x5ca4
movq -0x1a0(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
leaq -0x108(%rbp), %rdx
callq 0xd480
jmp 0x5cc0
leaq -0x48(%rbp), %rdi
addq $0x10, %rdi
movl -0xb4(%rbp), %eax
subl -0xd4(%rbp), %eax
movslq %eax, %rsi
callq 0xd3e0
movq -0xf0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xe8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xe0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x5bfc
jmp 0x5d12
movl -0xb4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x5b21
movl $0x0, -0x114(%rbp)
movq -0x148(%rbp), %rdi
movslq -0x114(%rbp), %rax
movq %rax, -0x1a8(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x5dd7
movq -0x148(%rbp), %rdi
addq $0x10, %rdi
movslq -0x114(%rbp), %rsi
callq 0xd3e0
movq %rax, %rsi
leaq -0x130(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xd580
jmp 0x5d8c
movq -0x148(%rbp), %rdi
addq $0x10, %rdi
movslq -0x114(%rbp), %rsi
callq 0xd3e0
movq -0x130(%rbp), %rcx
movq %rcx, (%rax)
movq -0x128(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x120(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x5d30
movq -0x148(%rbp), %rdi
callq 0x4920
jmp 0x5de5
movb $0x1, -0x19(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x49b0
testb $0x1, -0x19(%rbp)
jne 0x5e04
movq -0x148(%rbp), %rdi
callq 0x49b0
movq -0x140(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x49b0
movq -0x50(%rbp), %rdi
callq 0x22f0
nopl (%rax)