// 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;
        auto This = static_cast<Polynomial<ring,ringElement>const*>(this);
        out.canonicalType.scalar = This->canonicalType.scalar;
        out.coef = This->coef;

        /// Reduce to monic polynomial
        out.reduce();
        for(int i=0;i<p2.coef.size();++i)
            p2.coef[i] = p2.coef[i]/p2.coef.back();

        for(int i=out.coef.size()-1;i>=(int)p2.coef.size()-1;--i){
            auto tmp = out.coef[i];
            for(int j=0;j<p2.coef.size();++j)
                out.coef[i-j] = out.coef[i-j] - p2.coef.rbegin()[j] * tmp;
        }
        out.reduce();
        return out;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdx, -0xd0(%rbp)
movq %rdi, -0xb8(%rbp)
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x4870
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, (%rdi)
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
addq $0x10, %rdi
callq 0xd190
jmp 0xcc42
movq -0xb8(%rbp), %rdi
callq 0x4920
jmp 0xcc50
movl $0x0, -0x38(%rbp)
movq -0xd0(%rbp), %rdi
movslq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0xcd1e
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
movq %rdi, -0xe8(%rbp)
movslq -0x38(%rbp), %rsi
callq 0xd3e0
movq -0xe8(%rbp), %rdi
movq %rax, -0xe0(%rbp)
callq 0x9950
movq -0xe0(%rbp), %rsi
movq %rax, %rdx
leaq -0x50(%rbp), %rdi
callq 0xd400
jmp 0xccc8
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
movslq -0x38(%rbp), %rsi
callq 0xd3e0
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xcc57
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x49b0
jmp 0xced8
movq -0xb8(%rbp), %rdi
addq $0x10, %rdi
callq 0x95a0
subq $0x1, %rax
movl %eax, -0x54(%rbp)
movq -0xd0(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, -0xec(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movl -0xec(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0xcea4
movq -0xb8(%rbp), %rdi
addq $0x10, %rdi
movslq -0x54(%rbp), %rsi
callq 0xd3e0
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x68(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x74(%rbp)
movq -0xd0(%rbp), %rdi
movslq -0x74(%rbp), %rax
movq %rax, -0xf8(%rbp)
addq $0x10, %rdi
callq 0x95a0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
jae 0xce94
movq -0xb8(%rbp), %rdi
addq $0x10, %rdi
movl -0x54(%rbp), %eax
movl -0x74(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rsi
callq 0xd3e0
movq -0xd0(%rbp), %rsi
movq %rax, -0x110(%rbp)
addq $0x10, %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xd500
movq -0x108(%rbp), %rdi
movslq -0x74(%rbp), %rsi
callq 0xd550
movq %rax, -0x100(%rbp)
jmp 0xce1b
movq -0x100(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xd580
jmp 0xce34
movq -0x110(%rbp), %rsi
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0xd480
jmp 0xce50
movq -0xb8(%rbp), %rdi
addq $0x10, %rdi
movl -0x54(%rbp), %eax
subl -0x74(%rbp), %eax
movslq %eax, %rsi
callq 0xd3e0
movq -0x90(%rbp), %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xcd94
jmp 0xce96
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xcd35
movq -0xb8(%rbp), %rdi
callq 0x4920
jmp 0xceb2
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0xcec8
movq -0xb8(%rbp), %rdi
callq 0x49b0
movq -0xc8(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)